v2

package
v0.16.5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package v2 represents all Swagger / OpenAPI 2 low-level models.

Low-level models are more difficult to navigate than higher-level models, however they are packed with all the raw AST and node data required to perform any kind of analysis on the underlying data.

Every property is wrapped in a NodeReference or a KeyReference or a ValueReference.

IMPORTANT: As a general rule, Swagger / OpenAPI 2 should be avoided for new projects.

Example (CreateLowLevelSwaggerDocument)

How to create a low-level Swagger / OpenAPI 2 Document from a specification

// How to create a low-level OpenAPI 2 Document

// load petstore into bytes
petstoreBytes, _ := os.ReadFile("../../../test_specs/petstorev2.json")

// read in specification
info, _ := datamodel.ExtractSpecInfo(petstoreBytes)

// build low-level document model
document, err := CreateDocumentFromConfig(info, datamodel.NewDocumentConfiguration())

// if something went wrong, a slice of errors is returned
errs := utils.UnwrapErrors(err)
if len(errs) > 0 {
	for i := range errs {
		fmt.Printf("error: %s\n", errs[i].Error())
	}
	panic("cannot build document")
}

// print out email address from the info > contact object.
fmt.Print(document.Info.Value.Contact.Value.Email.Value)
Output:

apiteam@swagger.io

Index

Examples

Constants

