oas

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 6 Imported by: 2

README

OpenAPI Spec Builder

GoDoc Widget Build Status codecov Go Report Card

OpenAPI Spec 3.0.3 builder for Golang

Usage

go get gitee.com/go-genie/oas

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback struct {
	Reference
	CallbackObject
	SpecExtensions
}

func NewCallback

func NewCallback(method HttpMethod, rule RuntimeExpression, op *Operation) *Callback

func (Callback) MarshalJSON

func (i Callback) MarshalJSON() ([]byte, error)

func (*Callback) UnmarshalJSON

func (i *Callback) UnmarshalJSON(data []byte) error

type CallbackObject

type CallbackObject map[RuntimeExpression]*PathItem

type ComponentRefer

type ComponentRefer struct {
	Group string
	ID    string
}

func NewComponentRefer

func NewComponentRefer(group string, id string) *ComponentRefer

func ParseComponentRefer

func ParseComponentRefer(ref string) *ComponentRefer

func (ComponentRefer) RefString

func (ref ComponentRefer) RefString() string

type Components

type Components struct {
	ComponentsObject
	SpecExtensions
}

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 *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 (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) *Schema

func (*ComponentsObject) RequireSecurity

func (object *ComponentsObject) RequireSecurity(id string, scopes ...string) SecurityRequirement

type Contact

type Contact struct {
	ContactObject
	SpecExtensions
}

func (Contact) MarshalJSON

func (i Contact) MarshalJSON() ([]byte, error)

func (*Contact) UnmarshalJSON

func (i *Contact) UnmarshalJSON(data []byte) error

type ContactObject

type ContactObject struct {
	Name  string `json:"name,omitempty"`
	URL   string `json:"url,omitempty"`
	Email string `json:"email,omitempty"`
}

type Discriminator

type Discriminator struct {
	PropertyName string            `json:"propertyName"`
	Mapping      map[string]string `json:"mapping,omitempty"`
}

type Encoding

type Encoding struct {
	EncodingObject
	SpecExtensions
}

func NewEncoding

func NewEncoding() *Encoding

func (Encoding) MarshalJSON

func (i Encoding) MarshalJSON() ([]byte, error)

func (*Encoding) UnmarshalJSON

func (i *Encoding) UnmarshalJSON(data []byte) error

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 (e Example) MarshalJSON() ([]byte, error)

func (*Example) UnmarshalJSON

func (e *Example) UnmarshalJSON(data []byte) error

type ExampleObject

type ExampleObject struct {
	Summary       string      `json:"summary,omitempty"`
	Description   string      `json:"description,omitempty"`
	Value         interface{} `json:"value,omitempty"`
	ExternalValue string      `json:"externalValue,omitempty"`
}

type ExternalDoc

type ExternalDoc struct {
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
}

func NewExternalDoc

func NewExternalDoc(url string, desc string) *ExternalDoc

func NewHeaderWithSchema

func NewHeaderWithSchema(s *Schema) *Header

func (Header) MarshalJSON

func (h Header) MarshalJSON() ([]byte, error)

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(data []byte) error

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 (i Info) MarshalJSON() ([]byte, error)

func (*Info) UnmarshalJSON

func (i *Info) UnmarshalJSON(data []byte) error

type InfoObject

type InfoObject struct {
	Title          string `json:"title"`
	Description    string `json:"description,omitempty"`
	TermsOfService string `json:"termsOfService,omitempty"`
	*Contact       `json:"contact,omitempty"`
	*License       `json:"license,omitempty"`
	Version        string `json:"version"`
}

type License

type License struct {
	LicenseObject
	SpecExtensions
}

func (License) MarshalJSON

func (i License) MarshalJSON() ([]byte, error)

func (*License) UnmarshalJSON

func (i *License) UnmarshalJSON(data []byte) error

type LicenseObject

