ogen

package module
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: Apache-2.0 Imports: 8 Imported by: 40

README

ogen svg logo

ogen Go Reference codecov openapi v3 experimental

Opinionated OpenAPI v3 Code Generator for Go.

Getting started.

Work is still in progress, so currently no backward compatibility is provided. However, we are close to alpha.

Telegram group for development: @ogen_dev

Install

go get -d github.com/ogen-go/ogen

Usage

//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema schema.json --target target/dir -package api --clean

Features

  • No reflection or interface{}
    • The json encoding is code-generated, optimized and uses go-faster/jx for speed and overcoming encoding/json limitations
    • Validation is code-generated according to spec
  • Code-generated static radix router
  • No more boilerplate
    • Structures are generated from OpenAPI v3 specification
    • Arguments, headers, url queries are parsed according to specification into structures
    • String formats like uuid, date, date-time, uri are represented by go types directly
  • Statically typed client and server
  • Convenient support for optional, nullable and optional nullable fields
    • No more pointers
    • Generated Optional[T], Nullable[T] or OptionalNullable[T] wrappers with helpers
    • Special case for array handling with nil semantics relevant to specification
      • When array is optional, nil denotes absence of value
      • When nullable, nil denotes that value is nil
      • When required, nil currently the same as [], but is actually invalid
      • If both nullable and required, wrapper will be generated (TODO)
  • Generated sum types for oneOf
    • Primitive types (string, number) are detected by type
    • Discriminator field is used if defined in schema
    • Type is inferred by unique fields if possible
  • OpenTelemetry tracing and metrics

Example generated structure from schema:

// Pet describes #/components/schemas/Pet.
type Pet struct {
	Birthday     time.Time     `json:"birthday"`
	Friends      []Pet         `json:"friends"`
	ID           int64         `json:"id"`
	IP           net.IP        `json:"ip"`
	IPV4         net.IP        `json:"ip_v4"`
	IPV6         net.IP        `json:"ip_v6"`
	Kind         PetKind       `json:"kind"`
	Name         string        `json:"name"`
	Next         OptData       `json:"next"`
	Nickname     NilString     `json:"nickname"`
	NullStr      OptNilString  `json:"nullStr"`
	Rate         time.Duration `json:"rate"`
	Tag          OptUUID       `json:"tag"`
	TestArray1   [][]string    `json:"testArray1"`
	TestDate     OptTime       `json:"testDate"`
	TestDateTime OptTime       `json:"testDateTime"`
	TestDuration OptDuration   `json:"testDuration"`
	TestFloat1   OptFloat64    `json:"testFloat1"`
	TestInteger1 OptInt        `json:"testInteger1"`
	TestTime     OptTime       `json:"testTime"`
	Type         OptPetType    `json:"type"`
	URI          url.URL       `json:"uri"`
	UniqueID     uuid.UUID     `json:"unique_id"`
}

Example generated server interface:

// Server handles operations described by OpenAPI v3 specification.
type Server interface {
	PetGetByName(ctx context.Context, params PetGetByNameParams) (Pet, error)
	// ...
}

Example generated client method signature:

type PetGetByNameParams struct {
    Name string
}

// GET /pet/{name}
func (c *Client) PetGetByName(ctx context.Context, params PetGetByNameParams) (res Pet, err error)

Generics

Instead of using pointers, ogen generates generic wrappers.

For example, OptNilString is string that is optional (no value) and can be null.

// OptNilString is optional nullable string.
type OptNilString struct {
	Value string
	Set   bool
	Null  bool
}

Multiple convenience helper methods and functions are generated, some of them:

func (OptNilString) Get() (v string, ok bool)
func (OptNilString) IsNull() bool
func (OptNilString) IsSet() bool

func NewOptNilString(v string) OptNilString

Recursive types

If ogen encounters recursive types that can't be expressed in go, pointers are used as fallback.

Sum types

For oneOf sum-types are generated. ID that is one of [string, integer] will be represented like that:

type ID struct {
	Type   IDType
	String string
	Int    int
}

// Also, some helpers:
func NewStringID(v string) ID
func NewIntID(v int) ID

JSON

Code generation provides very efficient and flexible encoding and decoding of json:

// ReadJSON reads Error from json stream.
func (s *Error) ReadJSON(r *json.Reader) error {
	if s == nil {
		return fmt.Errorf(`invalid: unable to decode Error to nil`)
	}
	return r.ObjBytes(func(r *json.Reader, k []byte) error {
		switch string(k) {
		case "code":
			v, err := r.Int64()
			s.Code = int64(v)
			if err != nil {
				return err
			}
		case "message":
			v, err := r.Str()
			s.Message = string(v)
			if err != nil {
				return err
			}
		default:
			return r.Skip()
		}
		return nil
	})
}

Roadmap

  • Security (e.g. Bearer token)
  • Cookie params
  • Default value
  • Tests for ip package
  • Convenient global errors schema (e.g. 500, 404)
    • Add convenience for Error, not only ErrorWithCode
    • Handle case when ref is not used, but responses are equal
  • Webhook support
  • AnyOf
  • Full validation support
  • Client retries
    • Retry strategy (e.g. exponential backoff)
    • Configuring via x-ogen-* annotations
    • Configuring via generation config
  • Separate JSON Schema generator
  • Tool for OAS validation for ogen compatibility
    • Multiple error reporting with references
      • JSON path
      • Line and column (optional)
  • Tool for OAS backward compatibility check
  • DSL-based ent-like code-first approach for writing schemas
  • Reduce generated code via generics
  • Extreme optimizations
    • Code generation for regex
    • Streaming/iterator API support
      • Enable via x-ogen-streaming extension
      • Iteration over array or map elements of object
      • Also can fit njson
    • Advanced Code Generation
      • HTTP
        • URI
        • Header
        • Cookie
      • Templating
      • Encoding/Decoding
        • MessagePack
        • ProtoBuff
    • String interning
  • Websocket support via extension?
  • Async support (Websocket, other protocols)
  • More marshaling protocols support
    • msgpack
    • protobuf
    • ndjson, newline-delimited json
    • text/html
  • Automatic end-to-end tests support via routing header
    • Header selects specific response variant
    • Code-generated tests with full coverage
  • TechEmpower benchmark implementation
  • Integrations

Documentation

Overview

Package ogen implements OpenAPI v3 code generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdditionalProperties added in v0.9.0

type AdditionalProperties struct {
	Bool   *bool
	Schema Schema
}

AdditionalProperties represent JSON Schema additionalProperties validator description.

func (AdditionalProperties) MarshalJSON added in v0.9.0

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

MarshalJSON implements json.Marshaler.

func (*AdditionalProperties) ToJSONSchema added in v0.13.0

