Documentation
¶
Index ¶
- func Handler(provider DocumentProvider) http.Handler
- func HandlerFunc(provider DocumentProvider) http.HandlerFunc
- func JSONContent(schema Schema) map[string]MediaType
- func Marshal(doc *Document) ([]byte, error)
- func PublicSecurity() *[]SecurityRequirement
- func RequireSecurity(reqs ...SecurityRequirement) *[]SecurityRequirement
- func WriteJSON(w io.Writer, doc *Document) error
- type Components
- type Document
- type DocumentProvider
- type Info
- type MediaType
- type Operation
- type Parameter
- type PathItem
- type RequestBody
- type Response
- type Schema
- type SecurityRequirement
- type SecurityScheme
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(provider DocumentProvider) http.Handler
Handler builds an http.Handler that serves the document as JSON.
func HandlerFunc ¶
func HandlerFunc(provider DocumentProvider) http.HandlerFunc
HandlerFunc adapts a provider into a GET-friendly handler func.
func JSONContent ¶
func PublicSecurity ¶
func PublicSecurity() *[]SecurityRequirement
PublicSecurity returns an explicit empty security override marking an operation as requiring NO authentication, even when the document declares a global security requirement. (A nil Operation.Security inherits the global.) This is a contract DECLARATION only — runtime auth enforcement is the app middleware's responsibility, never the document's.
func RequireSecurity ¶
func RequireSecurity(reqs ...SecurityRequirement) *[]SecurityRequirement
RequireSecurity wraps requirements into the pointer form an Operation's Security field takes; a non-nil value overrides the document's global security for that operation.
Types ¶
type Components ¶
type Components struct {
Schemas map[string]Schema `json:"schemas,omitempty"`
SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty"`
}
type Document ¶
type Document struct {
OpenAPI string `json:"openapi"`
Info Info `json:"info"`
Servers []Server `json:"servers,omitempty"`
Security []SecurityRequirement `json:"security,omitempty"`
Paths map[string]PathItem `json:"paths,omitempty"`
Components Components `json:"components,omitempty"`
}
Document is a small OpenAPI 3.1 document model used by generated contracts. It intentionally covers the subset Nucleus scaffolds need today.
func NewDocument ¶
func (*Document) AddSecurityScheme ¶
func (d *Document) AddSecurityScheme(name string, scheme SecurityScheme)
AddSecurityScheme registers a named scheme under components.securitySchemes (lazily creating the map). Reference it by the same name from a SecurityRequirement.
func (*Document) EnsureComponents ¶
func (d *Document) EnsureComponents()
func (*Document) EnsurePaths ¶
func (d *Document) EnsurePaths()
type DocumentProvider ¶
type DocumentProvider func() *Document
DocumentProvider returns the current OpenAPI document to serve.
type Operation ¶
type Operation struct {
OperationID string `json:"operationId,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
// Security overrides the document's global security for this operation. A
// nil value inherits the global default; a non-nil value (including an empty
// slice — see PublicSecurity) replaces it. Pointer so an explicit empty
// override survives JSON marshalling (a plain slice would be omitted).
Security *[]SecurityRequirement `json:"security,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
RequestBody *RequestBody `json:"requestBody,omitempty"`
Responses map[string]Response `json:"responses"`
}
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Schema Schema `json:"schema"`
}
func QueryParameter ¶
func SearchQueryParameter ¶
type RequestBody ¶
type RequestBody struct {
Required bool `json:"required,omitempty"`
Content map[string]MediaType `json:"content"`
}
func JSONRequestBody ¶
func JSONRequestBody(schema Schema, required bool) *RequestBody
type Response ¶
type Response struct {
Description string `json:"description"`
Content map[string]MediaType `json:"content,omitempty"`
}
func EmptyResponse ¶
func ErrorResponse ¶
func JSONResponse ¶
type Schema ¶
type Schema struct {
Ref string `json:"$ref,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Description string `json:"description,omitempty"`
Properties map[string]Schema `json:"properties,omitempty"`
Items *Schema `json:"items,omitempty"`
Required []string `json:"required,omitempty"`
AdditionalProperties *Schema `json:"additionalProperties,omitempty"`
}
func ArraySchema ¶
func DataEnvelopeSchema ¶
func ErrorSchema ¶
func ErrorSchema() Schema
type SecurityRequirement ¶
SecurityRequirement is an OpenAPI Security Requirement Object (§4.8.30): a map of security-scheme name to the scope names it requires. HTTP and apiKey schemes take no scopes, so their requirement value is an empty slice.
func Require ¶
func Require(scheme string, scopes ...string) SecurityRequirement
Require builds a Security Requirement naming one registered scheme, with optional OAuth-style scopes (empty for http/apiKey schemes). A nil scope slice — including a spread nil — is normalised to an empty list, the correct serialisation for a scheme that takes no scopes.
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type"` // "http" | "apiKey"
Description string `json:"description,omitempty"`
Scheme string `json:"scheme,omitempty"` // type=http: "bearer" | "basic"
BearerFormat string `json:"bearerFormat,omitempty"` // scheme=bearer: token-shape hint, e.g. "JWT"
Name string `json:"name,omitempty"` // type=apiKey: request element name
In string `json:"in,omitempty"` // type=apiKey: "header" | "query" | "cookie"
}
SecurityScheme is an OpenAPI 3.1 Security Scheme Object (§4.8.27). Nucleus models the two schemes a generated contract realistically needs — HTTP authentication (`type: http`, e.g. `bearer` or `basic`) and API keys (`type: apiKey`). oauth2 / openIdConnect flows are out of scope for the scaffold subset.
func APIKeyScheme ¶
func APIKeyScheme(name, in string) SecurityScheme
APIKeyScheme returns an apiKey Security Scheme carried in the named request element. in is one of "header", "query" or "cookie".
func BearerAuthScheme ¶
func BearerAuthScheme(bearerFormat string) SecurityScheme
BearerAuthScheme returns an HTTP bearer Security Scheme. bearerFormat is an optional hint for the token shape (e.g. "JWT") and may be empty.