type LicenseObject struct {
	Name string `json:"name"`
	URL  string `json:"url,omitempty"`
}
type Link struct {
	Reference
	LinkObject
	SpecExtensions
}
func NewLink(operationId string) *Link

func (Link) MarshalJSON

func (l Link) MarshalJSON() ([]byte, error)

func (*Link) UnmarshalJSON

func (l *Link) UnmarshalJSON(data []byte) error

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 NewMediaTypeWithSchema(s *Schema) *MediaType

func (MediaType) MarshalJSON

func (i MediaType) MarshalJSON() ([]byte, error)

func (*MediaType) UnmarshalJSON

func (i *MediaType) UnmarshalJSON(data []byte) error

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 NewOAuthFlow(authorizationURL string, tokenURL string, refreshURL string, scopes map[string]string) *OAuthFlow

func (OAuthFlow) MarshalJSON

func (i OAuthFlow) MarshalJSON() ([]byte, error)

func (*OAuthFlow) UnmarshalJSON

func (i *OAuthFlow) UnmarshalJSON(data []byte) error

type OAuthFlowObject

type OAuthFlowObject struct {
	AuthorizationURL string            `json:"authorizationUrl"`
	TokenURL         string            `json:"tokenUrl"`
	RefreshURL       string            `json:"refreshUrl,omitempty"`
	Scopes           map[string]string `json:"scopes"`
}

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 OAuthFlowsObject struct {
	Implicit          *OAuthFlow `json:"implicit,omitempty"`
	Password          *OAuthFlow `json:"password,omitempty"`
	ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty"`
	AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty"`
}

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", ObjectOf(Props{
	"id":   Long(),
	"name": String(),
	"tag":  String(),
}, "id", "name"))

openapi.AddSchema("Pets", ItemsOf(openapi.RefSchema("Pet")))

openapi.AddSchema("Error", ObjectOf(Props{
	"code":    Integer(),
	"message": String(),
}, "code", "message"))