ToJSONSchema converts AdditionalProperties to jsonschema.AdditionalProperties.

func (*AdditionalProperties) UnmarshalJSON added in v0.9.0

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

UnmarshalJSON implements json.Unmarshaler.

type Components

type Components struct {
	Schemas         map[string]*Schema         `json:"schemas,omitempty"`
	Responses       map[string]*Response       `json:"responses,omitempty"`
	Parameters      map[string]*Parameter      `json:"parameters,omitempty"`
	Headers         map[string]*Header         `json:"headers,omitempty"`
	Examples        map[string]*Example        `json:"examples,omitempty"`
	RequestBodies   map[string]*RequestBody    `json:"requestBodies,omitempty"`
	SecuritySchemes map[string]*SecuritySchema `json:"securitySchemes,omitempty"`
}

Components hold a set of reusable objects for different aspects of the OAS. All objects defined within the components object will have no effect on the API unless they are explicitly referenced from properties outside the components object.

type Contact

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

Contact information for the exposed API.

func NewContact

func NewContact() *Contact

NewContact returns a new Contact.

func (*Contact) SetEmail

func (c *Contact) SetEmail(e string) *Contact

SetEmail sets the Email of the Contact.

func (*Contact) SetName

func (c *Contact) SetName(n string) *Contact

SetName sets the Name of the Contact.

func (*Contact) SetURL

func (c *Contact) SetURL(url string) *Contact

SetURL sets the URL of the Contact.

type Discriminator

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

Discriminator discriminates types for OneOf, AllOf, AnyOf.

func (*Discriminator) ToJSONSchema added in v0.13.0

func (d *Discriminator) ToJSONSchema() *jsonschema.Discriminator

ToJSONSchema converts Discriminator to jsonschema.Discriminator.

type Encoding added in v0.33.0

type Encoding struct {
	// Describes how the parameter value will be serialized
	// depending on the type of the parameter value.
	Style string `json:"style,omitempty"`

	// When this is true, parameter values of type array or object
	// generate separate parameters for each value of the array
	// or key-value pair of the map.
	// For other types of parameters this property has no effect.
	Explode *bool `json:"explode,omitempty"`

	// Determines whether the parameter value SHOULD allow reserved characters, as defined by
	// RFC3986 :/?#[]@!$&'()*+,;= to be included without percent-encoding.
	// The default value is false. This property SHALL be ignored if the request body media type
	// is not application/x-www-form-urlencoded.
	AllowReserved bool `json:"allowReserved,omitempty"`
}

Encoding describes single encoding definition applied to a single schema property.

type Example

type Example struct {
	Ref           string          `json:"$ref,omitempty"` // ref object
	Summary       string          `json:"summary,omitempty"`
	Description   string          `json:"description,omitempty"`
	Value         json.RawMessage `json:"value,omitempty"`
	ExternalValue string          `json:"externalValue,omitempty"`
}

Example object.

https://swagger.io/specification/#example-object

type Header = Parameter

Header describes header response.

Header Object follows the structure of the Parameter Object with the following changes:

  1. `name` MUST NOT be specified, it is given in the corresponding headers map.
  2. `in` MUST NOT be specified, it is implicitly in header.
  3. All traits that are affected by the location MUST be applicable to a location of header.

type Info

type Info struct {
	// REQUIRED. The title of the API.
	Title string `json:"title"`
	// 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 *Contact `json:"contact,omitempty"`
	// The license information for the exposed API.
	License *License `json:"license,omitempty"`
	// REQUIRED. The version of the OpenAPI document.
	Version string `json:"version"`
}

Info 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.

func NewInfo

func NewInfo() *Info

NewInfo returns a new Info.

func (*Info) SetContact

func (i *Info) SetContact(c *Contact) *Info

SetContact sets the Contact of the Info.

func (*Info) SetDescription

func (i *Info) SetDescription(d string) *Info

SetDescription sets the description of the Info.

func (*Info) SetLicense

func (i *Info) SetLicense(l *License) *Info

SetLicense sets the License of the Info.

func (*Info) SetTermsOfService

func (i *Info) SetTermsOfService(t string) *Info

SetTermsOfService sets the terms of service of the Info.

func (*Info) SetTitle

func (i *Info) SetTitle(t string) *Info

SetTitle sets the title of the Info.

func (*Info) SetVersion

func (i *Info) SetVersion(v string) *Info

SetVersion sets the version of the Info.

type License

type License struct {
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}

License information for the exposed API.

func NewLicense

func NewLicense() *License

NewLicense returns a new License.

func (*License) SetName

func (l *License) SetName(n string) *License

SetName sets the Name of the License.

func (*License) SetURL

func (l *License) SetURL(url string) *License

SetURL sets the URL of the License.

type Media

type Media struct {
	// The schema defining the content of the request, response, or parameter.
	Schema   *Schema             `json:"schema,omitempty"`
	Example  json.RawMessage     `json:"example,omitempty"`
	Examples map[string]*Example `json:"examples,omitempty"`

	// A map between a property name and its encoding information. The key, being the property name, MUST exist in
	// the schema as a property. The encoding object SHALL only apply to requestBody objects when the media
	// type is multipart or application/x-www-form-urlencoded.
	Encoding map[string]Encoding `json:"encoding,omitempty"`
}

Media provides schema and examples for the media type identified by its key.

type NamedParameter

type NamedParameter struct {
	Parameter *Parameter
	Name      string
}

NamedParameter can be used to construct a reference to the wrapped Parameter.

func NewNamedParameter

func NewNamedParameter(n string, p *Parameter) *NamedParameter

NewNamedParameter returns a new NamedParameter.

func (*NamedParameter) AsLocalRef

func (p *NamedParameter) AsLocalRef() *Parameter

AsLocalRef returns a new Parameter referencing the wrapped Parameter in the local document.

type NamedPathItem

type NamedPathItem struct {
	PathItem *PathItem
	Name     string
}

NamedPathItem can be used to construct a reference to the wrapped PathItem.

func NewNamedPathItem

func NewNamedPathItem(n string, p *PathItem) *NamedPathItem

NewNamedPathItem returns a new NamedPathItem.

func (*NamedPathItem) AsLocalRef

func (p *NamedPathItem) AsLocalRef() *PathItem

AsLocalRef returns a new PathItem referencing the wrapped PathItem in the local document.

type NamedRequestBody

type NamedRequestBody struct {
	RequestBody *RequestBody
	Name        string
}

NamedRequestBody can be used to construct a reference to the wrapped RequestBody.

func NewNamedRequestBody

func NewNamedRequestBody(n string, p *RequestBody) *NamedRequestBody

NewNamedRequestBody returns a new NamedRequestBody.

