ir

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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 ParameterComponentName(parameter *Parameter) string

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

func RenderSchema(schema *Schema) *openapi.Schema

RenderSchema converts an IR schema to the concrete OpenAPI schema type.

func RenderSchemaMap

func RenderSchemaMap(schemas map[string]*Schema) map[string]*openapi.Schema

RenderSchemaMap converts a schema map.

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

func (a *Analyzer) ClaimExplicitName(name string, h uint64) string

ClaimExplicitName reserves an explicit component name or panics if it conflicts.

func (*Analyzer) Components

func (a *Analyzer) Components() map[string]*Schema

Components returns the analyzed component schemas.

func (*Analyzer) HashAttribute

func (*Analyzer) HashAttribute(att *expr.AttributeExpr, h hash.Hash64) uint64

HashAttribute computes a structural hash for the given attribute.

func (*Analyzer) SchemaHashes

func (a *Analyzer) SchemaHashes() map[string]uint64

SchemaHashes returns the tracked component hashes keyed by component name.

func (*Analyzer) Uniquify

func (a *Analyzer) Uniquify(name string, h uint64) string

Uniquify returns a stable unique 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

type BoolOrSchema struct {
	Bool   *bool
	Schema *Schema
}

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

type Discriminator struct {
	PropertyName string
	Mapping      map[string]string
}

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

type EndpointBodies struct {
	RequestBody    *Schema
	ResponseBodies map[int][]*Schema
}

EndpointBodies describes the request and response body schemas for one endpoint.

type Example

type Example struct {
	Summary     string
	Description string
	Value       any
}

Example describes an IR example object.

type ExampleRef

type ExampleRef struct {
	Ref   string
	Value *Example
}

ExampleRef is an example reference or value.

type ExternalDocs

type ExternalDocs struct {
	Description string
	URL         string
	Extensions  map[string]any
}

ExternalDocs describes operation-level external documentation.

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 HeaderRef

type HeaderRef struct {
	Ref   string
	Value *Header
}

HeaderRef is a header reference or value.

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 Media

type Media struct {
	BinaryEncoding string
	Type           string
}

Media represents JSON hyper schema media.

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

type ParameterRef struct {
	Ref   string
	Value *Parameter
}

ParameterRef is a parameter reference or value.

type PathItem

type PathItem struct {
	Operations map[string]*Operation
}

PathItem groups operations by method.

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 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

type ResponseRef struct {
	Ref   string
	Value *Response
}

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.

Jump to

Keyboard shortcuts

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