{
	op := NewOperation("listPets")
	op.Summary = "List all pets"
	op.Tags = []string{"pets"}

	parameterLimit := QueryParameter("limit", Integer(), false).
		WithDesc("How many items to return at one time (max 100)")

	op.AddParameter(parameterLimit)

	{
		resp := NewResponse("An paged array of pets")

		s := 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:
{
	"openapi": "3.0.3",
	"info": {
		"title": "Swagger Petstore",
		"license": {
			"name": "MIT"
		},
		"version": "1.0.0"
	},
	"paths": {
		"/pets": {
			"get": {
				"tags": [
					"pets"
				],
				"summary": "List all pets",
				"operationId": "listPets",
				"parameters": [
					{
						"name": "limit",
						"in": "query",
						"description": "How many items to return at one time (max 100)",
						"schema": {
							"type": "integer",
							"format": "int32"
						}
					}
				],
				"responses": {
					"200": {
						"description": "An paged array of pets",
						"headers": {
							"x-next": {
								"schema": {
									"type": "string",
									"description": "A link to the next page of responses"
								}
							}
						},
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/Pets"
								}
							}
						}
					},
					"default": {
						"description": "unexpected error",
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/Error"
								}
							}
						}
					}
				}
			},
			"post": {
				"tags": [
					"pets"
				],
				"summary": "Create a pet",
				"operationId": "createPets",
				"responses": {
					"204": {
						"description": "Null response"
					},
					"default": {
						"description": "unexpected error",
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/Error"
								}
							}
						}
					}
				}
			}
		}
	},
	"servers": [
		{
			"url": "http://petstore.swagger.io/v1"
		}
	],
	"tags": [
		{
			"name": "pets"
		}
	],
	"components": {
		"schemas": {
			"Error": {
				"type": "object",
				"properties": {
					"code": {
						"type": "integer",
						"format": "int32"
					},
					"message": {
						"type": "string"
					}
				},
				"required": [
					"code",
					"message"
				]
			},
			"Pet": {
				"type": "object",
				"properties": {
					"id": {
						"type": "integer",
						"format": "int64"
					},
					"name": {
						"type": "string"
					},
					"tag": {
						"type": "string"
					}
				},
				"required": [
					"id",
					"name"
				]
			},
			"Pets": {
				"type": "array",
				"items": {
					"$ref": "#/components/schemas/Pet"
				}
			}
		},
		"securitySchemes": {
			"token": {
				"type": "http",
				"scheme": "bearer",
				"bearerFormat": "JWT"
			}
		}
	}
}
*/}
			}
		},
		"securitySchemes": {
			"token": {
				"type": "http",
				"scheme": "bearer",
				"bearerFormat": "JWT"
			}
		}
	}
}
*/
Output:

	{
		"openapi": "3.0.3",
		"info": {
			"title": "Swagger Petstore",
			"license": {
				"name": "MIT"
			},
			"version": "1.0.0"
		},
		"paths": {
			"/pets": {
				"get": {
					"tags": [
						"pets"
					],
					"summary": "List all pets",
					"operationId": "listPets",
					"parameters": [
						{
							"name": "limit",
							"in": "query",
							"description": "How many items to return at one time (max 100)",
							"schema": {
								"type": "integer",
								"format": "int32"
							}
						}
					],
					"responses": {
						"200": {
							"description": "An paged array of pets",
							"headers": {
								"x-next": {
									"schema": {
										"type": "string",
										"description": "A link to the next page of responses"
									}
								}
							},
							"content": {
								"application/json": {
									"schema": {
										"$ref": "#/components/schemas/Pets"
									}
								}
							}
						},
						"default": {
							"description": "unexpected error",
							"content": {
								"application/json": {
									"schema": {
										"$ref": "#/components/schemas/Error"
									}
								}
							}
						}
					}
				},
				"post": {
					"tags": [
						"pets"
					],
					"summary": "Create a pet",
					"operationId": "createPets",
					"responses": {
						"204": {
							"description": "Null response"
						},
						"default": {
							"description": "unexpected error",
							"content": {
								"application/json": {
									"schema": {
										"$ref": "#/components/schemas/Error"
									}
								}
							}
						}
					}
				}
			}
		},
		"servers": [
			{
				"url": "http://petstore.swagger.io/v1"
			}
		],
		"tags": [
			{
				"name": "pets"
			}
		],
		"components": {
			"schemas": {
				"Error": {
					"type": "object",
					"properties": {
						"code": {
							"type": "integer",
							"format": "int32"
						},
						"message": {
							"type": "string"
						}
					},
					"required": [
						"code",
						"message"
					]
				},
				"Pet": {
					"type": "object",
					"properties": {
						"id": {
							"type": "integer",
							"format": "int64"
						},
						"name": {
							"type": "string"
						},
						"tag": {
							"type": "string"
						}
					},
					"required": [
						"id",
						"name"
					]
				},
				"Pets": {
					"type": "array",
					"items": {
						"$ref": "#/components/schemas/Pet"
					}
				}
			},
			"securitySchemes": {
				"token": {
					"type": "http",
					"scheme": "bearer",
					"bearerFormat": "JWT"
				}
			}
		}
	}

func NewOpenAPI

func NewOpenAPI() *OpenAPI

func (OpenAPI) MarshalJSON

func (i OpenAPI) MarshalJSON() ([]byte, error)

func (*OpenAPI) UnmarshalJSON

func (i *OpenAPI) UnmarshalJSON(data []byte) error

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 NewOperation(operationId string) *Operation

func (Operation) MarshalJSON

func (op Operation) MarshalJSON() ([]byte, error)

func (*Operation) UnmarshalJSON

func (op *Operation) UnmarshalJSON(data []byte) error

func (Operation) WithDesc

func (op Operation) WithDesc(desc string) *Operation

func (Operation) WithSummary