func (*NamedRequestBody) AsLocalRef

func (p *NamedRequestBody) AsLocalRef() *RequestBody

AsLocalRef returns a new RequestBody referencing the wrapped RequestBody in the local document.

type NamedResponse

type NamedResponse struct {
	Response *Response
	Name     string
}

NamedResponse can be used to construct a reference to the wrapped Response.

func NewNamedResponse

func NewNamedResponse(n string, p *Response) *NamedResponse

NewNamedResponse returns a new NamedResponse.

func (*NamedResponse) AsLocalRef

func (p *NamedResponse) AsLocalRef() *Response

AsLocalRef returns a new Response referencing the wrapped Response in the local document.

type NamedSchema

type NamedSchema struct {
	Schema *Schema
	Name   string
}

NamedSchema can be used to construct a reference to the wrapped Schema.

func NewNamedSchema

func NewNamedSchema(n string, p *Schema) *NamedSchema

NewNamedSchema returns a new NamedSchema.

func (*NamedSchema) AsLocalRef

func (p *NamedSchema) AsLocalRef() *Schema

AsLocalRef returns a new Schema referencing the wrapped Schema in the local document.

type Num added in v0.16.0

type Num = jsonschema.Num

Num represents JSON number.

type OAuthFlow added in v0.19.0

type OAuthFlow struct {
	// The authorization URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.
	AuthorizationURL string `json:"authorizationUrl"`
	// The token URL to be used for this flow. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.
	TokenURL string `json:"tokenUrl"`
	// The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL. The OAuth2 standard requires the use of TLS.
	RefreshURL string `json:"refreshUrl,omitempty"`
	// The available scopes for the OAuth2 security scheme. A map between the scope name and a short description for it. The map MAY be empty.
	Scopes map[string]string `json:"scopes"`
}

OAuthFlow is configuration details for a supported OAuth Flow.

type OAuthFlows added in v0.19.0

type OAuthFlows struct {
	// Configuration for the OAuth Implicit flow.
	Implicit *OAuthFlow `json:"implicit"`
	// Configuration for the OAuth Resource Owner Password flow.
	Password *OAuthFlow `json:"password"`
	// Configuration for the OAuth Client Credentials flow. Previously called application in OpenAPI 2.0.
	ClientCredentials *OAuthFlow `json:"clientCredentials"`
	// Configuration for the OAuth Authorization Code flow. Previously called accessCode in OpenAPI 2.0.
	AuthorizationCode *OAuthFlow `json:"authorizationCode"`
}

OAuthFlows allows configuration of the supported OAuth Flows.

type Operation

type Operation struct {
	// 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               `json:"summary,omitempty"`
	Description string               `json:"description,omitempty"`
	OperationID string               `json:"operationId,omitempty"`
	Parameters  []*Parameter         `json:"parameters,omitempty"`
	RequestBody *RequestBody         `json:"requestBody,omitempty"`
	Responses   Responses            `json:"responses,omitempty"`
	Security    SecurityRequirements `json:"security,omitempty"`
	Deprecated  bool                 `json:"deprecated,omitempty"`
}

Operation describes a single API operation on a path.

func NewOperation

func NewOperation() *Operation

NewOperation returns a new Operation.

func (*Operation) AddNamedResponses

func (o *Operation) AddNamedResponses(ps ...*NamedResponse) *Operation

AddNamedResponses adds the given namedResponses to the Responses of the Operation.

func (*Operation) AddParameters

func (o *Operation) AddParameters(ps ...*Parameter) *Operation

AddParameters adds Parameters to the Parameters of the Operation.

func (*Operation) AddResponse

func (o *Operation) AddResponse(n string, p *Response) *Operation

AddResponse adds the given Response under the given Name to the Responses of the Operation.

func (*Operation) AddTags

func (o *Operation) AddTags(ts ...string) *Operation

AddTags adds Tags to the Tags of the Operation.

func (*Operation) SetDescription

func (o *Operation) SetDescription(d string) *Operation

SetDescription sets the Description of the Operation.

func (*Operation) SetOperationID

func (o *Operation) SetOperationID(id string) *Operation

SetOperationID sets the OperationID of the Operation.

func (*Operation) SetParameters

func (o *Operation) SetParameters(ps []*Parameter) *Operation

SetParameters sets the Parameters of the Operation.

func (*Operation) SetRequestBody

func (o *Operation) SetRequestBody(r *RequestBody) *Operation

SetRequestBody sets the RequestBody of the Operation.

func (*Operation) SetResponses

func (o *Operation) SetResponses(r Responses) *Operation

SetResponses sets the Responses of the Operation.

func (*Operation) SetSummary

func (o *Operation) SetSummary(s string) *Operation

SetSummary sets the Summary of the Operation.

func (*Operation) SetTags

func (o *Operation) SetTags(ts []string) *Operation

SetTags sets the Tags of the Operation.

type Parameter

type Parameter struct {
	Ref  string `json:"$ref,omitempty"`
	Name string `json:"name"`

	// The location of the parameter. Possible values are "query", "header", "path" or "cookie".
	In          string  `json:"in"`
	Description string  `json:"description,omitempty"`
	Schema      *Schema `json:"schema,omitempty"`

	// 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"`

	// Specifies that a parameter is deprecated and SHOULD be transitioned out of usage.
	// Default value is false.
	Deprecated bool `json:"deprecated,omitempty"` // TODO: implement

	// For more complex scenarios, the content property can define the media type and schema of the parameter.
	// A parameter MUST contain either a schema property, or a content property, but not both.
	// When example or examples are provided in conjunction with the schema object,
	// the example MUST follow the prescribed serialization strategy for the parameter.
	//
	// A map containing the representations for the parameter.
	// The key is the media type and the value describes it.
	// The map MUST only contain one entry.
	Content map[string]Media `json:"content,omitempty"` // TODO: implement

	// Describes how the parameter value will be serialized
	// depending on the type of the parameter value.
	Style string `json:"style,omitempty"`

	// When this is true, parameter values of type array or object
	// generate separate parameters for each value of the array
	// or key-value pair of the map.
	// For other types of parameters this property has no effect.
	Explode *bool `json:"explode,omitempty"`

	Example  json.RawMessage     `json:"example,omitempty"`
	Examples map[string]*Example `json:"examples,omitempty"`
}

Parameter describes a single operation parameter. A unique parameter is defined by a combination of a name and location.

func NewParameter

func NewParameter() *Parameter

NewParameter returns a new Parameter.

func (*Parameter) InCookie

func (p *Parameter) InCookie() *Parameter

InCookie sets the In of the Parameter to "cookie".

func (*Parameter) InHeader

func (p *Parameter) InHeader() *Parameter

