Documentation
¶
Index ¶
- func ApplySecurity(req *http.Request, schemes []ResolvedSecurityScheme, ...) error
- func FirstJSONSchema(content *orderedmap.Map[string, *v3.MediaType]) (*base.Schema, bool)
- func IsArraySchema(schema *base.Schema) bool
- func IsFreeForm(schema *base.Schema) bool
- func IsNullable(schema *base.Schema) bool
- func MergeSecurity(base, override map[string]string) map[string]string
- func PropertySchema(schema *base.Schema, name string) (*base.Schema, bool)
- func ResolveVariant(schema *base.Schema, data map[string]any) (*base.Schema, error)
- func ResponseSchema(op *v3.Operation, statusCode int) (*base.Schema, bool)
- func UnderlyingType(schema *base.Schema) *base.Schema
- type ResolvedSecurityScheme
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplySecurity ¶
func ApplySecurity(req *http.Request, schemes []ResolvedSecurityScheme, credentials map[string]string) error
ApplySecurity injects credentials into the outgoing request for each resolved scheme, using the caller-supplied credentials map (keyed by scheme name). A missing credential for a scheme the invoked operation actually requires fails here, at call time, using only the standard library's net/http and encoding/base64 - not eagerly at earlier construction time, since an operation the caller never calls shouldn't require its credentials to be supplied.
This returns a plain Go error. Callers embedding this in a language runtime with its own catchable/uncatchable error distinction (e.g. a scripting layer) should treat a missing credential as a caller bug - not a recoverable runtime condition like an HTTP-level auth failure from the server would be - and propagate it accordingly.
func FirstJSONSchema ¶
FirstJSONSchema finds the schema of the first JSON media type in content (an operation's requestBody.content or a response's content - both the same *orderedmap.Map[string, *v3.MediaType] shape), skipping any content-type not containing "json" and any media type with no schema. Returns ok=false if content is nil or declares no matching media type.
func IsArraySchema ¶
IsArraySchema reports whether schema declares the JSON Schema "array" type.
func IsFreeForm ¶
IsFreeForm reports whether schema describes an unstructured/arbitrary JSON value - no fixed Properties, and no composition (allOf/oneOf/anyOf) that would let the value's shape be resolved. A caller decoding a free-form value should fall back to a generic, untyped conversion rather than a schema-driven one - this is the right behavior for something like a tool's free-form `input_schema`, which must stay an opaque passthrough.
func IsNullable ¶
IsNullable reports whether schema allows a JSON null value, across both OpenAPI 3.0 (`nullable: true`) and 3.1 (`anyOf: [T, {type: null}]`) dialects.
func MergeSecurity ¶
MergeSecurity overlays call-level credential overrides onto a base credentials map, so a call can override just the schemes it cares about without having to resupply every credential the base map already has.
func PropertySchema ¶
PropertySchema resolves the schema for a named property, checking the schema's own Properties first, then each AllOf member in order - a merged property view, since the schema doesn't compose AllOf members into one and resolution has to check each in turn.
func ResolveVariant ¶
ResolveVariant determines the concrete schema for a value at this node, given the schema declared for it and the already-decoded data. If schema is a discriminated oneOf, it dispatches on the discriminator property's value in data. If it's a bare oneOf/anyOf union (no discriminator) with more than one candidate, it falls back to structural matching. A union with exactly one candidate resolves to that candidate directly - there's nothing to disambiguate, and the wrapper schema itself has no Properties of its own to decode against. A schema with no candidates at all (neither oneOf/anyOf, or an anyOf that's only the nullable-null branch) is returned unchanged.
func ResponseSchema ¶
ResponseSchema finds the declared response schema for an operation given the actual received status code: an exact match in op.Responses.Codes (keyed by the status code string, e.g. "200"), falling back to op.Responses.Default. Returns ok=false if the operation declares no response schema at all for this status - callers should preserve whatever their pre-typed-response behavior was in that case.
Types ¶
type ResolvedSecurityScheme ¶
type ResolvedSecurityScheme struct {
// contains filtered or unexported fields
}
ResolvedSecurityScheme is a single scheme (from one AND'd security requirement) that must be satisfied to call an operation.
func ResolveOperationSecurity ¶
func ResolveOperationSecurity( securitySchemes *orderedmap.Map[string, *v3.SecurityScheme], globalSecurity []*base.SecurityRequirement, opSecurity []*base.SecurityRequirement, ) ([]ResolvedSecurityScheme, error)
ResolveOperationSecurity determines the effective, AND'd set of security schemes required for an operation. The operation's own `security` (if declared at all, even as an empty slice) entirely overrides the document's global `security` - the OpenAPI "operation-level takes precedence" rule, matching libopenapi's own nil-vs-empty-slice distinction (v3/operation.go's Operation.Security: a nil Security means "not declared", an empty-but-non-nil slice means "declared as empty", i.e. explicitly no auth for this operation).
OR-alternatives (more than one requirement in the effective array) are out of scope for this iteration and fail loudly rather than silently picking one; so do any scheme types other than apiKey/http, cookie-based apiKey, and http schemes other than basic/bearer.