View Source
const (
	DefinitionsLabel         = "definitions"
	SecurityDefinitionsLabel = "securityDefinitions"
	ExamplesLabel            = "examples"
	HeadersLabel             = "headers"
	DefaultLabel             = "default"
	ItemsLabel               = "items"
	ParametersLabel          = "parameters"
	PathsLabel               = "paths"
	GetLabel                 = "get"
	PostLabel                = "post"
	PatchLabel               = "patch"
	PutLabel                 = "put"
	DeleteLabel              = "delete"
	OptionsLabel             = "options"
	HeadLabel                = "head"
	SecurityLabel            = "security"
	ScopesLabel              = "scopes"
	ResponsesLabel           = "responses"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Definitions

type Definitions struct {
	Schemas *orderedmap.Map[low.KeyReference[string], low.ValueReference[*base.SchemaProxy]]
}

Definitions is a low-level representation of a Swagger / OpenAPI 2 Definitions object

An object to hold data types that can be consumed and produced by operations. These data types can be primitives, arrays or models.

func (*Definitions) Build

func (d *Definitions) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract all definitions into SchemaProxy instances.

func (*Definitions) FindSchema

func (d *Definitions) FindSchema(schema string) *low.ValueReference[*base.SchemaProxy]

FindSchema will attempt to locate a base.SchemaProxy instance using a name.

func (*Definitions) Hash added in v0.2.0

func (d *Definitions) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the Definitions object

type Examples

type Examples struct {
	Values *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
}

Examples represents a low-level Swagger / OpenAPI 2 Example object. Allows sharing examples for operation responses

func (*Examples) Build

func (e *Examples) Build(_ context.Context, _, root *yaml.Node, _ *index.SpecIndex) error

Build will extract all examples and will attempt to unmarshal content into a map or slice based on type.

func (*Examples) FindExample

func (e *Examples) FindExample(name string) *low.ValueReference[*yaml.Node]

FindExample attempts to locate an example value, using a key label.

func (*Examples) Hash added in v0.2.0

func (e *Examples) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the Examples object

type Header struct {
	Type             low.NodeReference[string]
	Format           low.NodeReference[string]
	Description      low.NodeReference[string]
	Items            low.NodeReference[*Items]
	CollectionFormat low.NodeReference[string]
	Default          low.NodeReference[*yaml.Node]
	Maximum          low.NodeReference[int]
	ExclusiveMaximum low.NodeReference[bool]
	Minimum          low.NodeReference[int]
	ExclusiveMinimum low.NodeReference[bool]
	MaxLength        low.NodeReference[int]
	MinLength        low.NodeReference[int]
	Pattern          low.NodeReference[string]
	MaxItems         low.NodeReference[int]
	MinItems         low.NodeReference[int]
	UniqueItems      low.NodeReference[bool]
	Enum             low.NodeReference[[]low.ValueReference[*yaml.Node]]
	MultipleOf       low.NodeReference[int]
	Extensions       *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
}

Header Represents a low-level Swagger / OpenAPI 2 Header object.

A Header is essentially identical to a Parameter, except it does not contain 'name' or 'in' properties.

func (*Header) Build

func (h *Header) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will build out items, extensions and default value from the supplied node.

func (*Header) FindExtension

func (h *Header) FindExtension(ext string) *low.ValueReference[*yaml.Node]

FindExtension will attempt to locate an extension value using a name lookup.

func (*Header) GetCollectionFormat added in v0.2.0

func (h *Header) GetCollectionFormat() *low.NodeReference[string]

func (*Header) GetDefault added in v0.2.0

func (h *Header) GetDefault() *low.NodeReference[*yaml.Node]

func (*Header) GetDescription added in v0.2.0

func (h *Header) GetDescription() *low.NodeReference[string]

func (*Header) GetEnum added in v0.2.0

func (h *Header) GetEnum() *low.NodeReference[[]low.ValueReference[*yaml.Node]]

func (*Header) GetExclusiveMaximum added in v0.2.0

func (h *Header) GetExclusiveMaximum() *low.NodeReference[bool]

func (*Header) GetExclusiveMinimum added in v0.2.0

func (h *Header) GetExclusiveMinimum() *low.NodeReference[bool]

func (*Header) GetExtensions added in v0.3.2

func (h *Header) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all Header extensions and satisfies the low.HasExtensions interface.

func (*Header) GetFormat added in v0.2.0

func (h *Header) GetFormat() *low.NodeReference[string]

func (*Header) GetItems added in v0.2.0

func (h *Header) GetItems() *low.NodeReference[any]

func (*Header) GetMaxItems added in v0.2.0

func (h *Header) GetMaxItems() *low.NodeReference[int]

func (*Header) GetMaxLength added in v0.2.0

func (h *Header) GetMaxLength() *low.NodeReference[int]

func (*Header) GetMaximum added in v0.2.0

func (h *Header) GetMaximum() *low.NodeReference[int]

func (*Header) GetMinItems added in v0.2.0

func (h *Header) GetMinItems() *low.NodeReference[int]

func (*Header) GetMinLength added in v0.2.0

func (h *Header) GetMinLength() *low.NodeReference[int]

func (*Header) GetMinimum added in v0.2.0

func (h *Header) GetMinimum() *low.NodeReference[int]

func (*Header) GetMultipleOf added in v0.2.0

func (h *Header) GetMultipleOf() *low.NodeReference[int]

func (*Header) GetPattern added in v0.2.0

func (h *Header) GetPattern() *low.NodeReference[string]

func (*Header) GetType added in v0.2.0

func (h *Header) GetType() *low.NodeReference[string]

func (*Header) GetUniqueItems added in v0.2.0

func (h *Header) GetUniqueItems() *low.NodeReference[bool]

func (*Header) Hash added in v0.2.0

func (h *Header) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the Header object

type Items

type Items struct {
	Type             low.NodeReference[string]
	Format           low.NodeReference[string]
	CollectionFormat low.NodeReference[string]
	Items            low.NodeReference[*Items]
	Default          low.NodeReference[*yaml.Node]
	Maximum          low.NodeReference[int]
	ExclusiveMaximum low.NodeReference[bool]
	Minimum          low.NodeReference[int]
	ExclusiveMinimum low.NodeReference[bool]
	MaxLength        low.NodeReference[int]
	MinLength        low.NodeReference[int]
	Pattern          low.NodeReference[string]
	MaxItems         low.NodeReference[int]
	MinItems         low.NodeReference[int]
	UniqueItems      low.NodeReference[bool]
	Enum             low.NodeReference[[]low.ValueReference[*yaml.Node]]
	MultipleOf       low.NodeReference[int]
	Extensions       *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
}

Items is a low-level representation of a Swagger / OpenAPI 2 Items object.

Items is a limited subset of JSON-Schema's items object. It is used by parameter definitions that are not located in "body". Items, is actually identical to a Header, except it does not have description.

func (*Items) Build

func (i *Items) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will build out items and default value.

func (*Items) FindExtension added in v0.2.0

func (i *Items) FindExtension(ext string) *low.ValueReference[*yaml.Node]

FindExtension will attempt to locate an extension value using a name lookup.

func (*Items) GetCollectionFormat added in v0.2.0

func (i *Items) GetCollectionFormat() *low.NodeReference[string]

func (*Items) GetDefault added in v0.2.0

func (i *Items) GetDefault() *low.NodeReference[*yaml.Node]

func (*Items) GetDescription added in v0.2.0

func (i *Items) GetDescription() *low.NodeReference[string]

func (*Items) GetEnum added in v0.2.0

func (i *Items) GetEnum() *low.NodeReference[[]low.ValueReference[*yaml.Node]]

func (*Items) GetExclusiveMaximum added in v0.2.0

func (i *Items) GetExclusiveMaximum() *low.NodeReference[bool]

func (*Items) GetExclusiveMinimum added in v0.2.0

func (i *Items) GetExclusiveMinimum() *low.NodeReference[bool]

func (*Items) GetExtensions added in v0.3.2

func (i *Items) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all Items extensions and satisfies the low.HasExtensions interface.

func (*Items) GetFormat added in v0.2.0

func (i *Items) GetFormat() *low.NodeReference[string]

func (*Items) GetItems added in v0.2.0

func (i *Items) GetItems() *low.NodeReference[any]

func (*Items) GetMaxItems added in v0.2.0

func (i *Items) GetMaxItems() *low.NodeReference[int]

func (*Items) GetMaxLength added in v0.2.0

func (i *Items) GetMaxLength() *low.NodeReference[int]

func (*Items) GetMaximum added in v0.2.0

func (i *Items) GetMaximum() *low.NodeReference[int]

func (*Items) GetMinItems added in v0.2.0

func (i *Items) GetMinItems() *low.NodeReference[int]

func (*Items) GetMinLength added in v0.2.0

func (i *Items) GetMinLength() *low.NodeReference[int]

func (*Items) GetMinimum added in v0.2.0

func (i *Items) GetMinimum() *low.NodeReference[int]

func (*Items) GetMultipleOf added in v0.2.0

func (i *Items) GetMultipleOf() *low.NodeReference[int]

func (*Items) GetPattern added in v0.2.0

func (i *Items) GetPattern() *low.NodeReference[string]

func (*Items) GetType added in v0.2.0

func (i *Items) GetType() *low.NodeReference[string]

func (*Items) GetUniqueItems added in v0.2.0

func (i *Items) GetUniqueItems() *low.NodeReference[bool]

func (*Items) Hash added in v0.2.0

func (i *Items) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the Items object

type Operation

Operation represents a low-level Swagger / OpenAPI 2 Operation object.

It describes a single API operation on a path.

func (*Operation) Build

func (o *Operation) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract external docs, extensions, parameters, responses and security requirements.

func (*Operation) GetConsumes added in v0.2.0

func (o *Operation) GetConsumes() low.NodeReference[[]low.ValueReference[string]]

func (*Operation) GetDeprecated added in v0.2.0

func (o *Operation) GetDeprecated() low.NodeReference[bool]

func (*Operation) GetDescription added in v0.2.0

func (o *Operation) GetDescription() low.NodeReference[string]

func (*Operation) GetExtensions added in v0.2.0

func (o *Operation) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

func (*Operation) GetExternalDocs added in v0.2.0

func (o *Operation) GetExternalDocs() low.NodeReference[any]

func (*Operation) GetOperationId added in v0.2.0

func (o *Operation) GetOperationId() low.NodeReference[string]

func (*Operation) GetParameters added in v0.2.0

func (o *Operation) GetParameters() low.NodeReference[any]

func (*Operation) GetProduces added in v0.2.0

func (o *Operation) GetProduces() low.NodeReference[[]low.ValueReference[string]]

func (*Operation) GetResponses added in v0.2.0

func (o *Operation) GetResponses() low.NodeReference[any]

func (*Operation) GetSchemes added in v0.2.0

func (o *Operation) GetSchemes() low.NodeReference[[]low.ValueReference[string]]

func (*Operation) GetSecurity added in v0.2.0

func (o *Operation) GetSecurity() low.NodeReference[any]

func (*Operation) GetSummary added in v0.2.0

func (o *Operation) GetSummary() low.NodeReference[string]

func (*Operation) GetTags added in v0.2.0

func (*Operation) Hash added in v0.2.0

func (o *Operation) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the Operation object

type Parameter

type Parameter struct {
	Name             low.NodeReference[string]
	In               low.NodeReference[string]
	Type             low.NodeReference[string]
	Format           low.NodeReference[string]
	Description      low.NodeReference[string]
	Required         low.NodeReference[bool]
	AllowEmptyValue  low.NodeReference[bool]
	Schema           low.NodeReference[*base.SchemaProxy]
	Items            low.NodeReference[*Items]
	CollectionFormat low.NodeReference[string]
	Default          low.NodeReference[*yaml.Node]
	Maximum          low.NodeReference[int]
	ExclusiveMaximum low.NodeReference[bool]
	Minimum          low.NodeReference[int]
	ExclusiveMinimum low.NodeReference[bool]
	MaxLength        low.NodeReference[int]
	MinLength        low.NodeReference[int]
	Pattern          low.NodeReference[string]
	MaxItems         low.NodeReference[int]
	MinItems         low.NodeReference[int]
	UniqueItems      low.NodeReference[bool]
	Enum             low.NodeReference[[]low.ValueReference[*yaml.Node]]
	MultipleOf       low.NodeReference[int]
	Extensions       *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
}

Parameter represents a low-level Swagger / OpenAPI 2 Parameter object.

A unique parameter is defined by a combination of a name and location.

There are five possible parameter types.

Path

Used together with Path Templating, where the parameter value is actually part of the operation's URL.
This does not include the host or base path of the API. For example, in /items/{itemId}, the path parameter is itemId.

Query

Parameters that are appended to the URL. For example, in /items?id=###, the query parameter is id.

Header

Custom headers that are expected as part of the request.

Body

The payload that's appended to the HTTP request. Since there can only be one payload, there can only be one body parameter.
The name of the body parameter has no effect on the parameter itself and is used for documentation purposes only.
Since Form parameters are also in the payload, body and form parameters cannot exist together for the same operation.

Form

Used to describe the payload of an HTTP request when either application/x-www-form-urlencoded, multipart/form-data
or both are used as the content type of the request (in Swagger's definition, the consumes property of an operation).
This is the only parameter type that can be used to send files, thus supporting the file type. Since form parameters
are sent in the payload, they cannot be declared together with a body parameter for the same operation. Form
parameters have a different format based on the content-type used (for further details,
consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4):
  application/x-www-form-urlencoded - Similar to the format of Query parameters but as a payload. For example,
  foo=1&bar=swagger - both foo and bar are form parameters. This is normally used for simple parameters that are
                      being transferred.
  multipart/form-data - each parameter takes a section in the payload with an internal header. For example, for
                        the header Content-Disposition: form-data; name="submit-name" the name of the parameter is
                        submit-name. This type of form parameters is more commonly used for file transfers

https://swagger.io/specification/v2/#parameterObject

func (*Parameter) Build

func (p *Parameter) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract out extensions, schema, items and default value

func (*Parameter) FindExtension

func (p *Parameter) FindExtension(ext string) *low.ValueReference[*yaml.Node]

FindExtension attempts to locate a extension value given a name.

func (*Parameter) GetAllowEmptyValue added in v0.2.0

func (p *Parameter) GetAllowEmptyValue() *low.NodeReference[bool]

func (*Parameter) GetCollectionFormat added in v0.2.0

func (p *Parameter) GetCollectionFormat() *low.NodeReference[string]

func (*Parameter) GetDefault added in v0.2.0

func (p *Parameter) GetDefault() *low.NodeReference[*yaml.Node]

func (*Parameter) GetDescription added in v0.2.0

func (p *Parameter) GetDescription() *low.NodeReference[string]

func (*Parameter) GetEnum added in v0.2.0

func (p *Parameter) GetEnum() *low.NodeReference[[]low.ValueReference[*yaml.Node]]

func (*Parameter) GetExclusiveMaximum added in v0.2.0

func (p *Parameter) GetExclusiveMaximum() *low.NodeReference[bool]

func (*Parameter) GetExclusiveMinimum added in v0.2.0

func (p *Parameter) GetExclusiveMinimum() *low.NodeReference[bool]

func (*Parameter) GetExtensions added in v0.3.2

func (p *Parameter) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all Parameter extensions and satisfies the low.HasExtensions interface.

func (*Parameter) GetFormat added in v0.2.0

func (p *Parameter) GetFormat() *low.NodeReference[string]

func (*Parameter) GetIn added in v0.2.0

func (p *Parameter) GetIn() *low.NodeReference[string]

func (*Parameter) GetItems added in v0.2.0

func (p *Parameter) GetItems() *low.NodeReference[any]

func (*Parameter) GetMaxItems added in v0.2.0

func (p *Parameter) GetMaxItems() *low.NodeReference[int]

func (*Parameter) GetMaxLength added in v0.2.0

func (p *Parameter) GetMaxLength() *low.NodeReference[int]

func (*Parameter) GetMaximum added in v0.2.0

func (p *Parameter) GetMaximum() *low.NodeReference[int]

func (*Parameter) GetMinItems added in v0.2.0

func (p *Parameter) GetMinItems() *low.NodeReference[int]

func (*Parameter) GetMinLength added in v0.2.0

func (p *Parameter) GetMinLength() *low.NodeReference[int]

func (*Parameter) GetMinimum added in v0.2.0

func (p *Parameter) GetMinimum() *low.NodeReference[int]

func (*Parameter) GetMultipleOf added in v0.2.0

func (p *Parameter) GetMultipleOf() *low.NodeReference[int]

func (*Parameter) GetName added in v0.2.0

func (p *Parameter) GetName() *low.NodeReference[string]

func (*Parameter) GetPattern added in v0.2.0

func (p *Parameter) GetPattern() *low.NodeReference[string]

func (*Parameter) GetRequired added in v0.2.0

func (p *Parameter) GetRequired() *low.NodeReference[bool]

func (*Parameter) GetSchema added in v0.2.0

func (p *Parameter) GetSchema() *low.NodeReference[any]

func (*Parameter) GetType added in v0.2.0

func (p *Parameter) GetType() *low.NodeReference[string]

func (*Parameter) GetUniqueItems added in v0.2.0

func (p *Parameter) GetUniqueItems() *low.NodeReference[bool]

func (*Parameter) Hash added in v0.2.0

func (p *Parameter) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the Parameter object

type ParameterDefinitions

type ParameterDefinitions struct {
	Definitions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*Parameter]]
}