InHeader sets the In of the Parameter to "header".

func (*Parameter) InPath

func (p *Parameter) InPath() *Parameter

InPath sets the In of the Parameter to "PathItem".

func (*Parameter) InQuery

func (p *Parameter) InQuery() *Parameter

InQuery sets the In of the Parameter to "query".

func (*Parameter) SetContent

func (p *Parameter) SetContent(c map[string]Media) *Parameter

SetContent sets the Content of the Parameter.

func (*Parameter) SetDeprecated

func (p *Parameter) SetDeprecated(d bool) *Parameter

SetDeprecated sets the Deprecated of the Parameter.

func (*Parameter) SetDescription

func (p *Parameter) SetDescription(d string) *Parameter

SetDescription sets the Description of the Parameter.

func (*Parameter) SetExplode

func (p *Parameter) SetExplode(e bool) *Parameter

SetExplode sets the Explode of the Parameter.

func (*Parameter) SetIn

func (p *Parameter) SetIn(i string) *Parameter

SetIn sets the In of the Parameter.

func (*Parameter) SetName

func (p *Parameter) SetName(n string) *Parameter

SetName sets the Name of the Parameter.

func (*Parameter) SetRef

func (p *Parameter) SetRef(r string) *Parameter

SetRef sets the Ref of the Parameter.

func (*Parameter) SetRequired

func (p *Parameter) SetRequired(r bool) *Parameter

SetRequired sets the Required of the Parameter.

func (*Parameter) SetSchema

func (p *Parameter) SetSchema(s *Schema) *Parameter

SetSchema sets the Schema of the Parameter.

func (*Parameter) SetStyle

func (p *Parameter) SetStyle(s string) *Parameter

SetStyle sets the Style of the Parameter.

func (*Parameter) ToNamed

func (p *Parameter) ToNamed(n string) *NamedParameter

ToNamed returns a NamedParameter wrapping the receiver.

type PathItem

type PathItem struct {
	// Allows for an external definition of this path item.
	// The referenced structure MUST be in the format of a Path Item Object.
	// In case a Path Item Object field appears both
	// in the defined object and the referenced object, the behavior is undefined.
	Ref         string       `json:"$ref,omitempty"`
	Description string       `json:"description,omitempty"`
	Get         *Operation   `json:"get,omitempty"`
	Put         *Operation   `json:"put,omitempty"`
	Post        *Operation   `json:"post,omitempty"`
	Delete      *Operation   `json:"delete,omitempty"`
	Options     *Operation   `json:"options,omitempty"`
	Head        *Operation   `json:"head,omitempty"`
	Patch       *Operation   `json:"patch,omitempty"`
	Trace       *Operation   `json:"trace,omitempty"`
	Servers     []Server     `json:"servers,omitempty"`
	Parameters  []*Parameter `json:"parameters,omitempty"`
}

PathItem describes the operations available on a single path. A Path Item MAY be empty, due to ACL constraints. The path itself is still exposed to the documentation viewer, but they will not know which operations and parameters are available.

func NewPathItem

func NewPathItem() *PathItem

NewPathItem returns a new PathItem.

func (*PathItem) AddParameters

func (p *PathItem) AddParameters(ps ...*Parameter) *PathItem

AddParameters adds Parameters to the Parameters of the PathItem.

func (*PathItem) AddServers

func (p *PathItem) AddServers(srvs ...*Server) *PathItem

AddServers adds Servers to the Servers of the PathItem.

func (*PathItem) SetDelete

func (p *PathItem) SetDelete(o *Operation) *PathItem

SetDelete sets the Delete of the PathItem.

func (*PathItem) SetDescription

func (p *PathItem) SetDescription(d string) *PathItem

SetDescription sets the Description of the PathItem.

func (*PathItem) SetGet

func (p *PathItem) SetGet(o *Operation) *PathItem

SetGet sets the Get of the PathItem.

func (*PathItem) SetHead

func (p *PathItem) SetHead(o *Operation) *PathItem

SetHead sets the Head of the PathItem.

func (*PathItem) SetOptions

func (p *PathItem) SetOptions(o *Operation) *PathItem

SetOptions sets the Options of the PathItem.

func (*PathItem) SetParameters

func (p *PathItem) SetParameters(ps []*Parameter) *PathItem

SetParameters sets the Parameters of the PathItem.

func (*PathItem) SetPatch

func (p *PathItem) SetPatch(o *Operation) *PathItem

SetPatch sets the Patch of the PathItem.

func (*PathItem) SetPost

func (p *PathItem) SetPost(o *Operation) *PathItem

SetPost sets the Post of the PathItem.

func (*PathItem) SetPut

func (p *PathItem) SetPut(o *Operation) *PathItem

SetPut sets the Put of the PathItem.

func (*PathItem) SetRef

func (p *PathItem) SetRef(r string) *PathItem

SetRef sets the Ref of the PathItem.

func (*PathItem) SetServers

func (p *PathItem) SetServers(srvs []Server) *PathItem

SetServers sets the Servers of the PathItem.

func (*PathItem) SetTrace

func (p *PathItem) SetTrace(o *Operation) *PathItem

SetTrace sets the Trace of the PathItem.

func (*PathItem) ToNamed

func (p *PathItem) ToNamed(n string) *NamedPathItem

ToNamed returns a NamedPathItem wrapping the receiver.

type Paths

type Paths map[string]*PathItem

Paths holds the relative paths to the individual endpoints and their operations. The path is appended to the URL from the Server Object in order to construct the full URL. The Paths MAY be empty, due to ACL constraints.

type PatternProperties added in v0.23.0

type PatternProperties []PatternProperty

PatternProperties represent JSON Schema patternProperties validator description.

func (PatternProperties) MarshalJSON added in v0.23.0

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

MarshalJSON implements json.Marshaler.

func (PatternProperties) ToJSONSchema added in v0.23.0

func (r PatternProperties) ToJSONSchema() (result jsonschema.RawPatternProperties)

ToJSONSchema converts PatternProperties to jsonschema.RawPatternProperties.

func (*PatternProperties) UnmarshalJSON added in v0.23.0

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

UnmarshalJSON implements json.Unmarshaler.

type PatternProperty added in v0.23.0

type PatternProperty struct {
	Pattern string
	Schema  *Schema
}

PatternProperty is item of PatternProperties.

type Properties

type Properties []Property

Properties represent JSON Schema properties validator description.

func (Properties) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Properties) ToJSONSchema added in v0.13.0

func (p Properties) ToJSONSchema() jsonschema.RawProperties

ToJSONSchema converts Properties to jsonschema.RawProperties.

func (*Properties) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

type Property

type Property struct {
	Name   string
	Schema *Schema
}

