Help us shape the future of Go! Take the 2026 Go Developer Survey

spec

package
v1.55.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package spec provides OpenAPI specification parsing.

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

This section is empty.

Types

type Components added in v0.2.6

type Components struct {
	Schemas map[string]*Schema `json:"schemas"`
}

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

type ExpansionResources added in v0.2.6

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

ExpansionResources is a struct for possible expansions in a resource.

type Fixtures added in v0.2.6

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 added in v0.2.6

type HTTPVerb string

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

type Info added in v0.2.6

type Info struct {
	// Version is the Stripe API version represented in the specification. It
	// takes a date-based form like `2019-02-19`.
	Version string `json:"version"`
}

Info is the `info` portion of an OpenAPI specification that contains meta information about it.

type MediaType added in v0.2.6

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 added in v0.2.6

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

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

type Parameter added in v0.2.6

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

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

type Path added in v0.2.6

type Path string

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

type RequestBody added in v0.2.6

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 added in v0.2.6

type ResourceID string

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

type Response added in v0.2.6

type Response struct {
	Description string               `json:"description"`
	Content     map[string]MediaType `json:"content"`
}

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

type Schema added in v0.2.6

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

	AnyOf       []*Schema          `json:"anyOf,omitempty"`
	OneOf       []*Schema          `json:"oneOf,omitempty"`
	Description string             `json:"description,omitempty"`
	Enum        []interface{}      `json:"enum,omitempty"`
	Format      string             `json:"format,omitempty"`
	Items       *Schema            `json:"items,omitempty"`
	MaxLength   int                `json:"maxLength,omitempty"`
	Nullable    bool               `json:"nullable,omitempty"`
	Pattern     string             `json:"pattern,omitempty"`
	Properties  map[string]*Schema `json:"properties,omitempty"`
	Required    []string           `json:"required,omitempty"`
	Type        string             `json:"type,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"`
	XStripeOperations   *[]StripeOperation  `json:"x-stripeOperations,omitempty"`
	XStripeMostCommon   []string            `json:"x-stripeMostCommon,omitempty"`
	XStripeEvent        *StripeEvent        `json:"x-stripeEvent,omitempty"`
	XStripeNotPublic    bool                `json:"x-stripeNotPublic,omitempty"`
	XStripeError        *StripeError        `json:"x-stripeError"`
	XStripeEnum         *StripeEnum         `json:"x-stripeEnum,omitempty"`
}

Schema is a struct representing a JSON schema.

func (*Schema) String added in v0.2.6

func (s *Schema) String() string

func (*Schema) UnmarshalJSON added in v0.2.6

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 Server added in v1.37.1

type Server struct {
	URL string `json:"url"`
}

Server is a struct representing server information in an OpenAPI specification.

type Spec added in v0.2.6

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

Spec is a struct representing an OpenAPI specification.

func LoadSpec

func LoadSpec(specPath string) (*Spec, error)

LoadSpec loads and returns the OpenAPI spec.

type StatusCode added in v0.2.6

type StatusCode string

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

type StripeEnum added in v1.45.0

type StripeEnum struct {
	Kind   string            `json:"kind,omitempty"`
	Values []StripeEnumValue `json:"values,omitempty"`
}

StripeEnum represents the x-stripeEnum extension. It handles both the new object format ({kind, values}) and the legacy array format ([{value, ...}]).

func (*StripeEnum) UnmarshalJSON added in v1.45.0

func (e *StripeEnum) UnmarshalJSON(data []byte) error

UnmarshalJSON handles both the new object format and the legacy array format.

type StripeEnumValue added in v1.26.0

type StripeEnumValue struct {
	Description string `json:"description"`
	Value       string `json:"value"`
}

StripeEnumValue represents a single value in a Stripe enum

type StripeError added in v1.25.0

type StripeError struct {
	Code           string `json:"code"`
	HTTPStatusCode int    `json:"httpStatusCode"`
}

type StripeEvent added in v1.24.0

type StripeEvent struct {
	EventType string  `json:"type"`
	EventKind *string `json:"kind,omitempty"`
}

StripeEvent is a struct containing information about a Stripe event.

If EventKind is defined and set to "thin", it indicates a thin event. EventKind is optional.

type StripeOperation added in v0.2.6

type StripeOperation struct {
	MethodName string   `json:"method_name"`
	MethodOn   string   `json:"method_on"`
	MethodType string   `json:"method_type"`
	Operation  HTTPVerb `json:"operation"`
	Path       string   `json:"path"`
}

StripeOperation is a struct for possible operations on a resource.

Jump to

Keyboard shortcuts

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