ParameterDefinitions is a low-level representation of a Swagger / OpenAPI 2 Parameters Definitions object.

ParameterDefinitions holds parameters to be reused across operations. Parameter definitions can be referenced to the ones defined here. It does not define global operation parameters

func (*ParameterDefinitions) Build

func (pd *ParameterDefinitions) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract all ParameterDefinitions into Parameter instances.

func (*ParameterDefinitions) FindParameter

func (pd *ParameterDefinitions) FindParameter(parameter string) *low.ValueReference[*Parameter]

FindParameter will attempt to locate a Parameter instance using a name.

type PathItem

PathItem represents a low-level Swagger / OpenAPI 2 PathItem object.

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 tooling, but will not know which operations and parameters are available.

func (*PathItem) Build

func (p *PathItem) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract extensions, parameters and operations for all methods. Every method is handled asynchronously, in order to keep things moving quickly for complex operations.

func (*PathItem) FindExtension

func (p *PathItem) FindExtension(ext string) *low.ValueReference[*yaml.Node]

FindExtension will attempt to locate an extension given a name.

func (*PathItem) GetExtensions added in v0.3.2

func (p *PathItem) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all PathItem extensions and satisfies the low.HasExtensions interface.

func (*PathItem) Hash added in v0.2.0

func (p *PathItem) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the PathItem object