func (op Operation) WithSummary(summary string) *Operation

func (Operation) WithTags

func (op Operation) WithTags(tags ...string) *Operation

type OperationObject

type OperationObject struct {
	Tags         []string     `json:"tags,omitempty"`
	Summary      string       `json:"summary,omitempty"`
	Description  string       `json:"description,omitempty"`
	ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"`

	OperationId string `json:"operationId"`
	WithParameters
	RequestBody *RequestBody `json:"requestBody,omitempty"`
	Responses   Responses    `json:"responses"`
	WithCallbacks
	WithSecurityRequirement
	Deprecated bool `json:"deprecated,omitempty"`
	WithServers
}

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 CookieParameter

func CookieParameter(name string, s *Schema, required bool) *Parameter

func HeaderParameter

func HeaderParameter(name string, s *Schema, required bool) *Parameter

func PathParameter

func PathParameter(name string, s *Schema) *Parameter

func QueryParameter

func QueryParameter(name string, s *Schema, required bool) *Parameter

func (Parameter) MarshalJSON

func (p Parameter) MarshalJSON() ([]byte, error)

func (*Parameter) UnmarshalJSON

func (p *Parameter) UnmarshalJSON(data []byte) error

func (Parameter) WithDesc

func (p Parameter) WithDesc(desc string) *Parameter

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 (i PathItem) MarshalJSON() ([]byte, error)

func (*PathItem) UnmarshalJSON

func (i *PathItem) UnmarshalJSON(data []byte) error

type PathItemObject

type PathItemObject struct {
	Summary     string `json:"summary,omitempty"`
	Description string `json:"description,omitempty"`

	Servers    []*Server    `json:"servers,omitempty"`
	Parameters []*Parameter `json:"parameters,omitempty"`
}

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 (p Paths) MarshalJSON() ([]byte, error)

func (*Paths) UnmarshalJSON

func (p *Paths) UnmarshalJSON(data []byte) error

type Position

type Position string
const (
	PositionQuery  Position = "query"
	PositionPath   Position = "path"
	PositionHeader Position = "header"
	PositionCookie Position = "cookie"
)

type Props

type Props map[string]*Schema

type Refer

type Refer interface {
	RefString() string
}

type Reference

type Reference struct {
	Refer Refer
}

func (Reference) MarshalJSONRefFirst

func (ref Reference) MarshalJSONRefFirst(values ...interface{}) ([]byte, error)

func (*Reference) UnmarshalJSONRefFirst

func (ref *Reference) UnmarshalJSONRefFirst(data []byte, values ...interface{}) error

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 NewResponse(desc string) *Response

func (Response) MarshalJSON

func (r Response) MarshalJSON() ([]byte, error)

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(data []byte) error

type ResponseObject

type ResponseObject struct {
	Description string `json:"description"`
	WithHeaders
	WithContent
	WithLinks
}

type Responses

type Responses struct {
	ResponsesObject
	SpecExtensions
}

func (Responses) MarshalJSON

func (i Responses) MarshalJSON() ([]byte, error)

func (*Responses) UnmarshalJSON

func (i *Responses) UnmarshalJSON(data []byte) error

type ResponsesObject

type ResponsesObject struct {
	Default   *Response
	Responses map[int]*Response
}

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 struct {
	Reference
	SchemaObject
	SpecExtensions
}

func AllOf

func AllOf(schemas ...*Schema) *Schema

func AnyOf

func AnyOf(schemas ...*Schema) *Schema

func Binary

func Binary() *Schema

func Boolean

func Boolean() *Schema

func Byte

func Byte() *Schema

func Date

func Date() *Schema

func DateTime

func DateTime() *Schema

func Double

func Double() *Schema

func Float

func Float() *Schema

func Integer

func Integer() *Schema

func ItemsOf

func ItemsOf(items *Schema) *Schema

func KeyValueOf

