Documentation
¶
Index ¶
- func NewComponentRefer(group string, id string) jsonschema.Refer
- type Callback
- type CallbackObject
- type Components
- type ComponentsObject
- func (object *ComponentsObject) AddParameter(id string, p *Parameter)
- func (object *ComponentsObject) AddRequestBody(id string, e *RequestBody)
- func (object *ComponentsObject) AddResponse(id string, r *Response)
- func (object *ComponentsObject) AddSchema(id string, s *jsonschema.Schema)
- func (object *ComponentsObject) RefCallback(id string) *Callback
- func (object *ComponentsObject) RefExample(id string) *Example
- func (object *ComponentsObject) RefHeader(id string) *Header
- func (object *ComponentsObject) RefLink(id string) *Link
- func (object *ComponentsObject) RefParameter(id string) *Parameter
- func (object *ComponentsObject) RefRequestBody(id string) *RequestBody
- func (object *ComponentsObject) RefResponse(id string) *Response
- func (object *ComponentsObject) RefSchema(id string) *jsonschema.Schema
- func (object *ComponentsObject) RequireSecurity(id string, scopes ...string) SecurityRequirement
- type Contact
- type ContactObject
- type Encoding
- type EncodingObject
- type Example
- type ExampleObject
- type ExternalDoc
- type Header
- type HttpMethod
- type Info
- type InfoObject
- type License
- type LicenseObject
- type Link
- type LinkObject
- type MediaType
- type MediaTypeObject
- type OAuthFlow
- type OAuthFlowObject
- type OAuthFlows
- type OAuthFlowsObject
- type OpenAPI
- type OpenAPIObject
- type Operation
- type OperationGetter
- type OperationObject
- type Operations
- type Parameter
- type ParameterCommonObject
- type ParameterObject
- type ParameterStyle
- type PathItem
- type PathItemObject
- type Paths
- type Position
- type Reference
- type RequestBody
- type RequestBodyObject
- type Response
- type ResponseObject
- type Responses
- type ResponsesObject
- type RuntimeExpression
- type Schema
- type SecurityRequirement
- type SecurityScheme
- func NewAPIKeySecurityScheme(name string, in Position) *SecurityScheme
- func NewHTTPSecurityScheme(scheme string, bearerFormat string) *SecurityScheme
- func NewOAuth2SecurityScheme(oauthFlowsObject OAuthFlowsObject) *SecurityScheme
- func NewOpenIdConnectSecurityScheme(openIdConnectUrl string) *SecurityScheme
- type SecuritySchemeObject
- type SecurityType
- type Server
- type ServerObject
- type ServerVariable
- type ServerVariableObject
- type SpecExtensions
- type Tag
- type TagObject
- type WithCallbacks
- type WithContent
- type WithContentOrSchema
- type WithEncoding
- type WithExamples
- type WithHeaders
- type WithLinks
- type WithSecurityRequirement
- type WithSecuritySchemes
- type WithServers
- type WithTags
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewComponentRefer ¶
func NewComponentRefer(group string, id string) jsonschema.Refer
Types ¶
type Callback ¶
type Callback struct { Reference CallbackObject SpecExtensions }
func NewCallback ¶
func NewCallback(method HttpMethod, rule RuntimeExpression, op *Operation) *Callback
func (Callback) MarshalJSON ¶
func (*Callback) UnmarshalJSON ¶
type CallbackObject ¶
type CallbackObject map[RuntimeExpression]*PathItem
type Components ¶
type Components struct { ComponentsObject jsonschema.VendorExtensible }
func (Components) MarshalJSON ¶
func (i Components) MarshalJSON() ([]byte, error)
func (*Components) UnmarshalJSON ¶
func (i *Components) UnmarshalJSON(data []byte) error
type ComponentsObject ¶
type ComponentsObject struct { Schemas map[string]*Schema `json:"schemas,omitempty"` Responses map[string]*Response `json:"responses,omitempty"` Parameters map[string]*Parameter `json:"parameters,omitempty"` WithExamples RequestBodies map[string]*RequestBody `json:"requestBodies,omitempty"` WithHeaders WithSecuritySchemes WithLinks WithCallbacks }
func (*ComponentsObject) AddParameter ¶
func (object *ComponentsObject) AddParameter(id string, p *Parameter)
func (*ComponentsObject) AddRequestBody ¶
func (object *ComponentsObject) AddRequestBody(id string, e *RequestBody)
func (*ComponentsObject) AddResponse ¶
func (object *ComponentsObject) AddResponse(id string, r *Response)
func (*ComponentsObject) AddSchema ¶
func (object *ComponentsObject) AddSchema(id string, s *jsonschema.Schema)
func (*ComponentsObject) RefCallback ¶
func (object *ComponentsObject) RefCallback(id string) *Callback
func (*ComponentsObject) RefExample ¶
func (object *ComponentsObject) RefExample(id string) *Example
func (*ComponentsObject) RefHeader ¶
func (object *ComponentsObject) RefHeader(id string) *Header
func (*ComponentsObject) RefLink ¶
func (object *ComponentsObject) RefLink(id string) *Link
func (*ComponentsObject) RefParameter ¶
func (object *ComponentsObject) RefParameter(id string) *Parameter
func (*ComponentsObject) RefRequestBody ¶
func (object *ComponentsObject) RefRequestBody(id string) *RequestBody
func (*ComponentsObject) RefResponse ¶
func (object *ComponentsObject) RefResponse(id string) *Response
func (*ComponentsObject) RefSchema ¶
func (object *ComponentsObject) RefSchema(id string) *jsonschema.Schema
func (*ComponentsObject) RequireSecurity ¶
func (object *ComponentsObject) RequireSecurity(id string, scopes ...string) SecurityRequirement
type Contact ¶
type Contact struct { ContactObject SpecExtensions }
func (Contact) MarshalJSON ¶
func (*Contact) UnmarshalJSON ¶
type ContactObject ¶
type Encoding ¶
type Encoding struct { EncodingObject SpecExtensions }
func NewEncoding ¶
func NewEncoding() *Encoding
func (Encoding) MarshalJSON ¶
func (*Encoding) UnmarshalJSON ¶
type EncodingObject ¶
type EncodingObject struct { ContentType string `json:"contentType,omitempty"` WithHeaders Style ParameterStyle `json:"style,omitempty"` Explode bool `json:"explode,omitempty"` AllowReserved bool `json:"allowReserved,omitempty"` }
type Example ¶
type Example struct { Reference ExampleObject SpecExtensions }
func NewExample ¶
func NewExample() *Example
func (Example) MarshalJSON ¶
func (*Example) UnmarshalJSON ¶
type ExampleObject ¶
type ExternalDoc ¶
type ExternalDoc = jsonschema.ExternalDoc
type Header ¶
type Header struct { Reference ParameterCommonObject SpecExtensions }
func NewHeaderWithSchema ¶
func (Header) MarshalJSON ¶
func (*Header) UnmarshalJSON ¶
type HttpMethod ¶
type HttpMethod string
const ( GET HttpMethod = "get" PUT HttpMethod = "put" POST HttpMethod = "post" DELETE HttpMethod = "delete" OPTIONS HttpMethod = "options" HEAD HttpMethod = "head" PATCH HttpMethod = "patch" TRACE HttpMethod = "trace" )
type Info ¶
type Info struct { InfoObject SpecExtensions }
func (Info) MarshalJSON ¶
func (*Info) UnmarshalJSON ¶
type InfoObject ¶
type License ¶
type License struct { LicenseObject SpecExtensions }
func (License) MarshalJSON ¶
func (*License) UnmarshalJSON ¶
type LicenseObject ¶
type Link ¶
type Link struct { Reference LinkObject SpecExtensions }
func (Link) MarshalJSON ¶
func (*Link) UnmarshalJSON ¶
type LinkObject ¶
type LinkObject struct { OperationRef string `json:"operationRef,omitempty"` OperationId string `json:"operationId,omitempty"` Parameters map[string]RuntimeExpression `json:"parameters,omitempty"` RequestBody RuntimeExpression `json:"requestBody,omitempty"` Description string `json:"description,omitempty"` Server *Server `json:"server,omitempty"` }
func (*LinkObject) AddParameter ¶
func (o *LinkObject) AddParameter(name string, expr RuntimeExpression)
func (*LinkObject) SetRequestBody ¶
func (o *LinkObject) SetRequestBody(expr RuntimeExpression)
type MediaType ¶
type MediaType struct { MediaTypeObject SpecExtensions }
func NewMediaTypeWithSchema ¶
func (MediaType) MarshalJSON ¶
func (*MediaType) UnmarshalJSON ¶
type MediaTypeObject ¶
type MediaTypeObject struct { Schema *Schema `json:"schema,omitempty"` Example interface{} `json:"example,omitempty"` WithExamples WithEncoding }
type OAuthFlow ¶
type OAuthFlow struct { OAuthFlowObject SpecExtensions }
func NewOAuthFlow ¶
func (OAuthFlow) MarshalJSON ¶
func (*OAuthFlow) UnmarshalJSON ¶
type OAuthFlowObject ¶
type OAuthFlows ¶
type OAuthFlows struct { OAuthFlowsObject SpecExtensions }
func (OAuthFlows) MarshalJSON ¶
func (i OAuthFlows) MarshalJSON() ([]byte, error)
func (*OAuthFlows) UnmarshalJSON ¶
func (i *OAuthFlows) UnmarshalJSON(data []byte) error
type OAuthFlowsObject ¶
type OpenAPI ¶
type OpenAPI struct { OpenAPIObject SpecExtensions }
Example ¶
openapi := NewOpenAPI() openapi.Version = "1.0.0" openapi.Title = "Swagger Petstore" openapi.License = &License{ LicenseObject: LicenseObject{ Name: "MIT", }, } openapi.AddTag(nil) openapi.AddTag(NewTag("pets")) openapi.AddSecurityScheme("token", NewHTTPSecurityScheme("bearer", "JWT")) openapi.AddServer(NewServer("http://petstore.swagger.io/v1")) openapi.AddSchema("Pet", jsonschema.ObjectOf(jsonschema.Props{ "id": jsonschema.Long(), "name": jsonschema.String(), "tag": jsonschema.String(), }, "id", "name")) openapi.AddSchema("Pets", jsonschema.ItemsOf(openapi.RefSchema("Pet"))) openapi.AddSchema("Error", jsonschema.ObjectOf(jsonschema.Props{ "code": jsonschema.Integer(), "message": jsonschema.String(), }, "code", "message")) { op := NewOperation("listPets") op.Summary = "List all pets" op.Tags = []string{"pets"} parameterLimit := QueryParameter("limit", jsonschema.Integer(), false). WithDesc("How many items to return at one time (max 100)") op.AddParameter(parameterLimit) { resp := NewResponse("An paged array of pets") s := jsonschema.String() s.Description = "A link to the next page of responses" resp.AddHeader("x-next", NewHeaderWithSchema(s)) resp.AddContent("application/json", NewMediaTypeWithSchema(openapi.RefSchema("Pets"))) op.AddResponse(http.StatusOK, resp) } { resp := NewResponse("unexpected error") resp.AddContent("application/json", NewMediaTypeWithSchema(openapi.RefSchema("Error"))) op.SetDefaultResponse(resp) } openapi.AddOperation(GET, "/pets", op) } { op := NewOperation("createPets") op.Summary = "Create a pet" op.Tags = []string{"pets"} { resp := NewResponse("Null response") op.AddResponse(http.StatusNoContent, resp) } { resp := NewResponse("unexpected error") resp.AddContent("application/json", NewMediaTypeWithSchema(openapi.RefSchema("Error"))) op.SetDefaultResponse(resp) } openapi.AddOperation(POST, "/pets", op) } data, _ := json.MarshalIndent(openapi, "\t", "\t") fmt.Println(string(data)) // Output
Output:
func NewOpenAPI ¶
func NewOpenAPI() *OpenAPI
func (OpenAPI) MarshalJSON ¶
func (*OpenAPI) UnmarshalJSON ¶
type OpenAPIObject ¶
type OpenAPIObject struct { OpenAPI string `json:"openapi"` Info `json:"info"` Paths `json:"paths"` WithServers WithSecurityRequirement WithTags Components `json:"components"` }
type Operation ¶
type Operation struct { OperationObject SpecExtensions }
func NewOperation ¶
func (Operation) MarshalJSON ¶
func (*Operation) UnmarshalJSON ¶
func (Operation) WithSummary ¶
type OperationGetter ¶
type OperationGetter interface {
OpenAPIOperation(ref func(t string) jsonschema.Refer) *Operation
}
type OperationObject ¶
type OperationObject struct { Tags []string `json:"tags,omitempty"` Summary string `json:"summary,omitempty"` Description string `json:"description,omitempty"` OperationId string `json:"operationId"` Parameters []*Parameter `json:"parameters,omitempty"` RequestBody *RequestBody `json:"requestBody,omitempty"` Responses Responses `json:"responses"` ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"` WithCallbacks WithSecurityRequirement WithServers Deprecated bool `json:"deprecated,omitempty"` }
func (*OperationObject) AddParameter ¶
func (object *OperationObject) AddParameter(p *Parameter)
func (*OperationObject) AddResponse ¶
func (o *OperationObject) AddResponse(statusCode int, r *Response)
func (*OperationObject) SetDefaultResponse ¶
func (o *OperationObject) SetDefaultResponse(r *Response)
func (*OperationObject) SetRequestBody ¶
func (o *OperationObject) SetRequestBody(rb *RequestBody)
type Operations ¶
type Operations struct {
Operations map[HttpMethod]*Operation
}
func (*Operations) AddOperation ¶
func (v *Operations) AddOperation(method HttpMethod, op *Operation)
func (Operations) MarshalJSON ¶
func (v Operations) MarshalJSON() ([]byte, error)
func (*Operations) UnmarshalJSON ¶
func (v *Operations) UnmarshalJSON(data []byte) error
type Parameter ¶
type Parameter struct { Reference ParameterObject SpecExtensions }
func PathParameter ¶
func (Parameter) MarshalJSON ¶
func (*Parameter) UnmarshalJSON ¶
type ParameterCommonObject ¶
type ParameterCommonObject struct { Description string `json:"description,omitempty"` Required bool `json:"required,omitempty"` Deprecated bool `json:"deprecated,omitempty"` AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` Style ParameterStyle `json:"style,omitempty"` Explode bool `json:"explode,omitempty"` AllowReserved bool `json:"allowReserved,omitempty"` WithContentOrSchema Example interface{} `json:"example,omitempty"` WithExamples }
type ParameterObject ¶
type ParameterObject struct { Name string `json:"name"` In Position `json:"in"` ParameterCommonObject }
type ParameterStyle ¶
type ParameterStyle string
const ( // https://tools.ietf.org/html/rfc6570#section-3.2.7 ParameterStyleMatrix ParameterStyle = "matrix" // https://tools.ietf.org/html/rfc6570#section-3.2.5 ParameterStyleLabel ParameterStyle = "label" // https://tools.ietf.org/html/rfc6570#section-3.2.8 ParameterStyleForm ParameterStyle = "form" // for array, csv https://tools.ietf.org/html/rfc6570#section-3.2.2 ParameterStyleSimple ParameterStyle = "simple" // for array, ssv ParameterStyleSpaceDelimited ParameterStyle = "spaceDelimited" // for array, pipes ParameterStylePipeDelimited ParameterStyle = "pipeDelimited" // for object ParameterStyleDeepObject ParameterStyle = "deepObject" )
type PathItem ¶
type PathItem struct { Operations PathItemObject SpecExtensions }
func (PathItem) MarshalJSON ¶
func (*PathItem) UnmarshalJSON ¶
type PathItemObject ¶
type Paths ¶
type Paths struct { Paths map[string]*PathItem SpecExtensions }
func (*Paths) AddOperation ¶
func (p *Paths) AddOperation(method HttpMethod, path string, op *Operation)
func (Paths) MarshalJSON ¶
func (*Paths) UnmarshalJSON ¶
type Reference ¶
type Reference = jsonschema.Reference
type RequestBody ¶
type RequestBody struct { Reference RequestBodyObject SpecExtensions }
func NewRequestBody ¶
func NewRequestBody(desc string, required bool) *RequestBody
func (RequestBody) MarshalJSON ¶
func (r RequestBody) MarshalJSON() ([]byte, error)
func (*RequestBody) UnmarshalJSON ¶
func (r *RequestBody) UnmarshalJSON(data []byte) error
type RequestBodyObject ¶
type RequestBodyObject struct { Description string `json:"description,omitempty"` Required bool `json:"required,omitempty"` WithContent }
type Response ¶
type Response struct { Reference ResponseObject SpecExtensions }
func NewResponse ¶
func (Response) MarshalJSON ¶
func (*Response) UnmarshalJSON ¶
type ResponseObject ¶
type ResponseObject struct { Description string `json:"description"` WithHeaders WithContent WithLinks }
type Responses ¶
type Responses struct { ResponsesObject SpecExtensions }
func (Responses) MarshalJSON ¶
func (*Responses) UnmarshalJSON ¶
type ResponsesObject ¶
func (*ResponsesObject) AddResponse ¶
func (o *ResponsesObject) AddResponse(statusCode int, r *Response)
func (ResponsesObject) MarshalJSON ¶
func (o ResponsesObject) MarshalJSON() ([]byte, error)
func (*ResponsesObject) SetDefaultResponse ¶
func (o *ResponsesObject) SetDefaultResponse(r *Response)
func (*ResponsesObject) UnmarshalJSON ¶
func (o *ResponsesObject) UnmarshalJSON(data []byte) error
type RuntimeExpression ¶
type RuntimeExpression string
type Schema ¶
type Schema = jsonschema.Schema
type SecurityRequirement ¶
type SecurityScheme ¶
type SecurityScheme struct { SecuritySchemeObject SpecExtensions }
func NewAPIKeySecurityScheme ¶
func NewAPIKeySecurityScheme(name string, in Position) *SecurityScheme
func NewHTTPSecurityScheme ¶
func NewHTTPSecurityScheme(scheme string, bearerFormat string) *SecurityScheme
func NewOAuth2SecurityScheme ¶
func NewOAuth2SecurityScheme(oauthFlowsObject OAuthFlowsObject) *SecurityScheme
func NewOpenIdConnectSecurityScheme ¶
func NewOpenIdConnectSecurityScheme(openIdConnectUrl string) *SecurityScheme
func (SecurityScheme) MarshalJSON ¶
func (i SecurityScheme) MarshalJSON() ([]byte, error)
func (*SecurityScheme) UnmarshalJSON ¶
func (i *SecurityScheme) UnmarshalJSON(data []byte) error
type SecuritySchemeObject ¶
type SecuritySchemeObject struct { Type SecurityType `json:"type"` Description string `json:"description,omitempty"` Name string `json:"name,omitempty"` In Position `json:"in,omitempty"` Scheme string `json:"scheme,omitempty"` BearerFormat string `json:"bearerFormat,omitempty"` Flows *OAuthFlows `json:"flows,omitempty"` OpenIdConnectUrl string `json:"openIdConnectUrl,omitempty"` }
type SecurityType ¶
type SecurityType string
const ( SecurityTypeAPIKey SecurityType = "apiKey" SecurityTypeHttp SecurityType = "http" SecurityTypeOAuth2 SecurityType = "oauth2" SecurityTypeOpenIdConnect SecurityType = "openIdConnect" )
type Server ¶
type Server struct { ServerObject SpecExtensions }
func (Server) MarshalJSON ¶
func (*Server) UnmarshalJSON ¶
type ServerObject ¶
type ServerObject struct { URL string `json:"url"` Description string `json:"description,omitempty"` Variables map[string]*ServerVariable `json:"variables,omitempty"` }
func (*ServerObject) AddVariable ¶
func (o *ServerObject) AddVariable(key string, v *ServerVariable)
type ServerVariable ¶
type ServerVariable struct { ServerVariableObject SpecExtensions }
func NewServerVariable ¶
func NewServerVariable(defaultValue string) *ServerVariable
func (ServerVariable) MarshalJSON ¶
func (i ServerVariable) MarshalJSON() ([]byte, error)
func (*ServerVariable) UnmarshalJSON ¶
func (i *ServerVariable) UnmarshalJSON(data []byte) error
type ServerVariableObject ¶
type SpecExtensions ¶
type SpecExtensions = jsonschema.VendorExtensible
type Tag ¶
type Tag struct { TagObject SpecExtensions }
func (Tag) MarshalJSON ¶
func (*Tag) UnmarshalJSON ¶
type TagObject ¶
type TagObject struct { Name string `json:"name"` Description string `json:"description,omitempty"` ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"` }
type WithCallbacks ¶
func (*WithCallbacks) AddCallback ¶
func (o *WithCallbacks) AddCallback(name string, c *Callback)
type WithContent ¶
func (*WithContent) AddContent ¶
func (o *WithContent) AddContent(contentType string, mt *MediaType)
type WithContentOrSchema ¶
type WithContentOrSchema struct { Schema *Schema `json:"schema,omitempty"` WithContent }
func (*WithContentOrSchema) AddContent ¶
func (o *WithContentOrSchema) AddContent(contentType string, mt *MediaType)
func (*WithContentOrSchema) SetSchema ¶
func (o *WithContentOrSchema) SetSchema(s *Schema)
type WithEncoding ¶
func (*WithEncoding) AddEncoding ¶
func (o *WithEncoding) AddEncoding(name string, e *Encoding)
type WithExamples ¶
func (*WithExamples) AddExample ¶
func (o *WithExamples) AddExample(name string, e *Example)
type WithHeaders ¶
func (*WithHeaders) AddHeader ¶
func (object *WithHeaders) AddHeader(name string, h *Header)
type WithSecurityRequirement ¶
type WithSecurityRequirement struct {
Security []*SecurityRequirement `json:"security,omitempty"`
}
func (*WithSecurityRequirement) AddSecurityRequirement ¶
func (o *WithSecurityRequirement) AddSecurityRequirement(sr *SecurityRequirement)
type WithSecuritySchemes ¶
type WithSecuritySchemes struct {
SecuritySchemes map[string]*SecurityScheme `json:"securitySchemes,omitempty"`
}
func (*WithSecuritySchemes) AddSecurityScheme ¶
func (o *WithSecuritySchemes) AddSecurityScheme(name string, ss *SecurityScheme)
type WithServers ¶
type WithServers struct {
Servers []*Server `json:"servers,omitempty"`
}
func (*WithServers) AddServer ¶
func (o *WithServers) AddServer(s *Server)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.