type Paths

type Paths struct {
	PathItems  *orderedmap.Map[low.KeyReference[string], low.ValueReference[*PathItem]]
	Extensions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
}

Paths represents a low-level Swagger / OpenAPI Paths object.

func (*Paths) Build

func (p *Paths) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract extensions and paths from node.

func (*Paths) FindExtension

func (p *Paths) FindExtension(ext string) *low.ValueReference[*yaml.Node]

FindExtension will attempt to locate an extension value given a name.

func (*Paths) FindPath

func (p *Paths) FindPath(path string) (result *low.ValueReference[*PathItem])

FindPath attempts to locate a PathItem instance, given a path key.

func (*Paths) FindPathAndKey added in v0.2.0

func (p *Paths) FindPathAndKey(path string) (key *low.KeyReference[string], value *low.ValueReference[*PathItem])

FindPathAndKey attempts to locate a PathItem instance, given a path key.

func (*Paths) GetExtensions added in v0.3.2

func (p *Paths) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all Paths extensions and satisfies the low.HasExtensions interface.

func (*Paths) Hash added in v0.2.0

func (p *Paths) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the PathItem object

type Response

Response is a representation of a high-level Swagger / OpenAPI 2 Response object, backed by a low-level one.

Response describes a single response from an API Operation

func (*Response) Build

