Documentation
¶
Overview ¶
Package openapi provides types and helpers for building OpenAPI 3.0.3 specification documents that fleet services expose at /openapi.json.
Typical usage:
spec := openapi.New(cfg.AppName, cfg.Version)
// optionally enrich with handler annotations:
openapi.ScanDir(".", spec)
srv := server.New(cfg, server.WithOpenAPI(spec))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScanDir ¶
ScanDir walks dir for *.go files and adds any @openapi-annotated handler comments to spec. Returns the number of routes added.
Comment annotation format (all lines must be consecutive, directly above the func declaration or anywhere in the file; mixed-in blank comment lines are tolerated):
// @openapi GET /example
// @summary Returns an example response
// @tag example
// @param query url string true URL to scan
// @param query target string false Alias for url
// @response 200 {"message":"string"}
func handleExample(w http.ResponseWriter, r *http.Request) { … }
@param format: @param <in> <name> <type> <required> <description...>
in: query | path | header | cookie type: string | integer | boolean | number required: true | false description: remainder of the line (spaces allowed, no quoting needed)
Only @openapi, @summary, @tag, @param, and @response are consumed. Unknown @-prefixed lines are silently ignored so the format can be extended forwards-compatibly.
Types ¶
type Components ¶
Components holds reusable schema definitions.
type Info ¶
type Info struct {
Title string `json:"title"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
}
Info carries the service identity block.
type MediaTypeObject ¶
type MediaTypeObject struct {
Schema *Schema `json:"schema,omitempty"`
}
MediaTypeObject wraps a Schema for a given media-type key.
type Operation ¶
type Operation struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
Responses map[string]Response `json:"responses"`
}
Operation is a single HTTP method on a path.
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"` // "path", "query", "header", "cookie"
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Schema *Schema `json:"schema,omitempty"`
}
Parameter describes a path, query, header, or cookie parameter.
type PathItem ¶
type PathItem struct {
Get *Operation `json:"get,omitempty"`
Post *Operation `json:"post,omitempty"`
Put *Operation `json:"put,omitempty"`
Delete *Operation `json:"delete,omitempty"`
Patch *Operation `json:"patch,omitempty"`
}
PathItem groups the operations available on a single URL path.
type Response ¶
type Response struct {
Description string `json:"description"`
Content map[string]MediaTypeObject `json:"content,omitempty"`
}
Response describes a single HTTP response.
type Schema ¶
type Schema struct {
Type string `json:"type,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty"`
Example interface{} `json:"example,omitempty"`
}
Schema is a simplified JSON Schema subset used inside OpenAPI.
type Spec ¶
type Spec struct {
OpenAPI string `json:"openapi"` // always "3.0.3"
Info Info `json:"info"`
Paths map[string]PathItem `json:"paths"`
Components *Components `json:"components,omitempty"`
}
Spec is the root OpenAPI 3.0.3 document. Only the fields fleet services use are included — the type is intentionally minimal.
func New ¶
New creates a Spec pre-populated with the four standard fleet endpoints that every container service exposes via go-common/server:
- GET /health → 200 {"status":"healthy"}
- GET /version → 200 text/plain
- GET /selftest → 200 {}
- GET /openapi.json → 200 (this document, self-referential)