swaggestimpl

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRequestExample

func AddRequestExample(op *openapi31.Operation, name string, value interface{})

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

func AddResponseExample(op *openapi31.Operation, status int, name string, value interface{})

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

func ApplyAPIKey(spec *Spec31, name, fieldName, in string)

ApplyAPIKey writes an apiKey scheme.

func ApplyBasicAuth

func ApplyBasicAuth(spec *Spec31, name string)

ApplyBasicAuth writes an HTTP-basic scheme.

func ApplyBearerJWT

func ApplyBearerJWT(spec *Spec31, name string)

ApplyBearerJWT writes an HTTP-bearer scheme with BearerFormat=JWT to components.securitySchemes[name].

func ApplyBearerToken

func ApplyBearerToken(spec *Spec31, name, bearerFormat string)

ApplyBearerToken writes an HTTP-bearer scheme with the given bearer format. Format is informational (e.g. "JWT", "opaque").

func ApplyDefaultSecurity

func ApplyDefaultSecurity(spec *Spec31, schemeNames []string)

ApplyDefaultSecurity sets the root-level security requirement.

func ApplyExternalDocs

func ApplyExternalDocs(spec *Spec31, url, description string)

ApplyExternalDocs sets the spec-level externalDocs block.

func ApplyMutualTLS

func ApplyMutualTLS(spec *Spec31, name string)

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

func ApplyOAuth2ClientCredentials(spec *Spec31, name, tokenURL string, scopes map[string]string)

ApplyOAuth2ClientCredentials writes an OAuth2 scheme with the client-credentials flow.

func ApplyOAuth2Implicit

func ApplyOAuth2Implicit(spec *Spec31, name, authURL string, scopes map[string]string)

ApplyOAuth2Implicit writes an OAuth2 scheme with the implicit flow.

func ApplyOAuth2Password

func ApplyOAuth2Password(spec *Spec31, name, tokenURL string, scopes map[string]string)

ApplyOAuth2Password writes an OAuth2 scheme with the password flow.

func ApplyOIDC

func ApplyOIDC(spec *Spec31, name, discoveryURL string)

ApplyOIDC writes an openIdConnect scheme.

func ApplyOperationExternalDocs

func ApplyOperationExternalDocs(op *openapi31.Operation, url, description string)

ApplyOperationExternalDocs attaches an external docs block to the operation.

func ApplyServers

func ApplyServers(spec *Spec31, urls []string, descs []string)

ApplyServers writes the servers array.

func ApplyTags

func ApplyTags(spec *Spec31, names, descriptions []string)

ApplyTags writes the tags array.

func EnsurePathParameter

func EnsurePathParameter(op *openapi31.Operation, name string)

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

func NewSwaggerUIHandler(title, specURL, basePath string) http.Handler

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

func OperationOn(r Reflector, method, path string) *openapi31.Operation

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

type Reflector = openapi.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`).

type Spec31

type Spec31 = openapi31.Spec

Spec31 aliases the OpenAPI 3.1 spec root type. The forge wrapper mutates this directly to set info / servers / tags / security schemes / default security.

func Spec

func Spec(r Reflector) *Spec31

Spec returns the underlying *openapi31.Spec for direct mutation. Used by the wrapper to apply spec-level configuration that doesn't have an exposed helper on the swaggest Reflector interface.

Jump to

Keyboard shortcuts

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