func (r *Response) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract schema, extensions, examples and headers from node

func (*Response) FindExtension

func (r *Response) FindExtension(ext string) *low.ValueReference[*yaml.Node]

FindExtension will attempt to locate an extension value given a key to lookup.

func (*Response) FindHeader

func (r *Response) FindHeader(hType string) *low.ValueReference[*Header]

FindHeader will attempt to locate a Header value, given a key

func (*Response) GetExtensions added in v0.3.2

func (r *Response) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all Response extensions and satisfies the low.HasExtensions interface.

func (*Response) Hash added in v0.2.0

func (r *Response) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the Response object

type Responses

type Responses struct {
	Codes      *orderedmap.Map[low.KeyReference[string], low.ValueReference[*Response]]
	Default    low.NodeReference[*Response]
	Extensions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
}

Responses is a low-level representation of a Swagger / OpenAPI 2 Responses object.

func (*Responses) Build

func (r *Responses) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract default value and extensions from node.

func (*Responses) FindResponseByCode

func (r *Responses) FindResponseByCode(code string) *low.ValueReference[*Response]

FindResponseByCode will attempt to locate a Response instance using an HTTP response code string.

func (*Responses) GetExtensions added in v0.3.2

func (r *Responses) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all Responses extensions and satisfies the low.HasExtensions interface.

