Documentation
¶
Index ¶
- Constants
- func ParameterComponentName(parameter *Parameter) string
- func RenderBodyTypes(bodyTypes *BodyTypes) (map[string]map[string]*RenderedEndpointBodies, map[string]*openapi.Schema)
- func RenderExternalDocs(docs *ExternalDocs) *openapi.ExternalDocs
- func RenderSchema(schema *Schema) *openapi.Schema
- func RenderSchemaMap(schemas map[string]*Schema) map[string]*openapi.Schema
- type Analyzer
- func (a *Analyzer) AnalyzeSchema(attr *expr.AttributeExpr, noref ...bool) *Schema
- func (a *Analyzer) ClaimExplicitName(name string, h uint64) string
- func (a *Analyzer) Components() map[string]*Schema
- func (*Analyzer) HashAttribute(att *expr.AttributeExpr, h hash.Hash64) uint64
- func (a *Analyzer) SchemaHashes() map[string]uint64
- func (a *Analyzer) Uniquify(name string, h uint64) string
- type AnalyzerOption
- type BodyTypes
- type BoolOrSchema
- type Components
- type Discriminator
- type Document
- type EndpointBodies
- type Example
- type ExampleRef
- type ExternalDocs
- type Header
- type HeaderRef
- type Link
- type Media
- type MediaType
- type Operation
- type Parameter
- type ParameterRef
- type PathItem
- type RenderedEndpointBodies
- type RequestBody
- type RequestBodyRef
- type Response
- type ResponseLink
- type ResponseLinkRef
- type ResponseRef
- type Schema
Constants ¶
const ( ParameterComponentRefPrefix = "#/components/parameters/" HeaderComponentRefPrefix = "#/components/headers/" RequestBodyComponentRefPrefix = "#/components/requestBodies/" ResponseComponentRefPrefix = "#/components/responses/" ExampleComponentRefPrefix = "#/components/examples/" )
Variables ¶
This section is empty.
Functions ¶
func ParameterComponentName ¶
func RenderBodyTypes ¶
func RenderBodyTypes(bodyTypes *BodyTypes) (map[string]map[string]*RenderedEndpointBodies, map[string]*openapi.Schema)
RenderBodyTypes converts IR endpoint bodies and components to rendered OpenAPI schemas.
func RenderExternalDocs ¶
func RenderExternalDocs(docs *ExternalDocs) *openapi.ExternalDocs
RenderExternalDocs converts IR external docs to the concrete OpenAPI type.
func RenderSchema ¶
RenderSchema converts an IR schema to the concrete OpenAPI schema type.
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer converts expr types into IR schemas and endpoint body models.
func NewAnalyzer ¶
func NewAnalyzer(rand *expr.ExampleGenerator, closeObjects bool, options ...AnalyzerOption) *Analyzer
NewAnalyzer creates a schema analyzer.
func (*Analyzer) AnalyzeSchema ¶
func (a *Analyzer) AnalyzeSchema(attr *expr.AttributeExpr, noref ...bool) *Schema
AnalyzeSchema builds an IR schema for the given attribute.
func (*Analyzer) ClaimExplicitName ¶
ClaimExplicitName reserves an explicit component name or panics if it conflicts.
func (*Analyzer) Components ¶
Components returns the analyzed component schemas.
func (*Analyzer) HashAttribute ¶
HashAttribute computes a structural hash for the given attribute.
func (*Analyzer) SchemaHashes ¶
SchemaHashes returns the tracked component hashes keyed by component name.
type AnalyzerOption ¶
type AnalyzerOption func(*Analyzer)
AnalyzerOption customizes analyzer behavior.
func WithExampleSuppression ¶
func WithExampleSuppression(fn func(*expr.AttributeExpr, bool) bool) AnalyzerOption
WithExampleSuppression controls whether examples should be omitted.
func WithExampleValue ¶
func WithExampleValue(fn func(*expr.AttributeExpr, any) (any, bool)) AnalyzerOption
WithExampleValue projects raw expr examples into OpenAPI-safe values.
type BodyTypes ¶
type BodyTypes struct {
Services map[string]map[string]*EndpointBodies
Components map[string]*Schema
}
BodyTypes groups endpoint bodies and component schemas.
func BuildBodyTypes ¶
func BuildBodyTypes(api *expr.APIExpr, types []expr.UserType, resultTypes []*expr.ResultTypeExpr, options ...AnalyzerOption) *BodyTypes
BuildBodyTypes analyzes endpoint request and response bodies plus referenced components.
type BoolOrSchema ¶
BoolOrSchema models JSON Schema bool-or-schema fields.
type Components ¶
type Components struct {
Schemas map[string]*Schema
Parameters map[string]*ParameterRef
Headers map[string]*HeaderRef
RequestBodies map[string]*RequestBodyRef
Responses map[string]*ResponseRef
Examples map[string]*ExampleRef
}
Components contains reusable IR components.
type Discriminator ¶
Discriminator describes union selection.
type Document ¶
type Document struct {
Paths map[string]*PathItem
Components *Components
}
Document is the root OpenAPI-oriented IR document.
func BuildDocument ¶
func BuildDocument(api *expr.APIExpr, types []expr.UserType, resultTypes []*expr.ResultTypeExpr, options ...AnalyzerOption) *Document
BuildDocument analyzes HTTP body/schema-related OpenAPI document data.
type EndpointBodies ¶
EndpointBodies describes the request and response body schemas for one endpoint.
type ExampleRef ¶
ExampleRef is an example reference or value.
type ExternalDocs ¶
ExternalDocs describes operation-level external documentation.
type Header ¶
type Header struct {
Description string
Required bool
Schema *Schema
Example any
Examples map[string]*ExampleRef
Extensions map[string]any
}
Header describes an IR header.
type Link ¶
type Link struct {
Title string
Description string
Rel string
Href string
Method string
Schema *Schema
TargetSchema *Schema
ResultType string
EncType string
}
Link represents JSON hyper schema link metadata.
type MediaType ¶
type MediaType struct {
Schema *Schema
Example any
Examples map[string]*ExampleRef
Extensions map[string]any
}
MediaType describes an IR media type.
type Operation ¶
type Operation struct {
Tags []string
Summary string
Description string
OperationID string
Parameters []*ParameterRef
RequestBody *RequestBodyRef
Responses map[string]*ResponseRef
Deprecated bool
Security []map[string][]string
ExternalDocs *ExternalDocs
Extensions map[string]any
}
Operation describes an IR operation.
func BuildOperation ¶
func BuildOperation(endpoint *expr.HTTPEndpointExpr, bodies *EndpointBodies, rand *expr.ExampleGenerator, closeObjects bool) *Operation
BuildOperation analyzes HTTP body/content-related OpenAPI operation data.
func BuildRouteOperation ¶
func BuildRouteOperation(route *expr.RouteExpr, path string, bodies *EndpointBodies, rand *expr.ExampleGenerator, apiMeta expr.MetaExpr, closeObjects bool) *Operation
BuildRouteOperation analyzes one route-scoped HTTP operation including parameters and OpenAPI metadata.
type Parameter ¶
type Parameter struct {
Name string
In string
ComponentName string `json:"-"`
Description string
Style string
Explode *bool
AllowEmptyValue bool
AllowReserved bool
Deprecated bool
Required bool
Schema *Schema
Example any
Examples map[string]*ExampleRef
Content map[string]*MediaType
Extensions map[string]any
}
Parameter describes an IR parameter object.
type ParameterRef ¶
ParameterRef is a parameter reference or value.
type RenderedEndpointBodies ¶
type RenderedEndpointBodies struct {
RequestBody *openapi.Schema
ResponseBodies map[int][]*openapi.Schema
}
RenderedEndpointBodies is the rendered endpoint body set used by v3 adapters.
type RequestBody ¶
type RequestBody struct {
Description string
Required bool
ComponentName string `json:"-"`
Content map[string]*MediaType
Extensions map[string]any
}
RequestBody describes an IR request body.
type RequestBodyRef ¶
type RequestBodyRef struct {
Ref string
Value *RequestBody
}
RequestBodyRef is a request body reference or value.
type Response ¶
type Response struct {
Description string
Headers map[string]*HeaderRef
Content map[string]*MediaType
Links map[string]*ResponseLinkRef
Extensions map[string]any
}
Response describes an IR response.
type ResponseLink ¶
type ResponseLink struct {
OperationID string
OperationRef string
Description string
Parameters map[string]any
RequestBody any
Extensions map[string]any
}
ResponseLink describes an OpenAPI response link.
type ResponseLinkRef ¶
type ResponseLinkRef struct {
Ref string
Value *ResponseLink
}
ResponseLinkRef is a response link reference or value.
type ResponseRef ¶
ResponseRef is a response reference or value.
type Schema ¶
type Schema struct {
Ref string
Type string
Format string
Items *Schema
Properties map[string]*Schema
Defs map[string]*Schema
Description string
DefaultValue any
Example any
Media *Media
ReadOnly bool
WriteOnly bool
Deprecated bool
ContentEncoding string
ContentMediaType string
PathStart string
Links []*Link
Enum []any
Pattern string
ExclusiveMinimum *float64
Minimum *float64
ExclusiveMaximum *float64
Maximum *float64
MinLength *int
MaxLength *int
MinItems *int
MaxItems *int
Required []string
AdditionalProperties *BoolOrSchema
UnevaluatedProperties *BoolOrSchema
AnyOf []*Schema
OneOf []*Schema
Discriminator *Discriminator
Extensions map[string]any
}
Schema represents a renderer-neutral schema node.