gopenapi

package module
v0.0.0-...-8059b2e Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2020 License: MIT Imports: 10 Imported by: 0

README

gopenapi

Open API 3.0 Parser

usage parser

$ go run cmd/parser/main.go

usage stub server

$ go run cmd/parser/main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalRef

func MarshalRef(value string, otherwise interface{}) ([]byte, error)

////////////////////////////////////////////////////////////////////////////////////////

Types

type CallbackRef

type CallbackRef struct {
	Ref   string
	Value Callback
}

CallbackRef

func (*CallbackRef) MarshalYAML

func (value *CallbackRef) MarshalYAML() ([]byte, error)

func (*CallbackRef) UnMarshalYAML

func (value *CallbackRef) UnMarshalYAML(data []byte) error

type Components

type Components struct {
	Schemas         map[string]*SchemaRef         `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	Parameters      map[string]*ParameterRef      `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Headers         map[string]*HeaderRef         `json:"headers,omitempty" yaml:"headers,omitempty"`
	RequestBodies   map[string]*RequestBodyRef    `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
	Responses       map[string]*ResponseRef       `json:"responses,omitempty" yaml:"responses,omitempty"`
	SecuritySchemes map[string]*SecuritySchemeRef `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
	Examples        map[string]*ExampleRef        `json:"examples,omitempty" yaml:"examples,omitempty"`
	Links           map[string]*LinkRef           `json:"links,omitempty" yaml:"links,omitempty"`
	Callbacks       map[string]*CallbackRef       `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
	ExtensionProps
}

Components : https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#components-object

type Contact

type Contact struct {
	// The identifying name of the contact person/organization.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	// 	The URL pointing to the contact information. MUST be in the format of a URL.
	URL string `json:"url,omitempty" yaml:"url,omitempty" validate:"url"`
	// The email address of the contact person/organization. MUST be in the format of an email address.
	Email string `json:"email,omitempty" yaml:"email,omitempty" validate:"email"`
	// This object MAY be extended with Specification Extensions.
	ExtensionProps
}

Contact information for the exposed API. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#contact-object

type Content

type Content map[string]*MediaType

type Discriminator

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

Discriminator : https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#discriminator-object

type Encoding

type Encoding struct {
	ExtensionProps
	ContentType   string                `json:"contentType,omitempty" yaml:"contentType,omitempty"`
	Headers       map[string]*HeaderRef `json:"headers,omitempty" yaml:"headers,omitempty"`
	Style         string                `json:"style,omitempty" yaml:"style,omitempty"`
	Explode       *bool                 `json:"explode,omitempty" yaml:"explode,omitempty"`
	AllowReserved bool                  `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
}

Encoding : https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#encoding-object

type Example

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

Example : https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#example-object

type ExampleRef

type ExampleRef struct {
	Ref   string
	Value Example
}

ExampleRef

func (*ExampleRef) MarshalYAML

func (value *ExampleRef) MarshalYAML() ([]byte, error)

func (*ExampleRef) UnMarshalYAML

func (value *ExampleRef) UnMarshalYAML(data []byte) error

type ExtensionProps

type ExtensionProps struct {
	Extensions map[string]interface{} `json:"-" yaml:"-"`
}

type ExternalDocs

type ExternalDocs struct {
	ExtensionProps
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	URL         string `json:"url,omitempty" yaml:"url,omitempty"`
}

ExternalDocumentation : https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#external-documentation-object

type Header struct {
	ExtensionProps
	Description string                 `json:"description,omitempty" yaml:"description,omitempty"`
	Deprecated  bool                   `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Required    bool                   `json:"required,omitempty" yaml:"required,omitempty"`
	Schema      *SchemaRef             `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example     interface{}            `json:"example,omitempty" yaml:"example,omitempty"`
	Examples    map[string]*ExampleRef `json:"examples,omitempty" yaml:"examples,omitempty"`
	Content     Content                `json:"content,omitempty" yaml:"content,omitempty"`
}

type HeaderRef

type HeaderRef struct {
	Ref   string
	Value Header
}

HeaderRef

func (*HeaderRef) MarshalYAML

func (value *HeaderRef) MarshalYAML() ([]byte, error)

func (*HeaderRef) UnMarshalYAML

func (value *HeaderRef) UnMarshalYAML(data []byte) error

type Info