func (*Responses) Hash added in v0.2.0

func (r *Responses) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the Examples object

type ResponsesDefinitions

type ResponsesDefinitions struct {
	Definitions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*Response]]
}

ResponsesDefinitions is a low-level representation of a Swagger / OpenAPI 2 Responses Definitions object.

ResponsesDefinitions is an object to hold responses to be reused across operations. Response definitions can be referenced to the ones defined here. It does not define global operation responses

func (*ResponsesDefinitions) Build

func (r *ResponsesDefinitions) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract all ResponsesDefinitions into Response instances.

func (*ResponsesDefinitions) FindResponse

func (r *ResponsesDefinitions) FindResponse(response string) *low.ValueReference[*Response]

FindResponse will attempt to locate a Response instance using a name.

type Scopes

type Scopes struct {
	Values     *orderedmap.Map[low.KeyReference[string], low.ValueReference[string]]
	Extensions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
}

Scopes is a low-level representation of a Swagger / OpenAPI 2 OAuth2 Scopes object.

Scopes lists the available scopes for an OAuth2 security scheme.

func (*Scopes) Build

func (s *Scopes) Build(_ context.Context, _, root *yaml.Node, _ *index.SpecIndex) error

Build will extract scope values and extensions from node.

func (*Scopes) FindScope

