openapi

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const OPENAPI_VERSION = "3.0.0"
View Source
const SCHEMA_PATH = "components/schemas"

Default location for schema references without leading or training "/".

Variables

This section is empty.

Functions

This section is empty.

Types

type ContactObject

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

func (*ContactObject) Validate added in v0.0.13

func (c *ContactObject) Validate() error

type ExternalDocumentationObject

type ExternalDocumentationObject struct {
	// REQUIRED. The URL for the target documentation. Value MUST be in the format of a URL.
	URL string `json:"url"`
	//description	string	A short description of the target documentation. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description,omitempty"`
}

func (*ExternalDocumentationObject) Validate added in v0.0.13

func (d *ExternalDocumentationObject) Validate() error

type HeaderObject

type HeaderObject struct {
	//description	string	A brief description of the parameter. This could contain examples of use. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description,omitempty"`
	//required	boolean	Determines whether this parameter is mandatory. If the parameter location is "path", this property is REQUIRED and its value MUST be true. Otherwise, the property MAY be included and its default value is false.
	Required bool `json:"required,omitempty"`
	//deprecated	boolean	Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is false.
	Deprecated bool `json:"deprecated,omitempty"`
	//allowEmptyValue	boolean	Sets the ability to pass empty-valued parameters. This is valid only for query parameters and allows sending a parameter with an empty value. Default value is false. If style is used, and if behavior is n/a (cannot be serialized), the value of allowEmptyValue SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision.}
	AllowEmptyValue bool `json:"allowEmptyValue,omitempty"`
}

type InfoObject

type InfoObject struct {
	// REQUIRED. The title of the API.
	Title string `json:"title" yaml:"title"`
	// REQUIRED. The version of the OpenAPI document (which is distinct from the OpenAPI Specification version or the API implementation version).
	Version string `json:"version"`

	// A short description of the API. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description,omitempty"`
	// A URL to the Terms of Service for the API. MUST be in the format of a URL.
	TermsOfService string `json:"termsOfService,omitempty"`

	// The contact information for the exposed API.
	Contact *ContactObject `json:"contact,omitempty"`

	// The license information for the exposed API.
	License *LicenseObject `json:"license,omitempty"`
}

func (*InfoObject) MarshalYAML added in v0.0.13

func (i *InfoObject) MarshalYAML(prefix string) ([]byte, error)

func (*InfoObject) Validate added in v0.0.13

func (i *InfoObject) Validate() error

type LicenseObject

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

func (*LicenseObject) Validate added in v0.0.13

func (lic *LicenseObject) Validate() error

type MediaTypeObject

type MediaTypeObject struct {
}

type MetaData

type MetaData struct {
	// REQUIRED. This string MUST be the semantic version number of the OpenAPI Specification version that
	// the OpenAPI document uses. The openapi field SHOULD be used by tooling specifications and clients
	// to interpret the OpenAPI document. This is not related to the API info.version string.
	OpenAPI string `json:"openapi"`

	// REQUIRED. Provides metadata about the API. The metadata MAY be used by tooling as required.
	Info *InfoObject `json:"info,omitempty"`

	// An array of Server Objects, which provide connectivity information to a target server. If the servers
	// property is not provided, or is an empty array, the default value would be a Server Object with a url value of /.
	Servers []*ServerObject `json:"servers,omitempty"`

	// Additional external documentation.
	ExternalDocs *ExternalDocumentationObject `json:"externalDocs,omitempty"`
}

func NewMetaData

func NewMetaData(title, version string) *MetaData

NewMetaData returns an empty metadata struct with the default version.

func (*MetaData) MarshalYAML added in v0.0.13

func (m *MetaData) MarshalYAML(prefix string) ([]byte, error)

MarshalYAML builds YAML strings in a specific key order.

func (*MetaData) Validate added in v0.0.9

func (m *MetaData) Validate() error

Validate checks that metadata contains required fields.

type OpenAPIRenderer

type OpenAPIRenderer struct {
	MetaData *MetaData
	Options  *renderer.Options
}

OpenAPIRenderer provides a simple string renderer.

func NewOpenAPIRenderer

func NewOpenAPIRenderer(metadata *MetaData, opt *renderer.Options) *OpenAPIRenderer

func (*OpenAPIRenderer) DeReference

func (r *OpenAPIRenderer) DeReference() bool

func (*OpenAPIRenderer) Indent

func (r *OpenAPIRenderer) Indent() int

func (*OpenAPIRenderer) NativeType added in v0.0.11

func (r *OpenAPIRenderer) NativeType(t *types.TypeNode) *types.NativeType

func (*OpenAPIRenderer) Path

func (r *OpenAPIRenderer) Path(t *types.TypeNode) []string

Path is a function that builds a path string from a TypeNode.

func (*OpenAPIRenderer) Post

func (r *OpenAPIRenderer) Post(t *types.TypeNode) []string

func (*OpenAPIRenderer) Pre

func (r *OpenAPIRenderer) Pre(t *types.TypeNode) []string

func (*OpenAPIRenderer) Prefix

func (r *OpenAPIRenderer) Prefix() string

func (*OpenAPIRenderer) ProcessSchema

func (r *OpenAPIRenderer) ProcessSchema(schema *types.Schema, settings ...string) ([]string, error)

func (*OpenAPIRenderer) SetIndent

func (r *OpenAPIRenderer) SetIndent(value int)

type OperationObject