func KeyValueOf(k *Schema, s *Schema) *Schema

func Long

func Long() *Schema

func MapOf

func MapOf(s *Schema) *Schema

func NewSchema

func NewSchema(tpe Type, fmt string) *Schema

func Not

func Not(schema *Schema) *Schema

func ObjectOf

func ObjectOf(props Props, required ...string) *Schema

func OneOf

func OneOf(schemas ...*Schema) *Schema

func Password

func Password() *Schema

func RefSchema

func RefSchema(ref string) *Schema

func RefSchemaByRefer

func RefSchemaByRefer(refer Refer) *Schema

func String

func String() *Schema

func (Schema) MarshalJSON

func (s Schema) MarshalJSON() ([]byte, error)

func (*Schema) SetProperty

func (s *Schema) SetProperty(name string, propSchema *Schema, required bool)

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(data []byte) error

func (Schema) WithDesc

func (s Schema) WithDesc(desc string) *Schema

func (Schema) WithDiscriminator

func (s Schema) WithDiscriminator(discriminator *Discriminator) *Schema

func (Schema) WithTitle

func (s Schema) WithTitle(title string) *Schema

func (Schema) WithValidation

func (s Schema) WithValidation(validation *SchemaValidation) *Schema

type SchemaObject

type SchemaObject struct {
	Title string `json:"title,omitempty"`

	Type   Type   `json:"type,omitempty"`
	Format string `json:"format,omitempty"`

	Items                *Schema            `json:"items,omitempty"`
	Properties           map[string]*Schema `json:"properties,omitempty"`
	AdditionalProperties *SchemaOrBool      `json:"additionalProperties,omitempty"`
	PropertyNames        *Schema            `json:"propertyNames,omitempty"`

	SchemaValidation

	AllOf []*Schema `json:"allOf,omitempty"`
	AnyOf []*Schema `json:"anyOf,omitempty"`
	OneOf []*Schema `json:"oneOf,omitempty"`
	Not   *Schema   `json:"not,omitempty"`

	Description string `json:"description,omitempty"`

	Default interface{} `json:"default,omitempty"`

	Nullable      bool           `json:"nullable,omitempty"`
	Discriminator *Discriminator `json:"discriminator,omitempty"`
	ReadOnly      bool           `json:"readOnly,omitempty"`
	WriteOnly     bool           `json:"writeOnly,omitempty"`
	XML           *XML           `json:"xml,omitempty"`
	ExternalDocs  *ExternalDoc   `json:"external_docs,omitempty"`
	Example       interface{}    `json:"example,omitempty"`
	Deprecated    bool           `json:"deprecated,omitempty"`
}

type SchemaOrBool

type SchemaOrBool struct {
	Allows bool
	Schema *Schema
}

func (*SchemaOrBool) MarshalJSON

func (s *SchemaOrBool) MarshalJSON() ([]byte, error)

func (*SchemaOrBool) UnmarshalJSON

func (s *SchemaOrBool) UnmarshalJSON(data []byte) error

type SchemaValidation

type SchemaValidation struct {
	// numbers
	MultipleOf       *float64 `json:"multipleOf,omitempty"`
	Maximum          *float64 `json:"maximum,omitempty"`
	ExclusiveMaximum bool     `json:"exclusiveMaximum,omitempty"`
	Minimum          *float64 `json:"minimum,omitempty"`
	ExclusiveMinimum bool     `json:"exclusiveMinimum,omitempty"`

	// string
	MaxLength *uint64 `json:"maxLength,omitempty"`
	MinLength *uint64 `json:"minLength,omitempty"`
	Pattern   string  `json:"pattern,omitempty"`

	// array
	MaxItems    *uint64 `json:"maxItems,omitempty"`
	MinItems    *uint64 `json:"minItems,omitempty"`
	UniqueItems bool    `json:"uniqueItems,omitempty"`

	// object
	MaxProperties *uint64  `json:"maxProperties,omitempty"`
	MinProperties *uint64  `json:"minProperties,omitempty"`
	Required      []string `json:"required,omitempty"`

	// any
	Enum []interface{} `json:"enum,omitempty"`
}