Property is item of Properties.

func NewProperty

func NewProperty() *Property

NewProperty returns a new Property.

func (*Property) SetName

func (p *Property) SetName(n string) *Property

SetName sets the Name of the Property.

func (*Property) SetSchema

func (p *Property) SetSchema(s *Schema) *Property

SetSchema sets the Schema of the Property.

func (Property) ToJSONSchema added in v0.13.0

func (p Property) ToJSONSchema() jsonschema.RawProperty

ToJSONSchema converts Property to jsonschema.Property.

type RequestBody

type RequestBody struct {
	Ref         string `json:"$ref,omitempty"`
	Description string `json:"description,omitempty"`

	// The content of the request body.
	// The key is a media type or media type range and the value describes it.
	// For requests that match multiple keys, only the most specific key is applicable.
	// e.g. text/plain overrides text/*
	Content map[string]Media `json:"content,omitempty"`

	// Determines if the request body is required in the request. Defaults to false.
	Required bool `json:"required,omitempty"`
}

RequestBody describes a single request body.

func NewRequestBody

func NewRequestBody() *RequestBody

NewRequestBody returns a new RequestBody.

func (*RequestBody) AddContent

func (r *RequestBody) AddContent(mt string, s *Schema) *RequestBody

AddContent adds the given Schema under the MediaType to the Content of the Response.

func (*RequestBody) SetContent

func (r *RequestBody) SetContent(c map[string]Media) *RequestBody

SetContent sets the Content of the RequestBody.

func (*RequestBody) SetDescription

func (r *RequestBody) SetDescription(d string) *RequestBody

SetDescription sets the Description of the RequestBody.

func (*RequestBody) SetJSONContent

func (r *RequestBody) SetJSONContent(s *Schema) *RequestBody

SetJSONContent sets the given Schema under the JSON MediaType to the Content of the Response.

func (*RequestBody) SetRef

func (r *RequestBody) SetRef(ref string) *RequestBody

SetRef sets the Ref of the RequestBody.

func (*RequestBody) SetRequired

func (r *RequestBody) SetRequired(req bool) *RequestBody

SetRequired sets the Required of the RequestBody.

func (*RequestBody) ToNamed

func (r *RequestBody) ToNamed(n string) *NamedRequestBody

ToNamed returns a NamedRequestBody wrapping the receiver.

type Response

type Response struct {
	Ref         string                 `json:"$ref,omitempty"`
	Description string                 `json:"description,omitempty"`
	Headers     map[string]*Header     `json:"headers,omitempty"`
	Content     map[string]Media       `json:"content,omitempty"`
	Links       map[string]interface{} `json:"links,omitempty"` // TODO: implement
}

Response describes a single response from an API Operation, including design-time, static links to operations based on the response.

func NewResponse

func NewResponse() *Response

NewResponse returns a new Response.

func (*Response) AddContent

func (r *Response) AddContent(mt string, s *Schema) *Response

AddContent adds the given Schema under the MediaType to the Content of the Response.

func (*Response) SetContent

func (r *Response) SetContent(c map[string]Media) *Response

SetContent sets the Content of the Response.

func (*Response) SetDescription

func (r *Response) SetDescription(d string) *Response

SetDescription sets the Description of the Response.

func (*Response) SetHeaders added in v0.33.0

func (r *Response) SetHeaders(h map[string]*Header) *Response

SetHeaders sets the Headers of the Response.

func (*Response) SetJSONContent

func (r *Response) SetJSONContent(s *Schema) *Response

SetJSONContent sets the given Schema under the JSON MediaType to the Content of the Response.

func (r *Response) SetLinks(l map[string]interface{}) *Response

SetLinks sets the Links of the Response.

func (*Response) SetRef

func (r *Response) SetRef(ref string) *Response

SetRef sets the Ref of the Response.

func (*Response) ToNamed

func (r *Response) ToNamed(n string) *NamedResponse

ToNamed returns a NamedResponse wrapping the receiver.

type Responses

type Responses map[string]*Response

Responses is a container for the expected responses of an operation. The container maps the HTTP response code to the expected response

type Schema

