spec

package
v0.0.0-...-0022d8d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const Default = "default"

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyObject

type BodyObject struct {
	MIMEType   MIMEType // the mimetype for the object
	HttpStatus string   // Any HTTP status code, '200', '201', '400' the value of 'default' can be used to cover all responses not defined
	Array      bool     // is the reference to an array
	Body       any      // the response object example used to determine the type and name of each field returned
	Desc       string   // description of the body
	Title      string   // object title
}

func NewBody

func NewBody(mtype MIMEType, status, desc string, array bool, body any) BodyObject

NewBody is the data for mapping a request / response object to a specific route

type Components

type Components struct {
	Schemas       Schemas                `json:"schema,omitempty"`
	RequestBodies map[string]RequestBody `json:"requestBodies,omitempty"`
	Params        map[string]Param       `json:"params,omitempty"`
}

reusable reference objects

type Contact

type Contact struct {
	Name  string `json:"name"`  // The identifying name of the contact person/organization.
	URL   string `json:"url"`   // The URL pointing to the contact information. MUST be in the format of a URL.
	Email string `json:"email"` // The email address of the contact person/organization. MUST be in the format of an email address.
}

type ExternalDocs

type ExternalDocs struct {
	Desc string `json:"description"`
	URL  string `json:"url" required:"true"`
}

type Format

type Format int
const (
	Int32 Format = iota + 1
	Int64
	Float
	Double
	Byte     // base64 encoded characters
	Binary   // any sequence of octets
	Date     // full-date - https://www.rfc-editor.org/rfc/rfc3339#section-5.6
	DateTime // date-time - https://www.rfc-editor.org/rfc/rfc3339#section-5.6
	Password
)

func (Format) String

func (f Format) String() string

type Info

type Info struct {
	Title   string   `json:"title"`                   // REQUIRED. The title of the API.
	Desc    string   `json:"description"`             // A short description of the API. CommonMark syntax MAY be used for rich text representation.
	Terms   string   `json:"termsOfService"`          // A URL to the Terms of Service for the API. MUST be in the format of a URL.
	Contact *Contact `json:"contact"`                 // The contact information for the exposed API.
	License *License `json:"license"`                 // The license information for the exposed API.
	Version string   `json:"version" required:"true"` // REQUIRED. The version of the OpenAPI document (which is distinct from the OpenAPI Specification version or the API implementation version).
}

type License

type License struct {
	Name string `json:"name"` // REQUIRED. The license name used for the API.
	URL  string `json:"url"`  // A URL to the license used for the API. MUST be in the format of a URL.
}

type MIMEType

type MIMEType string
const (
	Json    MIMEType = "application/json"
	Xml     MIMEType = "application/xml"
	Text    MIMEType = "text/plain"
	General MIMEType = "application/octet-stream"
	Html    MIMEType = "text/html"
	XForm   MIMEType = "application/x-www-form-urlencoded"
	Jscript MIMEType = "application/javascript"
	Form    MIMEType = "multipart/form-data"
)

common media types

type Media

type Media struct {
	Schema Schema `json:"schema"`
}

type Method

type Method string
const (
	GET     Method = "get"
	PUT     Method = "put"
	POST    Method = "post"
	DELETE  Method = "delete"
	OPTIONS Method = "options"
	HEAD    Method = "head"
	PATCH   Method = "patch"
	TRACE   Method = "trace"
)

type OpenAPI

type OpenAPI struct {
	Version string   `json:"openapi"`           // the  semantic version number of the OpenAPI Specification version
	Tags    []Tag    `json:"tags,omitempty"`    // A list of tags used by the specification with additional metadata
	Servers []Server `json:"servers,omitempty"` // Array of Server Objects, which provide connectivity information to a target server.
	Paths   Paths    `json:"paths"`             // REQUIRED. Map of uri paths mapped to methods i.e., get, put, post, delete
	Info    Info     `json:"info"`              // REQUIRED. Provides metadata about the API. The metadata MAY be used by tooling as required.
	//Components   Components    `json:"components,omitempty"`   // reuseable components not used here
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` //Additional external documentation.

	// non OpenAPI external reference for simplified routes
	Routes map[UniqueRoute]Route `json:"-"`
}

func New

func New(title, version, description string) *OpenAPI

func (*OpenAPI) AddParam

func (o *OpenAPI) AddParam(ur UniqueRoute, rp RouteParam) error

AddParam adds a param object to the given unique route

func (*OpenAPI) AddReqBody

func (o *OpenAPI) AddReqBody(ur UniqueRoute, bo BodyObject) error

AddReq adds request information to the api requestBody object

func (*OpenAPI) AddResp

func (o *OpenAPI) AddResp(ur UniqueRoute, bo BodyObject) error

AddResp adds response information to the api responses map this is used for a request body, response body

func (*OpenAPI) AddRoute

func (o *OpenAPI) AddRoute(path, method, tag, desc, summary string) (ur UniqueRoute, err error)

AddRoute will add a new route to the paths object for the openapi spec

func (*OpenAPI) AddTag

func (o *OpenAPI) AddTag(tag, description string)

func (*OpenAPI) AddTags

func (o *OpenAPI) AddTags(t Tags)

func (*OpenAPI) JSON

func (o *OpenAPI) JSON() string

JSON returns the json string value for the OpenAPI object

type Operation

type Operation struct {
	Tags         []string      `json:"tags,omitempty"`
	Summary      string        `json:"summary,omitempty"`
	Desc         string        `json:"description,omitempty"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
	OperationID  string        `json:"operationId,omitempty"`
	Params       []Param       `json:"parameters,omitempty"`  // A list of parameters that are applicable for this operation.
	RequestBody  *RequestBody  `json:"requestBody,omitempty"` // The request body applicable for this operation.
	Responses    Responses     `json:"responses,omitempty"`   // key 200,400 REQUIRED. The list of possible responses as they are returned from executing this operation.
}

