Documentation
¶
Overview ¶
Package swaggestimpl is the sole importer of github.com/swaggest/openapi-go in the forge repo. It exposes type aliases and small constructors that other forge packages (openapi/, transport/rest/, jsonapi/, cmd/petstore/) use without ever pulling swaggest into their import graphs.
Keeping the boundary tight makes it trivial to replace or vendor the implementation later — only this package changes.
Index ¶
- func AddRequestExample(op *openapi31.Operation, name string, value interface{})
- func AddResponseExample(op *openapi31.Operation, status int, name string, value interface{})
- func ApplyAPIKey(spec *Spec31, name, fieldName, in string)
- func ApplyBasicAuth(spec *Spec31, name string)
- func ApplyBearerJWT(spec *Spec31, name string)
- func ApplyBearerToken(spec *Spec31, name, bearerFormat string)
- func ApplyDefaultSecurity(spec *Spec31, schemeNames []string)
- func ApplyExternalDocs(spec *Spec31, url, description string)
- func ApplyMutualTLS(spec *Spec31, name string)
- func ApplyOAuth2AuthorizationCode(spec *Spec31, name, authURL, tokenURL string, scopes map[string]string)
- func ApplyOAuth2ClientCredentials(spec *Spec31, name, tokenURL string, scopes map[string]string)
- func ApplyOAuth2Implicit(spec *Spec31, name, authURL string, scopes map[string]string)
- func ApplyOAuth2Password(spec *Spec31, name, tokenURL string, scopes map[string]string)
- func ApplyOIDC(spec *Spec31, name, discoveryURL string)
- func ApplyOperationExternalDocs(op *openapi31.Operation, url, description string)
- func ApplyServers(spec *Spec31, urls []string, descs []string)
- func ApplyTags(spec *Spec31, names, descriptions []string)
- func EnsurePathParameter(op *openapi31.Operation, name string)
- func ExposeOperation(oc OperationContext) *openapi31.Operation
- func NewSwaggerUIHandler(title, specURL, basePath string) http.Handler
- func OperationOn(r Reflector, method, path string) *openapi31.Operation
- type ContentOption
- type OperationContext
- type Reflector
- type Spec31
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddRequestExample ¶
AddRequestExample attaches a named example to every content-type declared on the operation's request body. Called after the request structure has been added so the body's media types are populated.
Idempotent on the name: subsequent calls with the same name overwrite the prior example.
func AddResponseExample ¶
AddResponseExample attaches a named example to every content-type of the response at the given HTTP status. Like AddRequestExample, the status entry must already exist (added via AddRespStructure).
func ApplyAPIKey ¶
ApplyAPIKey writes an apiKey scheme.
func ApplyBasicAuth ¶
ApplyBasicAuth writes an HTTP-basic scheme.
func ApplyBearerJWT ¶
ApplyBearerJWT writes an HTTP-bearer scheme with BearerFormat=JWT to components.securitySchemes[name].
func ApplyBearerToken ¶
ApplyBearerToken writes an HTTP-bearer scheme with the given bearer format. Format is informational (e.g. "JWT", "opaque").
func ApplyDefaultSecurity ¶
ApplyDefaultSecurity sets the root-level security requirement.
func ApplyExternalDocs ¶
ApplyExternalDocs sets the spec-level externalDocs block.
func ApplyMutualTLS ¶
ApplyMutualTLS writes a mutualTLS scheme.
func ApplyOAuth2AuthorizationCode ¶
func ApplyOAuth2AuthorizationCode(spec *Spec31, name, authURL, tokenURL string, scopes map[string]string)
ApplyOAuth2AuthorizationCode writes an OAuth2 scheme with the authorization-code flow.
func ApplyOAuth2ClientCredentials ¶
ApplyOAuth2ClientCredentials writes an OAuth2 scheme with the client-credentials flow.
func ApplyOAuth2Implicit ¶
ApplyOAuth2Implicit writes an OAuth2 scheme with the implicit flow.
func ApplyOAuth2Password ¶
ApplyOAuth2Password writes an OAuth2 scheme with the password flow.
func ApplyOperationExternalDocs ¶
ApplyOperationExternalDocs attaches an external docs block to the operation.
func ApplyServers ¶
ApplyServers writes the servers array.
func EnsurePathParameter ¶
EnsurePathParameter appends a Parameter{In: path, Name: name, Required: true} to the operation if one isn't already declared. Used by the Collector to satisfy swaggest's path-param validation when the kit's handlers don't declare path params via struct tags (they use r.PathValue("name") instead).
func ExposeOperation ¶
func ExposeOperation(oc OperationContext) *openapi31.Operation
ExposeOperation reaches through swaggest's OperationExposer (openapi31 variant) to get the concrete *Operation for direct mutation. Used by the forge wrapper to attach external docs and example values that aren't exposed on the public OperationContext interface.
func NewSwaggerUIHandler ¶
NewSwaggerUIHandler returns an http.Handler that renders Swagger UI v5 at basePath, fetching its spec from specURL. Title shows in the UI's header.
func OperationOn ¶
OperationOn looks up an Operation already added to the spec by (method, path). Returns nil if no such operation exists. The Collector uses this to apply example mutations that have to land AFTER AddOperation has finalised the Operation's RequestBody and Responses content maps.
Types ¶
type ContentOption ¶
type ContentOption = openapi.ContentOption
ContentOption aliases swaggest's content-option type used by AddReqStructure and AddRespStructure.
func WithHTTPStatus ¶
func WithHTTPStatus(status int) ContentOption
WithHTTPStatus is the canonical content option for declaring the response status of an AddRespStructure call.
type OperationContext ¶
type OperationContext = openapi.OperationContext
OperationContext aliases swaggest's per-operation context. Method names from the swaggest interface (AddReqStructure, SetSummary, etc.) are wrapped on the openapi side; callers reference only the forge-owned openapi.OperationContext interface.
type Reflector ¶
Reflector aliases swaggest's reflector interface. Both openapi3 and openapi31 reflectors implement it; we use the openapi31 variant by default for OpenAPI 3.1 output.
func NewReflector ¶
func NewReflector() Reflector
NewReflector returns a fresh openapi31 reflector — the canonical engine for OpenAPI 3.1 output.
Configured to strip kit package prefixes from schema names so `openapi.ErrorBody` doesn't surface as `OpenapiErrorBody` and `jsonapi.Document` doesn't surface as `JsonapiDocument` in the `#/components/schemas/...` map. Consumer-defined types keep their natural prefix (`auth.UserDTO` stays `AuthUserDTO`).