type Info struct {
	// REQUIRED. The title of the API.
	Title string `json:"title" yaml:"title"`
	// A short summary of the API.
	Summary string `json:"summary" yaml:"summary"`
	// A short description of the API. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description,omitempty" yaml:"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" yaml:"termsOfService,omitempty" validate:"url"`
	// The contact information for the exposed API.
	Contact *Contact `json:"contact,omitempty" yaml:"contact,omitempty"`
	// The license information for the exposed API.
	License *License `json:"license,omitempty" yaml:"license,omitempty"`
	// REQUIRED. The version of the OpenAPI document (which is distinct from the OpenAPI Specification version or the API implementation version).
	Version string `json:"version" yaml:"version" validate:"required"`
	// This object MAY be extended with Specification Extensions.
	ExtensionProps
}

Info is the object provides metadata about the API. The metadata MAY be used by the clients if needed, and MAY be presented in editing or documentation generation tools for convenience. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#infoObject

type License

type License struct {
	// REQUIRED. The license name used for the API.
	Name string `json:"name" yaml:"name" validate:"required"`
	// An SPDX license expression for the API. The identifier field is mutually exclusive of the url field.
	Identifier string `json:"identifier" yaml:"identifier"`
	// A URL to the license used for the API. MUST be in the format of a URL. The url field is mutually exclusive of the identifier field.
	URL string `json:"url,omitempty" yaml:"url,omitempty" validate:"url"`
	// This object MAY be extended with Specification Extensions.
	ExtensionProps
}

License information for the exposed API. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#license-object

type Link struct {
	ExtensionProps
	OperationID  string                 `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	OperationRef string                 `json:"operationRef,omitempty" yaml:"operationRef,omitempty"`
	Description  string                 `json:"description,omitempty" yaml:"description,omitempty"`
	Parameters   map[string]interface{} `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Server       *Server                `json:"server,omitempty" yaml:"server,omitempty"`
	RequestBody  interface{}            `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
}

Link Object.

type LinkRef

type LinkRef struct {
	Ref   string
	Value Link
}

LinkRef

func (*LinkRef) MarshalYAML

func (value *LinkRef) MarshalYAML() ([]byte, error)

func (*LinkRef) UnMarshalYAML

func (value *LinkRef) UnMarshalYAML(data []byte) error

type MediaType

type MediaType struct {
	ExtensionProps
	Schema   *SchemaRef             `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example  interface{}            `json:"example,omitempty" yaml:"example,omitempty"`
	Examples map[string]*ExampleRef `json:"examples,omitempty" yaml:"examples,omitempty"`
	Encoding map[string]*Encoding   `json:"encoding,omitempty" yaml:"encoding,omitempty"`
}

MediaType Object.

type OAuthFlow

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

OAuthFlow Object.

type OAuthFlows

type OAuthFlows struct {
	ExtensionProps
	Implicit          *OAuthFlow `json:"implicit,omitempty" yaml:"implicit,omitempty"`
	Password          *OAuthFlow `json:"password,omitempty" yaml:"password,omitempty"`
	ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty" yaml:"clientCredentials,omitempty"`
	AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty" yaml:"authorizationCode,omitempty"`
}

OAuthFlows Object

type OpenAPI

type OpenAPI struct {
	// REQUIRED. This string MUST be the version number of the OpenAPI Specification that the OpenAPI document uses. The openapi field SHOULD be used by tooling to interpret the OpenAPI document. This is not related to the API info.version string.
	OpenAPI string `json:"openapi" yaml:"openapi" validate:"required"`
	// REQUIRED. Provides metadata about the API. The metadata MAY be used by tooling as required.
	Info *Info `json:"info" yaml:"info" validate:"required"`
	// 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 Servers `json:"servers,omitempty" yaml:"servers,omitempty"`
	// The available paths and operations for the API.
	Paths Paths `json:"paths" yaml:"paths"`
	// webhooks
	//
	Security     SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"`
	Tags         Tags                 `json:"tags,omitempty" yaml:"tags,omitempty"`
	Components   Components           `json:"components,omitempty" yaml:"components,omitempty"`
	ExternalDocs *ExternalDocs        `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
	ExtensionProps
}

OpenAPI is the root object of the OpenAPI document. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#openapi-object

func LoadWithValidation

func LoadWithValidation(filePath string) (*OpenAPI, error)

func (*OpenAPI) Validate

func (doc *OpenAPI) Validate(c context.Context) error

type Operation

type Operation struct {
	ExtensionProps
	Tags         []string                `json:"tags,omitempty" yaml:"tags,omitempty"`
	Summary      string                  `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description  string                  `json:"description,omitempty" yaml:"description,omitempty"`
	OperationID  string                  `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Parameters   Parameters              `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBody  *RequestBodyRef         `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
	Responses    Responses               `json:"responses" yaml:"responses"` // Required
	Callbacks    map[string]*CallbackRef `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
	Deprecated   bool                    `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Security     *SecurityRequirements   `json:"security,omitempty" yaml:"security,omitempty"`
	Servers      *Servers                `json:"servers,omitempty" yaml:"servers,omitempty"`
	ExternalDocs *ExternalDocs           `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
}