func (s *Scopes) FindScope(scope string) *low.ValueReference[string]

FindScope will attempt to locate a scope string using a key.

func (*Scopes) GetExtensions added in v0.3.2

func (s *Scopes) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all Scopes extensions and satisfies the low.HasExtensions interface.

func (*Scopes) Hash added in v0.2.0

func (s *Scopes) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the Scopes object

type SecurityDefinitions

type SecurityDefinitions struct {
	Definitions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*SecurityScheme]]
}

SecurityDefinitions is a low-level representation of a Swagger / OpenAPI 2 Security Definitions object.

A declaration of the security schemes available to be used in the specification. This does not enforce the security schemes on the operations and only serves to provide the relevant details for each scheme

func (*SecurityDefinitions) Build

func (s *SecurityDefinitions) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract all SecurityDefinitions into SecurityScheme instances.

func (*SecurityDefinitions) FindSecurityDefinition

func (s *SecurityDefinitions) FindSecurityDefinition(securityDef string) *low.ValueReference[*SecurityScheme]

FindSecurityDefinition will attempt to locate a SecurityScheme using a name.

type SecurityScheme

type SecurityScheme struct {
	Type             low.NodeReference[string]
	Description      low.NodeReference[string]
	Name             low.NodeReference[string]
	In               low.NodeReference[string]
	Flow             low.NodeReference[string]
	AuthorizationUrl low.NodeReference[string]
	TokenUrl         low.NodeReference[string]
	Scopes           low.NodeReference[*Scopes]
	Extensions       *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]
}

SecurityScheme is a low-level representation of a Swagger / OpenAPI 2 SecurityScheme object.

SecurityScheme allows the definition of a security scheme that can be used by the operations. Supported schemes are basic authentication, an API key (either as a header or as a query parameter) and OAuth2's common flows (implicit, password, application and access code)

func (*SecurityScheme) Build

func (ss *SecurityScheme) Build(ctx context.Context, _, root *yaml.Node, idx *index.SpecIndex) error

Build will extract extensions and scopes from the node.

func (*SecurityScheme) GetExtensions added in v0.3.2

func (ss *SecurityScheme) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all SecurityScheme extensions and satisfies the low.HasExtensions interface.

func (*SecurityScheme) Hash added in v0.2.0

func (ss *SecurityScheme) Hash() [32]byte

Hash will return a consistent SHA256 Hash of the SecurityScheme object

type Swagger