type Schema struct {
	Ref         string `json:"$ref,omitempty"` // ref object
	Description string `json:"description,omitempty"`

	// Value MUST be a string. Multiple types via an array are not supported.
	Type string `json:"type,omitempty"`

	// See Data Type Formats for further details (https://swagger.io/specification/#data-type-format).
	// While relying on JSON Schema's defined formats,
	// the OAS offers a few additional predefined formats.
	Format string `json:"format,omitempty"`

	// Property definitions MUST be a Schema Object and not a standard JSON Schema
	// (inline or referenced).
	Properties Properties `json:"properties,omitempty"`

	// Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object
	// and not a standard JSON Schema. Consistent with JSON Schema, additionalProperties defaults to true.
	AdditionalProperties *AdditionalProperties `json:"additionalProperties,omitempty"`

	// The value of "patternProperties" MUST be an object. Each property
	// name of this object SHOULD be a valid regular expression, according
	// to the ECMA-262 regular expression dialect. Each property value of
	// this object MUST be a valid JSON Schema.
	PatternProperties PatternProperties `json:"patternProperties,omitempty"`

	// The value of this keyword MUST be an array.
	// This array MUST have at least one element.
	// Elements of this array MUST be strings, and MUST be unique.
	Required []string `json:"required,omitempty"`

	// Value MUST be an object and not an array.
	// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
	// MUST be present if the Type is "array".
	Items *Schema `json:"items,omitempty"`

	// A true value adds "null" to the allowed type specified by the type keyword,
	// only if type is explicitly defined within the same Schema Object.
	// Other Schema Object constraints retain their defined behavior,
	// and therefore may disallow the use of null as a value.
	// A false value leaves the specified or default type unmodified.
	// The default value is false.
	Nullable bool `json:"nullable,omitempty"`

	// AllOf takes an array of object definitions that are used
	// for independent validation but together compose a single object.
	// Still, it does not imply a hierarchy between the models.
	// For that purpose, you should include the discriminator.
	AllOf []*Schema `json:"allOf,omitempty"` // TODO: implement.

	// OneOf validates the value against exactly one of the subschemas
	OneOf []*Schema `json:"oneOf,omitempty"` // TODO: implement.

	// AnyOf validates the value against any (one or more) of the subschemas
	AnyOf []*Schema `json:"anyOf,omitempty"` // TODO: implement.

	// Discriminator for subschemas.
	Discriminator *Discriminator `json:"discriminator,omitempty"`

	// The value of this keyword MUST be an array.
	// This array SHOULD have at least one element.
	// Elements in the array SHOULD be unique.
	Enum []json.RawMessage `json:"enum,omitempty"` // TODO: Nullable.

	// The value of "multipleOf" MUST be a number, strictly greater than 0.
	//
	// A numeric instance is only valid if division by this keyword's value
	// results in an integer.
	MultipleOf Num `json:"multipleOf,omitempty"`

	// The value of "maximum" MUST be a number, representing an upper limit
	// for a numeric instance.
	//
	// If the instance is a number, then this keyword validates if
	// "exclusiveMaximum" is true and instance is less than the provided
	// value, or else if the instance is less than or exactly equal to the
	// provided value.
	Maximum Num `json:"maximum,omitempty"`

	// The value of "exclusiveMaximum" MUST be a boolean, representing
	// whether the limit in "maximum" is exclusive or not.  An undefined
	// value is the same as false.
	//
	// If "exclusiveMaximum" is true, then a numeric instance SHOULD NOT be
	// equal to the value specified in "maximum".  If "exclusiveMaximum" is
	// false (or not specified), then a numeric instance MAY be equal to the
	// value of "maximum".
	ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`

	// The value of "minimum" MUST be a number, representing a lower limit
	// for a numeric instance.
	//
	// If the instance is a number, then this keyword validates if
	// "exclusiveMinimum" is true and instance is greater than the provided
	// value, or else if the instance is greater than or exactly equal to
	// the provided value.
	Minimum Num `json:"minimum,omitempty"`

	// The value of "exclusiveMinimum" MUST be a boolean, representing
	// whether the limit in "minimum" is exclusive or not.  An undefined
	// value is the same as false.
	//
	// If "exclusiveMinimum" is true, then a numeric instance SHOULD NOT be
	// equal to the value specified in "minimum".  If "exclusiveMinimum" is
	// false (or not specified), then a numeric instance MAY be equal to the
	// value of "minimum".
	ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`

	// The value of this keyword MUST be a non-negative integer.
	//
	// The value of this keyword MUST be an integer.  This integer MUST be
	// greater than, or equal to, 0.
	//
	// A string instance is valid against this keyword if its length is less
	// than, or equal to, the value of this keyword.
	//
	// The length of a string instance is defined as the number of its
	// characters as defined by RFC 7159 [RFC7159].
	MaxLength *uint64 `json:"maxLength,omitempty"`

	// A string instance is valid against this keyword if its length is
	// greater than, or equal to, the value of this keyword.
	//
	// The length of a string instance is defined as the number of its
	// characters as defined by RFC 7159 [RFC7159].
	//
	// The value of this keyword MUST be an integer.  This integer MUST be
	// greater than, or equal to, 0.
	//
	// "minLength", if absent, may be considered as being present with
	// integer value 0.
	MinLength *uint64 `json:"minLength,omitempty"`

	// The value of this keyword MUST be a string.  This string SHOULD be a
	// valid regular expression, according to the ECMA 262 regular
	// expression dialect.
	//
	// A string instance is considered valid if the regular expression
	// matches the instance successfully. Recall: regular expressions are
	// not implicitly anchored.
	Pattern string `json:"pattern,omitempty"`

	// The value of this keyword MUST be an integer.  This integer MUST be
	// greater than, or equal to, 0.
	//
	// An array instance is valid against "maxItems" if its size is less
	// than, or equal to, the value of this keyword.
	MaxItems *uint64 `json:"maxItems,omitempty"`

	// The value of this keyword MUST be an integer.  This integer MUST be
	// greater than, or equal to, 0.
	//
	// An array instance is valid against "minItems" if its size is greater
	// than, or equal to, the value of this keyword.
	//
	// If this keyword is not present, it may be considered present with a
	// value of 0.
	MinItems *uint64 `json:"minItems,omitempty"`

	// The value of this keyword MUST be a boolean.
	//
	// If this keyword has boolean value false, the instance validates
	// successfully.  If it has boolean value true, the instance validates
	// successfully if all of its elements are unique.
	//
	// If not present, this keyword may be considered present with boolean
	// value false.
	UniqueItems bool `json:"uniqueItems,omitempty"`

	// The value of this keyword MUST be an integer.  This integer MUST be
	// greater than, or equal to, 0.
	//
	// An object instance is valid against "maxProperties" if its number of
	// properties is less than, or equal to, the value of this keyword.
	MaxProperties *uint64 `json:"maxProperties,omitempty"`

	// The value of this keyword MUST be an integer.  This integer MUST be
	// greater than, or equal to, 0.
	//
	// An object instance is valid against "minProperties" if its number of
	// properties is greater than, or equal to, the value of this keyword.
	//
	// If this keyword is not present, it may be considered present with a
	// value of 0.
	MinProperties *uint64 `json:"minProperties,omitempty"`

	// Default value.
	Default json.RawMessage `json:"default,omitempty"` // TODO: support

	// A free-form property to include an example of an instance for this schema.
	// To represent examples that cannot be naturally represented in JSON or YAML,
	// a string value can be used to contain the example with escaping where necessary.
	Example json.RawMessage `json:"example,omitempty"`

	// Specifies that a schema is deprecated and SHOULD be transitioned out
	// of usage.
	Deprecated bool `json:"deprecated,omitempty"`
}

The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays.

func Binary

func Binary() *Schema

Binary returns a sequence of octets OAS data type (Schema).

func Bool

func Bool() *Schema

Bool returns a boolean OAS data type (Schema).

func Bytes

func Bytes() *Schema

Bytes returns a base64 encoded OAS data type (Schema).

func Date

func Date() *Schema

Date returns a date as defined by full-date - RFC3339 OAS data type (Schema).

func DateTime

func DateTime() *Schema

DateTime returns a date as defined by date-time - RFC3339 OAS data type (Schema).

func Double

func Double() *Schema

Double returns a double OAS data type (Schema).

func Float

func Float() *Schema

Float returns a float OAS data type (Schema).

func Int added in v0.2.0

func Int() *Schema

Int returns an integer OAS data type (Schema).

func Int32

func Int32() *Schema

Int32 returns an 32-bit integer OAS data type (Schema).

func Int64

func Int64() *Schema

Int64 returns an 64-bit integer OAS data type (Schema).

func NewSchema

func NewSchema() *Schema

NewSchema returns a new Schema.

func Password

func Password() *Schema

Password returns an obscured OAS data type (Schema).

func String

func String() *Schema

String returns a string OAS data type (Schema).

func UUID added in v0.2.0

func UUID() *Schema

UUID returns a UUID OAS data type (Schema).

func (*Schema) AddOptionalProperties

func (s *Schema) AddOptionalProperties(ps ...*Property) *Schema

AddOptionalProperties adds the Properties to the Properties of the Schema.

func (*Schema) AddRequiredProperties