Operation Object.

type Parameter

type Parameter struct {
	ExtensionProps
	Name            string                 `json:"name,omitempty" yaml:"name,omitempty"`
	In              string                 `json:"in,omitempty" yaml:"in,omitempty"`
	Description     string                 `json:"description,omitempty" yaml:"description,omitempty"`
	Style           string                 `json:"style,omitempty" yaml:"style,omitempty"`
	Explode         *bool                  `json:"explode,omitempty" yaml:"explode,omitempty"`
	AllowEmptyValue bool                   `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"`
	AllowReserved   bool                   `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
	Deprecated      bool                   `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Required        bool                   `json:"required,omitempty" yaml:"required,omitempty"`
	Schema          *SchemaRef             `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example         interface{}            `json:"example,omitempty" yaml:"example,omitempty"`
	Examples        map[string]*ExampleRef `json:"examples,omitempty" yaml:"examples,omitempty"`
	Content         Content                `json:"content,omitempty" yaml:"content,omitempty"`
}

Parameter Object.

type ParameterRef

type ParameterRef struct {
	Ref   string
	Value Parameter
}

ParameterRef

func (*ParameterRef) MarshalYAML

func (value *ParameterRef) MarshalYAML() ([]byte, error)

func (*ParameterRef) UnMarshalYAML

func (value *ParameterRef) UnMarshalYAML(data []byte) error

type Parameters

type Parameters []*ParameterRef

type PathItem

type PathItem struct {
	ExtensionProps
	Ref         string     `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Summary     string     `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string     `json:"description,omitempty" yaml:"description,omitempty"`
	Connect     *Operation `json:"connect,omitempty" yaml:"connect,omitempty"`
	Delete      *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
	Get         *Operation `json:"get,omitempty" yaml:"get,omitempty"`
	Head        *Operation `json:"head,omitempty" yaml:"head,omitempty"`
	Options     *Operation `json:"options,omitempty" yaml:"options,omitempty"`
	Patch       *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
	Post        *Operation `json:"post,omitempty" yaml:"post,omitempty"`
	Put         *Operation `json:"put,omitempty" yaml:"put,omitempty"`
	Trace       *Operation `json:"trace,omitempty" yaml:"trace,omitempty"`
	Servers     Servers    `json:"servers,omitempty" yaml:"servers,omitempty"`
	Parameters  Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}

PathItem Object.

type Paths

type Paths map[string]*PathItem

Paths Object.

type RequestBody

type RequestBody struct {
	ExtensionProps
	Description string  `json:"description,omitempty" yaml:"description,omitempty"`
	Required    bool    `json:"required,omitempty" yaml:"required,omitempty"`
	Content     Content `json:"content,omitempty" yaml:"content,omitempty"`
}

RequestBody Object.

type RequestBodyRef

type RequestBodyRef struct {
	Ref   string
	Value RequestBody
}

RequestBodyRef

func (*RequestBodyRef) MarshalYAML

func (value *RequestBodyRef) MarshalYAML() ([]byte, error)

func (*RequestBodyRef) UnMarshalYAML

func (value *RequestBodyRef) UnMarshalYAML(data []byte) error

type Response

type Response struct {
	ExtensionProps
	Description *string               `json:"description,omitempty" yaml:"description,omitempty"`
	Headers     map[string]*HeaderRef `json:"headers,omitempty" yaml:"headers,omitempty"`
	Content     Content               `json:"content,omitempty" yaml:"content,omitempty"`
	Links       map[string]*LinkRef   `json:"links,omitempty" yaml:"links,omitempty"`
}

Response Object.

type ResponseRef

type ResponseRef struct {
	Ref   string
	Value Response
}

ResponseRef

func (*ResponseRef) MarshalYAML

func (value *ResponseRef) MarshalYAML() ([]byte, error)

func (*ResponseRef) UnmarshalYAML

func (value *ResponseRef) UnmarshalYAML(data []byte) error

type Responses

type Responses map[string]*ResponseRef

type Schema

type Schema struct {
	ExtensionProps

	OneOf        []*SchemaRef  `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
	AnyOf        []*SchemaRef  `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
	AllOf        []*SchemaRef  `json:"allOf,omitempty" yaml:"allOf,omitempty"`
	Not          *SchemaRef    `json:"not,omitempty" yaml:"not,omitempty"`
	Type         string        `json:"type,omitempty" yaml:"type,omitempty"`
	Title        string        `json:"title,omitempty" yaml:"title,omitempty"`
	Format       string        `json:"format,omitempty" yaml:"format,omitempty"`
	Description  string        `json:"description,omitempty" yaml:"description,omitempty"`
	Enum         []interface{} `json:"enum,omitempty" yaml:"enum,omitempty"`
	Default      interface{}   `json:"default,omitempty" yaml:"default,omitempty"`
	Example      interface{}   `json:"example,omitempty" yaml:"example,omitempty"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`

	// Object-related, here for struct compactness
	AdditionalPropertiesAllowed *bool `json:"-" multijson:"additionalProperties,omitempty" yaml:"-"`
	// Array-related, here for struct compactness
	UniqueItems bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"`
	// Number-related, here for struct compactness
	ExclusiveMin bool `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
	ExclusiveMax bool `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
	// Properties
	Nullable        bool `json:"nullable,omitempty" yaml:"nullable,omitempty"`
	ReadOnly        bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
	WriteOnly       bool `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
	AllowEmptyValue bool `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"`
	XML             *XML `json:"xml,omitempty" yaml:"xml,omitempty"`
	Deprecated      bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`

	// Number
	Min        *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	Max        *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	MultipleOf *float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`

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

	// Array
	MinItems uint64     `json:"minItems,omitempty" yaml:"minItems,omitempty"`
	MaxItems *uint64    `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
	Items    *SchemaRef `json:"items,omitempty" yaml:"items,omitempty"`

	// Object
	Required             []string              `json:"required,omitempty" yaml:"required,omitempty"`
	Properties           map[string]*SchemaRef `json:"properties,omitempty" yaml:"properties,omitempty"`
	MinProps             uint64                `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
	MaxProps             *uint64               `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty"`
	AdditionalProperties *SchemaRef            `json:"-" multijson:"additionalProperties,omitempty" yaml:"-"`
	Discriminator        *Discriminator        `json:"discriminator,omitempty" yaml:"discriminator,omitempty"`
	// contains filtered or unexported fields
}

