openapi

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildExampleURL added in v1.1.2

func BuildExampleURL(server, path string, params []Parameter) string

func DiscoverAPIs

func DiscoverAPIs(rootDir string) []string

DiscoverAPIs scans the apis/ directory in rootDir for OpenAPI spec files (.yaml, .yml, .json).

func GenerateExampleObject added in v1.1.2

func GenerateExampleObject(schema *Schema) string

GenerateExampleObject renders a pretty-printed JSON example for a schema.

func GenerateExampleValue added in v1.1.2

func GenerateExampleValue(schema *Schema, name string) interface{}

GenerateExampleValue builds an example value for a schema. An explicit `example` on the schema always wins; otherwise it composes from properties / items / enum, falling back to type-based placeholders.

func GetRequiredHeaders added in v1.1.2

func GetRequiredHeaders(params []Parameter) map[string]string

Types

type APIDoc

type APIDoc struct {
	Slug        string
	Title       string
	Description string
	Version     string
	Servers     []Server
	Tags        []Tag
	Endpoints   []Endpoint
	TagGroups   map[string][]Endpoint
}

func LoadAllSpecs

func LoadAllSpecs(files []string, rootDir string) ([]*APIDoc, error)

func ParseSpec

func ParseSpec(spec *Spec) *APIDoc

type Components

type Components struct {
	Schemas       map[string]*Schema      `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	Parameters    map[string]*Parameter   `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBodies map[string]*RequestBody `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
	Responses     map[string]*Response    `json:"responses,omitempty" yaml:"responses,omitempty"`
}

type Endpoint

type Endpoint struct {
	Method      string
	Path        string
	Summary     string
	Description string
	Tags        []string
	Parameters  []Parameter
	RequestBody *RequestBody
	Responses   map[string]Response
	Deprecated  bool
	Slug        string
}

type ExampleObject added in v1.1.4

type ExampleObject struct {
	Summary     string      `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string      `json:"description,omitempty" yaml:"description,omitempty"`
	Value       interface{} `json:"value,omitempty" yaml:"value,omitempty"`
}

ExampleObject is an OpenAPI Example Object (the `value` is what we render).

type Info

type Info struct {
	Title       string `json:"title" yaml:"title"`
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	Version     string `json:"version" yaml:"version"`
}

type MediaType

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

type Operation

type Operation struct {
	Summary     string              `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string              `json:"description,omitempty" yaml:"description,omitempty"`
	OperationID string              `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Tags        []string            `json:"tags,omitempty" yaml:"tags,omitempty"`
	Parameters  []Parameter         `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBody *RequestBody        `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
	Responses   map[string]Response `json:"responses,omitempty" yaml:"responses,omitempty"`
	Deprecated  bool                `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Security    []SecurityReq       `json:"security,omitempty" yaml:"security,omitempty"`
}

type Parameter

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

type PathItem

type PathItem struct {
	Get     *Operation `json:"get,omitempty" yaml:"get,omitempty"`
	Post    *Operation `json:"post,omitempty" yaml:"post,omitempty"`
	Put     *Operation `json:"put,omitempty" yaml:"put,omitempty"`
	Delete  *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
	Patch   *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
	Options *Operation `json:"options,omitempty" yaml:"options,omitempty"`
	Head    *Operation `json:"head,omitempty" yaml:"head,omitempty"`
}

type RequestBody

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

type Response

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

type Schema

type Schema struct {
	Type        string             `json:"type,omitempty" yaml:"type,omitempty"`
	Format      string             `json:"format,omitempty" yaml:"format,omitempty"`
	Description string             `json:"description,omitempty" yaml:"description,omitempty"`
	Properties  map[string]*Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
	Items       *Schema            `json:"items,omitempty" yaml:"items,omitempty"`
	Ref         string             `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Required    []string           `json:"required,omitempty" yaml:"required,omitempty"`
	Enum        []interface{}      `json:"enum,omitempty" yaml:"enum,omitempty"`
	Example     interface{}        `json:"example,omitempty" yaml:"example,omitempty"`
	AllOf       []*Schema          `json:"allOf,omitempty" yaml:"allOf,omitempty"`
	OneOf       []*Schema          `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
	AnyOf       []*Schema          `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
	RefName     string             `json:"-" yaml:"-"`
}

func (*Schema) TypeString

func (s *Schema) TypeString() string

type SecurityReq

type SecurityReq map[string][]string

type Server

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

type Spec

type Spec struct {
	OpenAPI    string               `json:"openapi" yaml:"openapi"`
	Info       Info                 `json:"info" yaml:"info"`
	Servers    []Server             `json:"servers,omitempty" yaml:"servers,omitempty"`
	Paths      map[string]*PathItem `json:"paths" yaml:"paths"`
	Tags       []Tag                `json:"tags,omitempty" yaml:"tags,omitempty"`
	Components *Components          `json:"components,omitempty" yaml:"components,omitempty"`
}

func LoadSpec

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

type Tag

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

Jump to

Keyboard shortcuts

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