func (s *Schema) AddRequiredProperties(ps ...*Property) *Schema

AddRequiredProperties adds the Properties to the Properties of the Schema and marks them as required.

func (*Schema) AsArray

func (s *Schema) AsArray() *Schema

AsArray returns a new "array" Schema wrapping the receiver.

func (*Schema) AsEnum

func (s *Schema) AsEnum(def json.RawMessage, values ...json.RawMessage) *Schema

AsEnum returns a new "enum" Schema wrapping the receiver.

func (*Schema) SetAllOf

func (s *Schema) SetAllOf(a []*Schema) *Schema

SetAllOf sets the AllOf of the Schema.

func (*Schema) SetAnyOf

func (s *Schema) SetAnyOf(a []*Schema) *Schema

SetAnyOf sets the AnyOf of the Schema.

func (*Schema) SetDefault

func (s *Schema) SetDefault(d json.RawMessage) *Schema

SetDefault sets the Default of the Schema.

func (*Schema) SetDescription

func (s *Schema) SetDescription(d string) *Schema

SetDescription sets the Description of the Schema.

func (*Schema) SetDiscriminator

func (s *Schema) SetDiscriminator(d *Discriminator) *Schema

SetDiscriminator sets the Discriminator of the Schema.

func (*Schema) SetEnum

func (s *Schema) SetEnum(e []json.RawMessage) *Schema

SetEnum sets the Enum of the Schema.

func (*Schema) SetExclusiveMaximum

func (s *Schema) SetExclusiveMaximum(e bool) *Schema

SetExclusiveMaximum sets the ExclusiveMaximum of the Schema.

func (*Schema) SetExclusiveMinimum

func (s *Schema) SetExclusiveMinimum(e bool) *Schema

SetExclusiveMinimum sets the ExclusiveMinimum of the Schema.

func (*Schema) SetFormat

func (s *Schema) SetFormat(f string) *Schema

SetFormat sets the Format of the Schema.

func (*Schema) SetItems

func (s *Schema) SetItems(i *Schema) *Schema

SetItems sets the Items of the Schema.

func (*Schema) SetMaxItems

func (s *Schema) SetMaxItems(m *uint64) *Schema

SetMaxItems sets the MaxItems of the Schema.

func (*Schema) SetMaxLength

func (s *Schema) SetMaxLength(m *uint64) *Schema

SetMaxLength sets the MaxLength of the Schema.

func (*Schema) SetMaxProperties

func (s *Schema) SetMaxProperties(m *uint64) *Schema

SetMaxProperties sets the MaxProperties of the Schema.

func (*Schema) SetMaximum

func (s *Schema) SetMaximum(m *int64) *Schema

SetMaximum sets the Maximum of the Schema.

func (*Schema) SetMinItems

func (s *Schema) SetMinItems(m *uint64) *Schema

SetMinItems sets the MinItems of the Schema.

func (*Schema) SetMinLength

func (s *Schema) SetMinLength(m *uint64) *Schema

SetMinLength sets the MinLength of the Schema.

func (*Schema) SetMinProperties

func (s *Schema) SetMinProperties(m *uint64) *Schema

SetMinProperties sets the MinProperties of the Schema.

func (*Schema) SetMinimum

func (s *Schema) SetMinimum(m *int64) *Schema

SetMinimum sets the Minimum of the Schema.

func (*Schema) SetMultipleOf

func (s *Schema) SetMultipleOf(m *uint64) *Schema

SetMultipleOf sets the MultipleOf of the Schema.

func (*Schema) SetNullable

func (s *Schema) SetNullable(n bool) *Schema

SetNullable sets the Nullable of the Schema.

func (*Schema) SetOneOf

func (s *Schema) SetOneOf(o []*Schema) *Schema

SetOneOf sets the OneOf of the Schema.

func (*Schema) SetPattern

func (s *Schema) SetPattern(p string) *Schema

SetPattern sets the Pattern of the Schema.

func (*Schema) SetProperties

func (s *Schema) SetProperties(p *Properties) *Schema

SetProperties sets the Properties of the Schema.

func (*Schema) SetRef

func (s *Schema) SetRef(r string) *Schema

SetRef sets the Ref of the Schema.

func (*Schema) SetRequired

func (s *Schema) SetRequired(r []string) *Schema

SetRequired sets the Required of the Schema.

func (*Schema) SetType

func (s *Schema) SetType(t string) *Schema

SetType sets the Type of the Schema.

func (*Schema) SetUniqueItems

func (s *Schema) SetUniqueItems(u bool) *Schema

SetUniqueItems sets the UniqueItems of the Schema.

func (*Schema) ToJSONSchema added in v0.13.0

func (s *Schema) ToJSONSchema() *jsonschema.RawSchema

ToJSONSchema converts Schema to jsonschema.Schema.

func (*Schema) ToNamed

func (s *Schema) ToNamed(n string) *NamedSchema

ToNamed returns a NamedSchema wrapping the receiver.

func (*Schema) ToProperty

func (s *Schema) ToProperty(n string) *Property

ToProperty returns a Property with the given name and with this Schema.

type SecurityRequirements added in v0.19.0

type SecurityRequirements []map[string][]string

SecurityRequirements lists the required security schemes to execute this operation.

type SecuritySchema added in v0.19.0

type SecuritySchema struct {
	Ref string `json:"ref,omitempty"`
	// The type of the security scheme. Valid values are "apiKey", "http", "mutualTLS", "oauth2", "openIdConnect".
	Type string `json:"type"`
	// A description for security scheme. CommonMark syntax MAY be used for rich text representation.
	Description string `json:"description,omitempty"`
	// The name of the header, query or cookie parameter to be used.
	Name string `json:"name,omitempty"`
	// The location of the API key. Valid values are "query", "header" or "cookie".
	In string `json:"in,omitempty"`
	// The name of the HTTP Authorization scheme to be used in the Authorization header as defined in RFC7235.
	// The values used SHOULD be registered in the IANA Authentication Scheme registry.
	Scheme string `json:"scheme,omitempty"`
	// A hint to the client to identify how the bearer token is formatted. Bearer tokens are usually generated
	// by an authorization server, so this information is primarily for documentation purposes.
	BearerFormat string `json:"bearerFormat,omitempty"`
	// An object containing configuration information for the flow types supported.
	Flows OAuthFlows `json:"flows"`
	// OpenId Connect URL to discover OAuth2 configuration values.
	// This MUST be in the form of a URL. The OpenID Connect standard requires the use of TLS.
	OpenIDConnectURL string `json:"openIdConnectUrl"`
}

SecuritySchema defines a security scheme that can be used by the operations.

type Server

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

Server represents a Server.

func NewServer