type SecurityRequirement

type SecurityRequirement map[string][]string

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 NewServer

func NewServer(url string) *Server

func (Server) MarshalJSON

func (i Server) MarshalJSON() ([]byte, error)

func (*Server) UnmarshalJSON

func (i *Server) UnmarshalJSON(data []byte) error

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 ServerVariableObject struct {
	Default     string   `json:"default"`
	Enum        []string `json:"enum,omitempty"`
	Description string   `json:"description,omitempty"`
}

type SpecExtensions

type SpecExtensions struct {
	Extensions map[string]interface{}
}

func (*SpecExtensions) AddExtension

func (v *SpecExtensions) AddExtension(key string, value interface{})

func (SpecExtensions) MarshalJSON

func (v SpecExtensions) MarshalJSON() ([]byte, error)

func (*SpecExtensions) UnmarshalJSON

func (v *SpecExtensions) UnmarshalJSON(data []byte) error

type StringRefer

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

func (StringRefer) RefString

func (ref StringRefer) RefString() string

type Tag

type Tag struct {
	TagObject
	SpecExtensions
}

func NewTag

func NewTag(name string) *Tag

func (Tag) MarshalJSON

func (i Tag) MarshalJSON() ([]byte, error)

func (*Tag) UnmarshalJSON

func (i *Tag) UnmarshalJSON(data []byte) error

type TagObject

type TagObject struct {
	Name         string       `json:"name"`
	Description  string       `json:"description,omitempty"`
	ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"`
}

type Type

type Type string
const (
	TypeInteger Type = "integer"
	TypeNumber  Type = "number"
	TypeString  Type = "string"
	TypeBoolean Type = "boolean"

	TypeArray  Type = "array"
	TypeObject Type = "object"
)

type WithCallbacks

type WithCallbacks struct {
	Callbacks map[string]*Callback `json:"callbacks,omitempty"`
}

func (*WithCallbacks) AddCallback

func (o *WithCallbacks) AddCallback(name string, c *Callback)

type WithContent

type WithContent struct {
	Content map[string]*MediaType `json:"content,omitempty"`
}

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

type WithEncoding struct {
	Encoding map[string]*Encoding `json:"encoding,omitempty"`
}

func (*WithEncoding) AddEncoding

func (o *WithEncoding) AddEncoding(name string, e *Encoding)

type WithExamples

type WithExamples struct {
	Examples map[string]*Example `json:"examples,omitempty"`
}

func (*WithExamples) AddExample

func (o *WithExamples) AddExample(name string, e *Example)

type WithHeaders

type WithHeaders struct {
	Headers map[string]*Header `json:"headers,omitempty"`
}

func (*WithHeaders) AddHeader

func (object *WithHeaders) AddHeader(name string, h *Header)
type WithLinks struct {
	Links map[string]*Link `json:"links,omitempty"`
}
func (object *WithLinks) AddLink(name string, l *Link)

type WithParameters

type WithParameters struct {
	Parameters []*Parameter `json:"parameters,omitempty"`
}

func (*WithParameters) AddParameter

func (object *WithParameters) AddParameter(p *Parameter)

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)

type WithTags

type WithTags struct {
	Tags []*Tag `json:"tags,omitempty"`
}

func (*WithTags) AddTag

func (o *WithTags) AddTag(t *Tag)

type XML

type XML struct {
	Name      string `json:"name,omitempty"`
	Namespace string `json:"namespace,omitempty"`
	Prefix    string `json:"prefix,omitempty"`
	Attribute bool   `json:"attribute,omitempty"`
	Wrapped   bool   `json:"wrapped,omitempty"`
}

Jump to

Keyboard shortcuts

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