spec

package
v0.8.17 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParameterPath  = "path"
	ParameterQuery = "query"
)

A set of constants for the different types of possible OpenAPI parameters.

View Source
const (
	TypeArray   = "array"
	TypeBoolean = "boolean"
	TypeInteger = "integer"
	TypeNumber  = "number"
	TypeObject  = "object"
	TypeString  = "string"
)

A set of constant for the named types available in JSON Schema.

Variables

This section is empty.

Functions

func GetValidatorForOpenAPI3Schema

func GetValidatorForOpenAPI3Schema(oaiSchema *Schema, components *ComponentsForValidation) (*jsval.JSVal, error)

GetValidatorForOpenAPI3Schema gets a JSON Schema validator for a given OpenAPI specification and set of JSON Schema components.

Types

type Components

type Components struct {
	Schemas    map[string]*Schema    `json:"schemas"`
	Parameters map[string]*Parameter `json:"parameters"`
	Responses  map[string]*Response  `json:"responses"`
}

Components is a struct for the components section of an OpenAPI specification.

type ComponentsForValidation

type ComponentsForValidation struct {
	// contains filtered or unexported fields
}

ComponentsForValidation is a collection of components for an OpenAPI specification that's been translated into equivalent JSON Schemas.

func GetComponentsForValidation

func GetComponentsForValidation(components *Components) *ComponentsForValidation

GetComponentsForValidation translates a collection of components for an OpenAPI specification into equivalent JSON schemas.

See also the comment on getJSONSchemaForOpenAPI3Schema.

type ExpansionResources

type ExpansionResources struct {
	OneOf []*Schema `json:"oneOf"`
}

ExpansionResources is a struct for possible expansions in a resource.

type Fixtures

type Fixtures struct {
	Resources map[ResourceID]interface{} `json:"resources"`
}

Fixtures is a struct for a set of companion fixtures for an OpenAPI specification.

type HTTPVerb

type HTTPVerb string

HTTPVerb is a type for an HTTP verb like GET, POST, etc.

type MediaType

type MediaType struct {
	Schema *Schema `json:"schema"`
}

MediaType is a struct bucketing a request or response by media type in an OpenAPI specification.

type Operation

type Operation struct {
	Description string                  `json:"description"`
	OperationID string                  `json:"operation_id"`
	Parameters  []*Parameter            `json:"parameters"`
	RequestBody *RequestBody            `json:"requestBody"`
	Responses   map[StatusCode]Response `json:"responses"`
}

Operation is a struct representing a possible HTTP operation in an OpenAPI specification.

type Parameter

type Parameter struct {
	Description string  `json:"description"`
	In          string  `json:"in"`
	Name        string  `json:"name"`
	Required    bool    `json:"required"`
	Schema      *Schema `json:"schema"`
	Ref         string  `json:"$ref,omitempty"`
}

Parameter is a struct representing a request parameter to an HTTP operation in an OpenAPI specification.

type Path

type Path string

Path is a type for an HTTP path in an OpenAPI specification.

type RequestBody

type RequestBody struct {
	Content  map[string]MediaType `json:"content"`
	Required bool                 `json:"required"`
}

RequestBody is a struct representing the body of a request in an OpenAPI specification.

type ResourceID

type ResourceID string

ResourceID is a type for the ID of a response resource in an OpenAPI specification.

type Response

type Response struct {
	Description string               `json:"description"`
	Content     map[string]MediaType `json:"content"`
	// Ref is populated if this JSON Schema is actually a JSON reference, and
	// it defines the location of the actual schema definition.
	Ref string `json:"$ref,omitempty"`
}

Response is a struct representing the response of an HTTP operation in an OpenAPI specification.

func (*Response) ResolveRef added in v0.8.9

func (r *Response) ResolveRef(responses map[string]*Response) (*Response, error)

ResolveRef returns the ultimate *Response.