type OperationMap

type OperationMap map[Method]Operation // map of methods to a openAPI Operation object

type Param

type Param struct {
	Name string `json:"name,omitempty"`        // REQUIRED. The name of the parameter. Parameter names are case sensitive.
	Desc string `json:"description,omitempty"` // A brief description of the parameter. This could contain examples of use. CommonMark syntax MAY be used for rich text representation.
	In   string `json:"in"`                    // REQUIRED. The location of the parameter. Possible values are "query", "header", "path" or "cookie".
}

type Params

type Params map[string]Param

type Paths

type Paths map[string]OperationMap

type Properties

type Properties map[string]Property

func (Properties) Construct

func (pr Properties) Construct(item any)

type Property

type Property struct {
	Type       string `json:"type"`
	Format     string `json:"format"`
	Desc       string `json:"description"`
	Properties `json:"properties"`
	Items      *Schema `json:"items"`
}

type Ref

type Ref struct {
	Ref string `json:"$ref"`
}

type Reference

type Reference string

type RequestBody

type RequestBody struct {
	Desc     string             `json:"description,omitempty"`
	Content  map[MIMEType]Media `json:"content,omitempty"`
	Required *bool              `json:"required,omitempty"`
}

type Requests

type Requests map[string]RequestBody

key is the reference name for the open api spec

type Response

type Response struct {
	Desc    string           `json:"description,omitempty"`
	Content map[string]Media `json:"content,omitempty"`
}

type Responses

type Responses map[string]Response

type Route

type Route struct {
	Tag       string
	Desc      string
	Content   MIMEType
	ReqType   Type                  // the request type for the path i.e., array, object, string, integer
	RespType  Type                  // the response type for the path i.e., array, object, string, integer
	Responses map[string]RouteResp  // key references for responses
	Params    map[string]RouteParam // key reference for params
	Requests  map[string]RouteReq   // key reference for requests
}

type RouteParam

type RouteParam struct {
	Name     string // unique name reference
	Desc     string // A brief description of the parameter. This could contain examples of use. CommonMark syntax MAY be used for rich text representation.
	Required bool   // is this paramater required
	Location string // REQUIRED. The location of the parameter. Possible values are "query", "header", "path" or "cookie".
	Example  map[string]any
}

type RouteReq

type RouteReq struct {
	Content MIMEType
	Ref     Reference
	Array   bool
}

type RouteResp

type RouteResp struct {
	Code    string // response code (as a string) "200","400","302"
	Content MIMEType
	Ref     Reference // the reference name for the response object
	Array   bool      // is the response object an array
}

type Schema

type Schema struct {
	AddProperties *Schema    `json:"additionalProperties"`
	Title         string     `json:"title,omitempty"`
	Desc          string     `json:"description,omitempty"`
	Type          string     `json:"type,omitempty"`
	Items         *Schema    `json:"items"`
	Properties    Properties `json:"properties,omitempty"`
}

type Schemas

type Schemas map[string]Schema

type Server

type Server struct {
	URL  string               `json:"url"`         // REQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the OpenAPI document is being served. Variable substitutions will be made when a variable is named in {brackets}.
	Desc string               `json:"description"` // An optional string describing the host designated by the URL. CommonMark syntax MAY be used for rich text representation.
	Vars map[string]ServerVar `json:"variables"`   // A map between a variable name and its value. The value is used for substitution in the server's URL template.
}

type ServerVar

type ServerVar struct {
	Enum    []string `json:"enum"`        // An enumeration of string values to be used if the substitution options are from a limited set. The array SHOULD NOT be empty.
	Default string   `json:"default"`     // REQUIRED. The default value to use for substitution, which SHALL be sent if an alternate value is not supplied. Note this behavior is different than the Schema Object's treatment of default values, because in those cases parameter values are optional. If the enum is defined, the value SHOULD exist in the enum's values.
	Desc    string   `json:"description"` // An optional description for the server variable. CommonMark syntax MAY be used for rich text representation.
}

type Tag

type Tag struct {
	Name         string        `json:"name"`
	Desc         string        `json:"description"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
}

type Tags

type Tags []Tag

type Type

type Type int
const (
	Integer Type = iota + 1
	Number
	String
	Boolean
	Object
	Array
)

func (Type) String

func (t Type) String() string

type UniqueRoute

type UniqueRoute struct {
	Path   string
	Method Method
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL