openapi

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package openapi builds OpenAPI 3.0.3 documents for gin-kit applications without annotations: every live route is documented from the router table, and operations described by generated code are enriched with typed schemas. Developers never write doc comments — generators emit the Describe calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildOptions

type BuildOptions struct {
	// Info store data used by this type.
	Info Info
	// Servers store data used by this type.
	Servers []string
	// Routes store data used by this type.
	Routes []Route
	// ExcludePaths store data used by this type.
	ExcludePaths []string
	// ExcludePrefixes store data used by this type.
	ExcludePrefixes []string
}

BuildOptions defines an implementation type used by this package.

type Components

type Components struct {
	// Schemas store data used by this type.
	Schemas map[string]*Schema `json:"schemas,omitempty"`
	// SecuritySchemes store data used by this type.
	SecuritySchemes map[string]*SecurityScheme `json:"securitySchemes,omitempty"`
}

Components defines an implementation type used by this package.

type Document

type Document struct {
	// OpenAPI store data used by this type.
	OpenAPI string `json:"openapi"`
	// Info store data used by this type.
	Info Info `json:"info"`
	// Servers store data used by this type.
	Servers []Server `json:"servers,omitempty"`
	// Paths store data used by this type.
	Paths map[string]*PathItem `json:"paths"`
	// Components store data used by this type.
	Components *Components `json:"components,omitempty"`
}

Document defines an implementation type used by this package.

type Info

type Info struct {
	// Title store data used by this type.
	Title string `json:"title"`
	// Version store data used by this type.
	Version string `json:"version"`
	// Description store data used by this type.
	Description string `json:"description,omitempty"`
}

Info defines an implementation type used by this package.

type MediaType

type MediaType struct {
	// Schema store data used by this type.
	Schema *Schema `json:"schema,omitempty"`
}

MediaType defines an implementation type used by this package.

type Operation

type Operation struct {
	// Method store data used by this type.
	Method string
	// Path store data used by this type.
	Path string
	// Summary store data used by this type.
	Summary string
	// Description store data used by this type.
	Description string
	// Tags store data used by this type.
	Tags []string
	// Request is an instance of the JSON body struct; nil means no body.
	Request any
	// Query is a struct whose `form` fields become query parameters.
	Query any
	// Response is an instance of the success data payload, wrapped as
	// {"data": ...}. nil with Status 204 means no content.
	Response any
	// List wraps Response as {"data": [...], "meta": {...}} and implies
	// pagination parameters.
	List bool
	// Status is the success status code; 0 means 200.
	Status int
	// Filters documents filter[name] query parameters.
	Filters []string
	// Sorts documents the sort parameter's allowed fields.
	Sorts []string
	// Paginated documents page and per_page parameters.
	Paginated bool
	// ErrorCodes lists canonical error codes; statuses are derived.
	ErrorCodes []string
	// Security requires the bearer scheme and documents 401 responses.
	Security bool
	// Hidden excludes the matching route from the document entirely.
	Hidden bool
}

Operation describes one HTTP operation. Paths use gin syntax ("/api/v1/tickets/:id").

type OperationObject

type OperationObject struct {
	// Summary store data used by this type.
	Summary string `json:"summary,omitempty"`
	// Description store data used by this type.
	Description string `json:"description,omitempty"`
	// Tags store data used by this type.
	Tags []string `json:"tags,omitempty"`
	// Parameters store data used by this type.
	Parameters []Parameter `json:"parameters,omitempty"`
	// RequestBody store data used by this type.
	RequestBody *RequestBody `json:"requestBody,omitempty"`
	// Responses store data used by this type.
	Responses map[string]*Response `json:"responses"`
	// Security store data used by this type.
	Security []map[string][]string `json:"security,omitempty"`
}

OperationObject defines an implementation type used by this package.

type Parameter

type Parameter struct {
	// Name store data used by this type.
	Name string `json:"name"`
	// In store data used by this type.
	In string `json:"in"`
	// Required store data used by this type.
	Required bool `json:"required,omitempty"`
	// Description store data used by this type.
	Description string `json:"description,omitempty"`
	// Schema store data used by this type.
	Schema *Schema `json:"schema,omitempty"`
}

Parameter defines an implementation type used by this package.

type PathItem

type PathItem struct {
	// Get store data used by this type.
	Get *OperationObject `json:"get,omitempty"`
	// Post store data used by this type.
	Post *OperationObject `json:"post,omitempty"`
	// Put store data used by this type.
	Put *OperationObject `json:"put,omitempty"`
	// Patch store data used by this type.
	Patch *OperationObject `json:"patch,omitempty"`
	// Delete store data used by this type.
	Delete *OperationObject `json:"delete,omitempty"`
}

PathItem defines an implementation type used by this package.

type Registry

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

Registry collects described operations before the document is built.

func NewRegistry

func NewRegistry() *Registry

NewRegistry performs this package operation.

func (*Registry) Build

func (r *Registry) Build(options BuildOptions) *Document

Build merges the live route table with the described operations into a complete document.

func (*Registry) Describe

func (r *Registry) Describe(operations ...Operation)

Describe registers operations; generated code calls this once per handler file.

func (*Registry) SetSecurityScheme

func (r *Registry) SetSecurityScheme(name string, scheme SecurityScheme)

SetSecurityScheme replaces the default bearer scheme, e.g. with an API key scheme.

type RequestBody

type RequestBody struct {
	// Required store data used by this type.
	Required bool `json:"required,omitempty"`
	// Content store data used by this type.
	Content map[string]MediaType `json:"content"`
}

RequestBody defines an implementation type used by this package.

type Response

type Response struct {
	// Description store data used by this type.
	Description string `json:"description"`
	// Content store data used by this type.
	Content map[string]MediaType `json:"content,omitempty"`
}

Response defines an implementation type used by this package.

type Route

type Route struct {
	// Method store data used by this type.
	Method string
	// Path store data used by this type.
	Path string
}

Route is one live router entry.

type Schema

type Schema struct {
	// Ref store data used by this type.
	Ref string `json:"$ref,omitempty"`
	// Type store data used by this type.
	Type string `json:"type,omitempty"`
	// Format store data used by this type.
	Format string `json:"format,omitempty"`
	// Description store data used by this type.
	Description string `json:"description,omitempty"`
	// Nullable store data used by this type.
	Nullable bool `json:"nullable,omitempty"`
	// Items store data used by this type.
	Items *Schema `json:"items,omitempty"`
	// Properties store data used by this type.
	Properties map[string]*Schema `json:"properties,omitempty"`
	// Required store data used by this type.
	Required []string `json:"required,omitempty"`
	// AdditionalProperties store data used by this type.
	AdditionalProperties *Schema `json:"additionalProperties,omitempty"`
	// AllOf store data used by this type.
	AllOf []*Schema `json:"allOf,omitempty"`
	// MinLength store data used by this type.
	MinLength *int `json:"minLength,omitempty"`
	// MaxLength store data used by this type.
	MaxLength *int `json:"maxLength,omitempty"`
	// Enum store data used by this type.
	Enum []string `json:"enum,omitempty"`
}

Schema defines an implementation type used by this package.

type SecurityScheme

type SecurityScheme struct {
	// Type store data used by this type.
	Type string `json:"type"`
	// Scheme store data used by this type.
	Scheme string `json:"scheme,omitempty"`
	// BearerFormat store data used by this type.
	BearerFormat string `json:"bearerFormat,omitempty"`
	// In store data used by this type.
	In string `json:"in,omitempty"`
	// Name store data used by this type.
	Name string `json:"name,omitempty"`
	// Description store data used by this type.
	Description string `json:"description,omitempty"`
}

SecurityScheme defines an implementation type used by this package.

type Server

type Server struct {
	// URL store data used by this type.
	URL string `json:"url"`
}

Server defines an implementation type used by this package.

Jump to

Keyboard shortcuts

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