type SchemaRef

type SchemaRef struct {
	Ref   string
	Value Schema
}

SchemaRef

func (*SchemaRef) MarshalYAML

func (value *SchemaRef) MarshalYAML() ([]byte, error)

func (*SchemaRef) UnmarshalYAML

func (value *SchemaRef) UnmarshalYAML(data []byte) error

type SecurityRequirement

type SecurityRequirement map[string][]string

type SecurityRequirements

type SecurityRequirements []SecurityRequirement

type SecurityScheme

type SecurityScheme struct {
	ExtensionProps
	Type             string      `json:"type,omitempty" yaml:"type,omitempty"`
	Description      string      `json:"description,omitempty" yaml:"description,omitempty"`
	Name             string      `json:"name,omitempty" yaml:"name,omitempty"`
	In               string      `json:"in,omitempty" yaml:"in,omitempty"`
	Scheme           string      `json:"scheme,omitempty" yaml:"scheme,omitempty"`
	BearerFormat     string      `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
	Flows            *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
	OpenIDConnectURL string      `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"`
}

SecurityScheme Object

type SecuritySchemeRef

type SecuritySchemeRef struct {
	Ref   string
	Value SecurityScheme
}

SecuritySchemeRef

func (*SecuritySchemeRef) MarshalYAML

func (value *SecuritySchemeRef) MarshalYAML() ([]byte, error)

func (*SecuritySchemeRef) UnMarshalYAML

func (value *SecuritySchemeRef) UnMarshalYAML(data []byte) error

type Server

type Server struct {
	URL         string                     `json:"url,omitempty"`
	Description string                     `json:"description,omitempty"`
	Variables   map[string]*ServerVariable `json:"variables,omitempty"`
}

Server : https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#fixed-fields-4

type ServerVariable

type ServerVariable struct {
	Enum        []interface{} `json:"enum,omitempty" yaml:"enum,omitempty"`
	Default     interface{}   `json:"default,omitempty" yaml:"default,omitempty"`
	Description string        `json:"description,omitempty" yaml:"description,omitempty"`
}

ServerVariable Object.

type Servers

type Servers []*Server

Servers

type Tag

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

Tag Object.

type Tags

type Tags []*Tag

type XML

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

XML Object.

Directories

Path Synopsis
cmd
gen-stub-server command
jsref command
parser command