If Ref is nil, the same *Response is returned that was passed in. Otherwise, the *Response will be resolved from the provided responses map.

type Schema

type Schema struct {
	// AdditionalProperties is either a `false` to indicate that no additional
	// properties in the object are allowed (beyond what's in Properties), or a
	// JSON schema that describes the expected format of any additional properties.
	//
	// We currently just read it as an `interface{}` because we're not using it
	// for anything right now.
	AdditionalProperties interface{} `json:"additionalProperties,omitempty"`

	// Discriminator is used for polymorphic responses, helping the client to
	// detect the object type
	//
	// We currently just read it as an `interface{}` because we're not using it
	Discriminator interface{} `json:"discriminator,omitempty"`

	AllOf      []*Schema          `json:"allOf,omitempty"`
	AnyOf      []*Schema          `json:"anyOf,omitempty"`
	OneOf      []*Schema          `json:"oneOf,omitempty"`
	Enum       []interface{}      `json:"enum,omitempty"`
	Format     string             `json:"format,omitempty"`
	Items      *Schema            `json:"items,omitempty"`
	MaxLength  int                `json:"maxLength,omitempty"`
	MinLength  int                `json:"minLength,omitempty"`
	Minimum    int                `json:"minimum,omitempty"`
	Maximum    int                `json:"maximum,omitempty"`
	Default    json.RawMessage    `json:"default,omitempty"`
	Nullable   bool               `json:"nullable,omitempty"`
	Example    json.RawMessage    `json:"example,omitempty"`
	Pattern    string             `json:"pattern,omitempty"`
	Properties map[string]*Schema `json:"properties,omitempty"`
	Required   []string           `json:"required,omitempty"`
	Type       string             `json:"type,omitempty"`
	WriteOnly  bool               `json:"writeOnly,omitempty"`
	ReadOnly   bool               `json:"readOnly,omitempty"`

	// Ref is populated if this JSON Schema is actually a JSON reference, and
	// it defines the location of the actual schema definition.
	Ref string `json:"$ref,omitempty"`

	XExpandableFields   *[]string           `json:"x-expandableFields,omitempty"`
	XExpansionResources *ExpansionResources `json:"x-expansionResources,omitempty"`
	XResourceID         string              `json:"x-resourceId,omitempty"`
}

Schema is a struct representing a JSON schema.

func BuildQuerySchema

func BuildQuerySchema(operation *Operation, parameters map[string]*Parameter) (*Schema, error)

BuildQuerySchema builds a JSON schema that will be used to validate query parameters on the incoming request. Unlike request bodies, OpenAPI puts query parameters in a different, non-JSON schema part of an operation.

func (*Schema) FlattenAllOf added in v0.8.8

func (s *Schema) FlattenAllOf() *Schema

FlattenAllOf will flatten the AllOf []*Schema slice and return a new single *Schema

func (*Schema) ResolveRef added in v0.8.9

func (s *Schema) ResolveRef(schemas map[string]*Schema) (*Schema, error)

ResolveRef returns the ultimate *Schema.

If Ref is nil, the same *Schema is returned that was passed in. Otherwise, the *Schema will be resolved from the provided schemas map.

func (*Schema) String

func (s *Schema) String() string

func (*Schema) UnmarshalJSON

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

UnmarshalJSON is a custom JSON unmarshaling implementation for Schema that provides better error messages instead of silently ignoring fields.

type Spec

type Spec struct {
	Components Components                       `json:"components"`
	Paths      map[Path]map[HTTPVerb]*Operation `json:"paths"`
}

Spec is a struct representing an OpenAPI specification.

func (*Spec) Flatten added in v0.8.8

func (s *Spec) Flatten()

Flatten will walk the Paths and flatten the RequestBody AllOf slices to a single Schema.

type StatusCode

type StatusCode string

StatusCode is a type for the response status code of an HTTP operation in an OpenAPI specification.

Jump to

Keyboard shortcuts

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