type Swagger struct {
	// Swagger is the version of Swagger / OpenAPI being used, extracted from the 'swagger: 2.x' definition.
	Swagger low.ValueReference[string]

	// Info represents a specification Info definition.
	// Provides metadata about the API. The metadata can be used by the clients if needed.
	// - https://swagger.io/specification/v2/#infoObject
	Info low.NodeReference[*base.Info]

	// Host is The host (name or ip) serving the API. This MUST be the host only and does not include the scheme nor
	// sub-paths. It MAY include a port. If the host is not included, the host serving the documentation is to be used
	// (including the port). The host does not support path templating.
	Host low.NodeReference[string]

	// BasePath is The base path on which the API is served, which is relative to the host. If it is not included,
	// the API is served directly under the host. The value MUST start with a leading slash (/).
	// The basePath does not support path templating.
	BasePath low.NodeReference[string]

	// Schemes represents the transfer protocol of the API. Requirements MUST be from the list: "http", "https", "ws", "wss".
	// If the schemes is not included, the default scheme to be used is the one used to access
	// the Swagger definition itself.
	Schemes low.NodeReference[[]low.ValueReference[string]]

	// Consumes is a list of MIME types the APIs can consume. This is global to all APIs but can be overridden on
	// specific API calls. Value MUST be as described under Mime Types.
	Consumes low.NodeReference[[]low.ValueReference[string]]

	// Produces is a list of MIME types the APIs can produce. This is global to all APIs but can be overridden on
	// specific API calls. Value MUST be as described under Mime Types.
	Produces low.NodeReference[[]low.ValueReference[string]]

	// Paths are the paths and operations for the API. Perhaps the most important part of the specification.
	//  - https://swagger.io/specification/v2/#pathsObject
	Paths low.NodeReference[*Paths]

	// Definitions is an object to hold data types produced and consumed by operations. It's composed of Schema instances
	//  - https://swagger.io/specification/v2/#definitionsObject
	Definitions low.NodeReference[*Definitions]

	// SecurityDefinitions represents security scheme definitions that can be used across the specification.
	//  - https://swagger.io/specification/v2/#securityDefinitionsObject
	SecurityDefinitions low.NodeReference[*SecurityDefinitions]

	// Parameters is an object to hold parameters that can be used across operations.
	// This property does not define global parameters for all operations.
	//  - https://swagger.io/specification/v2/#parametersDefinitionsObject
	Parameters low.NodeReference[*ParameterDefinitions]

	// Responses is an object to hold responses that can be used across operations.
	// This property does not define global responses for all operations.
	//  - https://swagger.io/specification/v2/#responsesDefinitionsObject
	Responses low.NodeReference[*ResponsesDefinitions]

	// Security is a declaration of which security schemes are applied for the API as a whole. The list of values
	// describes alternative security schemes that can be used (that is, there is a logical OR between the security
	// requirements). Individual operations can override this definition.
	//  - https://swagger.io/specification/v2/#securityRequirementObject
	Security low.NodeReference[[]low.ValueReference[*base.SecurityRequirement]]

	// Tags are 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.
	//  - https://swagger.io/specification/v2/#tagObject
	Tags low.NodeReference[[]low.ValueReference[*base.Tag]]

	// ExternalDocs is an instance of base.ExternalDoc for.. well, obvious really, innit mate?
	ExternalDocs low.NodeReference[*base.ExternalDoc]

	// Extensions contains all custom extensions defined for the top-level document.
	Extensions *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

	// Index is a reference to the index.SpecIndex that was created for the document and used
	// as a guide when building out the Document. Ideal if further processing is required on the model and
	// the original details are required to continue the work.
	//
	// This property is not a part of the OpenAPI schema, this is custom to libopenapi.
	Index *index.SpecIndex

	// SpecInfo is a reference to the datamodel.SpecInfo instance created when the specification was read.
	//
	// This property is not a part of the OpenAPI schema, this is custom to libopenapi.
	SpecInfo *datamodel.SpecInfo

	// Rolodex is a reference to the index.Rolodex instance created when the specification was read.
	// The rolodex is used to look up references from file systems (local or remote)
	Rolodex *index.Rolodex
}

Swagger represents a high-level Swagger / OpenAPI 2 document. An instance of Swagger is the root of the specification.

func CreateDocumentFromConfig added in v0.6.0

func CreateDocumentFromConfig(info *datamodel.SpecInfo,
	configuration *datamodel.DocumentConfiguration) (*Swagger, error)

CreateDocumentFromConfig will create a new Swagger document from the provided SpecInfo and DocumentConfiguration.

func (*Swagger) FindExtension

func (s *Swagger) FindExtension(ext string) *low.ValueReference[*yaml.Node]

FindExtension locates an extension from the root of the Swagger document.

func (*Swagger) GetExtensions added in v0.3.2

func (s *Swagger) GetExtensions() *orderedmap.Map[low.KeyReference[string], low.ValueReference[*yaml.Node]]

GetExtensions returns all Swagger/Top level extensions and satisfies the low.HasExtensions interface.

func (*Swagger) GetExternalDocs added in v0.2.0

func (s *Swagger) GetExternalDocs() *low.NodeReference[any]

Jump to

Keyboard shortcuts

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