func NewServer() *Server

NewServer returns a new Server.

func (*Server) SetDescription

func (s *Server) SetDescription(d string) *Server

SetDescription sets the Description of the Server.

func (*Server) SetURL

func (s *Server) SetURL(url string) *Server

SetURL sets the URL of the Server.

type Spec

type Spec struct {
	// This string MUST be the semantic version number
	// of the OpenAPI Specification version that the OpenAPI document uses.
	OpenAPI    string               `json:"openapi"`
	Info       Info                 `json:"info"`
	Servers    []Server             `json:"servers,omitempty"`
	Paths      Paths                `json:"paths,omitempty"`
	Components *Components          `json:"components,omitempty"`
	Security   SecurityRequirements `json:"security,omitempty"`

	// A list of tags used by the specification with additional metadata.
	// The order of the tags can be used to reflect on their order by the parsing
	// tools. Not all tags that are used by the Operation Object must be declared.
	// The tags that are not declared MAY be organized randomly or based on the tools' logic.
	// Each tag name in the list MUST be unique.
	Tags []Tag `json:"tags,omitempty"`

	// Raw JSON value. Used by JSON Schema resolver.
	Raw []byte `json:"-"`
}

Spec is the root document object of the OpenAPI document.

func NewSpec

func NewSpec() *Spec

NewSpec returns a new Spec.

func Parse

func Parse(data []byte) (*Spec, error)

Parse parses JSON/YAML into OpenAPI Spec.

func (*Spec) AddNamedParameters

func (s *Spec) AddNamedParameters(ps ...*NamedParameter) *Spec

AddNamedParameters adds the given namedParameters to the Components of the Spec.

func (*Spec) AddNamedPathItems

func (s *Spec) AddNamedPathItems(ps ...*NamedPathItem) *Spec

AddNamedPathItems adds the given namedPaths to the Paths of the Spec.

func (*Spec) AddNamedRequestBodies

func (s *Spec) AddNamedRequestBodies(scs ...*NamedRequestBody) *Spec

AddNamedRequestBodies adds the given namedRequestBodies to the Components of the Spec.

func (*Spec) AddNamedResponses

func (s *Spec) AddNamedResponses(scs ...*NamedResponse) *Spec

AddNamedResponses adds the given namedResponses to the Components of the Spec.

func (*Spec) AddNamedSchemas

func (s *Spec) AddNamedSchemas(scs ...*NamedSchema) *Spec

AddNamedSchemas adds the given namedSchemas to the Components of the Spec.

func (*Spec) AddParameter

func (s *Spec) AddParameter(n string, p *Parameter) *Spec

AddParameter adds the given Parameter under the given Name to the Components of the Spec.

func (*Spec) AddPathItem

func (s *Spec) AddPathItem(n string, p *PathItem) *Spec

AddPathItem adds the given PathItem under the given Name to the Paths of the Spec.

func (*Spec) AddRequestBody

func (s *Spec) AddRequestBody(n string, sc *RequestBody) *Spec

AddRequestBody adds the given RequestBody under the given Name to the Components of the Spec.

func (*Spec) AddResponse

func (s *Spec) AddResponse(n string, sc *Response) *Spec

AddResponse adds the given Response under the given Name to the Components of the Spec.

func (*Spec) AddSchema

func (s *Spec) AddSchema(n string, sc *Schema) *Spec

AddSchema adds the given Schema under the given Name to the Components of the Spec.

func (*Spec) AddServers

func (s *Spec) AddServers(srvs ...*Server) *Spec

AddServers adds Servers to the Servers of the Spec.

func (*Spec) Init

func (s *Spec) Init()

Init components of schema.

func (*Spec) RefRequestBody

func (s *Spec) RefRequestBody(n string) *NamedRequestBody

RefRequestBody returns a new RequestBody referencing the given name.

func (*Spec) RefResponse

func (s *Spec) RefResponse(n string) *NamedResponse

RefResponse returns a new Response referencing the given name.

func (*Spec) RefSchema

func (s *Spec) RefSchema(n string) *NamedSchema

RefSchema returns a new Schema referencing the given name.

func (*Spec) SetComponents

func (s *Spec) SetComponents(c *Components) *Spec

SetComponents sets the Components of the Spec.

func (*Spec) SetInfo

func (s *Spec) SetInfo(i *Info) *Spec

SetInfo sets the Info of the Spec.

func (*Spec) SetOpenAPI

func (s *Spec) SetOpenAPI(v string) *Spec

SetOpenAPI sets the OpenAPI Specification version of the document.

func (*Spec) SetPaths

func (s *Spec) SetPaths(p Paths) *Spec

SetPaths sets the Paths of the Spec.

func (*Spec) SetServers

func (s *Spec) SetServers(srvs []Server) *Spec

SetServers sets the Servers of the Spec.

func (*Spec) UnmarshalJSON added in v0.22.0

func (s *Spec) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Tag

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

Tag object.

https://swagger.io/specification/#tag-object

Directories

Path Synopsis
cmd
ogen
Binary ogen generates go source code from OAS.
Binary ogen generates go source code from OAS.
examples module
gen
genfs
Package genfs contains gen.FileSystem implementations.
Package genfs contains gen.FileSystem implementations.
ir
Package http implements crazy ideas for http optimizations that should be mostly std compatible.
Package http implements crazy ideas for http optimizations that should be mostly std compatible.
internal
capitalize
Package capitalize contains capitalize function.
Package capitalize contains capitalize function.
sample_api
Code generated by ogen, DO NOT EDIT.
Code generated by ogen, DO NOT EDIT.
sample_err
Code generated by ogen, DO NOT EDIT.
Code generated by ogen, DO NOT EDIT.
techempower
Code generated by ogen, DO NOT EDIT.
Code generated by ogen, DO NOT EDIT.
test_http_responses
Code generated by ogen, DO NOT EDIT.
Code generated by ogen, DO NOT EDIT.
test_single_endpoint
Code generated by ogen, DO NOT EDIT.
Code generated by ogen, DO NOT EDIT.
Package jsonpointer contains RFC 6901 JSON Pointer implementation.
Package jsonpointer contains RFC 6901 JSON Pointer implementation.
Package ogenerrors contains ogen errors type definitions and helpers.
Package ogenerrors contains ogen errors type definitions and helpers.
Package openapi represents OpenAPI v3 Specification in Go.
Package openapi represents OpenAPI v3 Specification in Go.
Package otelogen provides OpenTelemetry tracing for ogen.
Package otelogen provides OpenTelemetry tracing for ogen.
tools
Package uri implements OpenAPI path/query parameter encoding.
Package uri implements OpenAPI path/query parameter encoding.

Jump to

Keyboard shortcuts

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