type OperationObject struct {
	//tags	[string]	A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.
	Tags []string `json:"tags,omitempty"`
	//summary	string	A short summary of what the operation does.
	Summary string `json:"summary,omitempty"`
	//description	string	A verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description,omitempty"`
	//externalDocs	External Documentation Object	Additional external documentation for this operation.
	ExternalDocs *ExternalDocumentationObject `json:"externalDocs,omitempty"`
	//operationId	string	Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.
	OperationId string `json:"operationId,omitempty"`
	//parameters	[Parameter Object | Reference Object]	A list of parameters that are applicable for this operation. If a parameter is already defined at the Path Item, the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location. The list can use the Reference Object to link to parameters that are defined at the OpenAPI Object's components/parameters.
	Parameters []*ParameterObject `json:"parameters,omitempty"`
	//responses	Responses Object	REQUIRED. The list of possible responses as they are returned from executing this operation.
	Responses map[string]*ResponseObject `json:"responses,omitempty"`
	//deprecated	boolean	Declares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is false.
	Deprecated bool `json:"deprecated,omitempty"`
	//servers	[Server Object]	An alternative server array to service this operation. If an alternative server object is specified at the Path Item Object or Root level, it will be overridden by this value.
	Servers []*ServerObject `json:"servers,omitempty"`
}

type ParameterObject

type ParameterObject struct {
	//name	string	REQUIRED. The name of the parameter. Parameter names are case sensitive.
	//If in is "path", the name field MUST correspond to a template expression occurring within the path field in the Paths Object. See Path Templating for further information.
	//If in is "header" and the name field is "Accept", "Content-Type" or "Authorization", the parameter definition SHALL be ignored.
	//For all other cases, the name corresponds to the parameter name used by the in property.
	Name string `json:"name"`
	//in	string	REQUIRED. The location of the parameter. Possible values are "query", "header", "path" or "cookie".
	In string `json:"in"`
	//description	string	A brief description of the parameter. This could contain examples of use. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description,omitempty"`
	//required	boolean	Determines whether this parameter is mandatory. If the parameter location is "path", this property is REQUIRED and its value MUST be true. Otherwise, the property MAY be included and its default value is false.
	Required bool `json:"required,omitempty"`
	//deprecated	boolean	Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is false.
	Deprecated bool `json:"deprecated,omitempty"`
	//allowEmptyValue	boolean	Sets the ability to pass empty-valued parameters. This is valid only for query parameters and allows sending a parameter with an empty value. Default value is false. If style is used, and if behavior is n/a (cannot be serialized), the value of allowEmptyValue SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision.}
	AllowEmptyValue bool `json:"allowEmptyValue,omitempty"`
	//schema Schema Object The schema defining the type used for the parameter.
	//NOTE: This is just a placeholder using a map. Actual SchemaObject is much more complex.
	Schema *SimpleSchemaObject `json:"schema,omitempty"`
}

type PathItemObject

type PathItemObject struct {
	//summary	string	An optional, string summary, intended to apply to all operations in this path.
	Summary string `json:"summary,omitempty"`
	//description	string	An optional, string description, intended to apply to all operations in this path. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description,omitempty"`
	//get	Operation Object	A definition of a GET operation on this path.
	Get *OperationObject `json:"get,omitempty"`
	//put	Operation Object	A definition of a PUT operation on this path.
	Put *OperationObject `json:"put,omitempty"`
	//post	Operation Object	A definition of a POST operation on this path.
	Post *OperationObject `json:"post,omitempty"`
	//delete	Operation Object	A definition of a DELETE operation on this path.
	Delete *OperationObject `json:"delete,omitempty"`
	//options	Operation Object	A definition of a OPTIONS operation on this path.
	Options *OperationObject `json:"options,omitempty"`
	//head	Operation Object	A definition of a HEAD operation on this path.
	Head *OperationObject `json:"head,omitempty"`
	//patch	Operation Object	A definition of a PATCH operation on this path.
	Patch *OperationObject `json:"patch,omitempty"`
	//trace	Operation Object	A definition of a TRACE operation on this path.
	Trace *OperationObject `json:"trace,omitempty"`
	//servers	[Server Object]	An alternative server array to service all operations in this path.
	Servers []*ServerObject `json:"servers,omitempty"`
	//parameters	[Parameter Object | Reference Object]	A list of parameters that are applicable for all the operations described under this path. These parameters can be overridden at the operation level, but cannot be removed there. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location. The list can use the Reference Object to link to parameters that are defined at the OpenAPI Object's components/parameters.
	Parameters []*ParameterObject `json:"parameters,omitempty"`
}

type PathsObject

type PathsObject map[string]*PathItemObject

type ResponseObject

type ResponseObject struct {
	//description	string	REQUIRED. A short description of the response. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description"`
	//headers	Map[string, Header Object | Reference Object]	Maps a header name to its definition. RFC7230 states header names are case insensitive. If a response header is defined with the name "Content-Type", it SHALL be ignored.
	Headers map[string]*HeaderObject `json:"headers,omitempty"`
	//content	Map[string, Media Type Object]	A map containing descriptions of potential response payloads. The key is a media type or media type range and the value describes it. For responses that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*
	Content map[string]*MediaTypeObject `json:"content,omitempty"`
}

type ServerObject

type ServerObject struct {
	// 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}.
	URL string `json:"url"`

	// An optional string describing the host designated by the URL. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description,omitempty"`
}

func (*ServerObject) Validate added in v0.0.13

func (s *ServerObject) Validate() error

type SimpleSchemaObject

type SimpleSchemaObject struct {
	Type      string `json:"type,omitempty"`
	Reference string `json:"$ref,omitempty"`
}

SimpleSchemaObject is a lightweight representation of the SchemaObject.

Jump to

Keyboard shortcuts

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