Documentation
¶
Overview ¶
Package openapiimport analyzes OpenAPI documents into a deterministic, transport-neutral model suitable for later Loom design generation.
Index ¶
- Variables
- func Analyze(source []byte) (*Document, Diagnostics, error)
- func Render(document *Document, options Options) ([]byte, error)
- type AdditionalProperties
- type Components
- type Diagnostic
- type Diagnostics
- type Document
- type Header
- type NamedHeader
- type NamedParameter
- type NamedProperty
- type NamedRequestBody
- type NamedResponse
- type NamedSchema
- type Operation
- type Options
- type Parameter
- type RequestBody
- type Response
- type Schema
- type StatusResponse
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedVersion = errors.New("unsupported OpenAPI version")
ErrUnsupportedVersion indicates that the input is not an OpenAPI 3.1 or 3.2 document.
Functions ¶
func Analyze ¶
func Analyze(source []byte) (*Document, Diagnostics, error)
Analyze parses source without writing to the filesystem and returns a normalized model plus every unsupported-feature diagnostic it can discover. Syntax, model-building, and version failures are returned as errors.
Types ¶
type AdditionalProperties ¶
type AdditionalProperties struct {
// Allowed retains an authored boolean value.
Allowed *bool
// Schema describes map values when additionalProperties is a schema.
Schema *Schema
}
AdditionalProperties describes the boolean-or-schema JSON Schema keyword.
type Components ¶
type Components struct {
// Schemas contains reusable schema definitions sorted by source name.
Schemas []NamedSchema
// Parameters contains reusable parameter definitions.
Parameters []NamedParameter
// RequestBodies contains reusable request body definitions.
RequestBodies []NamedRequestBody
// Responses contains reusable response definitions.
Responses []NamedResponse
// Headers contains reusable header definitions.
Headers []NamedHeader
}
Components contains reusable OpenAPI definitions retained by the importer.
type Diagnostic ¶
Diagnostic describes an OpenAPI construct that the strict import subset cannot represent without losing contract information.
type Diagnostics ¶
type Diagnostics []Diagnostic
Diagnostics is a deterministic collection of unsupported-feature reports.
func (Diagnostics) Classify ¶
func (d Diagnostics) Classify(allowLossy bool) (fatal, warnings Diagnostics)
Classify separates diagnostics that may be omitted with explicit user consent from diagnostics that always prevent a faithful import. Unknown diagnostic codes remain fatal so new importer limits cannot be silently downgraded.
func (Diagnostics) Error ¶
func (d Diagnostics) Error() string
Error formats all diagnostics as a single error-style message.
type Document ¶
type Document struct {
// OpenAPIVersion is the exact supported 3.x version declared by the input.
OpenAPIVersion string
// Title is the API title.
Title string
// Description is the API description.
Description string
// APIVersion is the application version from the Info object.
APIVersion string
// Tags lists declared tag names in source order.
Tags []string
// Components contains normalized reusable definitions.
Components Components
// Operations contains HTTP operations in deterministic path-and-method order.
Operations []Operation
}
Document is the normalized subset of an OpenAPI document understood by the importer.
type Header ¶
type Header struct {
// Ref is the authored local component reference, when retained as a reference.
Ref string
// Description is the response header description.
Description string
// Required reports whether the response header is required.
Required bool
// Deprecated reports whether the response header is deprecated.
Deprecated bool
// Schema describes the response header value.
Schema *Schema
}
Header describes a response header. Ref is set instead of the remaining fields for a component reference.
type NamedHeader ¶
type NamedHeader struct {
// Name is the authored header name or component key.
Name string
// Header is the normalized header definition.
Header Header
}
NamedHeader is a reusable response header definition.
type NamedParameter ¶
type NamedParameter struct {
// Name is the authored OpenAPI component key.
Name string
// Parameter is the normalized component parameter.
Parameter Parameter
}
NamedParameter is a reusable parameter definition.
type NamedProperty ¶
type NamedProperty struct {
// Name is the authored JSON property name.
Name string
// Schema describes the property value.
Schema *Schema
}
NamedProperty is an object property in deterministic source-name order.
type NamedRequestBody ¶
type NamedRequestBody struct {
// Name is the authored OpenAPI component key.
Name string
// RequestBody is the normalized component request body.
RequestBody RequestBody
}
NamedRequestBody is a reusable request body definition.
type NamedResponse ¶
type NamedResponse struct {
// Name is the authored OpenAPI component key.
Name string
// Response is the normalized component response.
Response Response
}
NamedResponse is a reusable response definition.
type NamedSchema ¶
type NamedSchema struct {
// Name is the authored OpenAPI component key.
Name string
// GoName is the deterministic collision-safe Go identifier.
GoName string
// Schema is the normalized component schema.
Schema *Schema
}
NamedSchema is a reusable schema and its deterministic Go identifier.
type Operation ¶
type Operation struct {
// Method is the uppercase HTTP method.
Method string
// Path is the authored OpenAPI path template.
Path string
// OperationID is the authored OpenAPI operationId, if present.
OperationID string
// GoName is the deterministic collision-safe method identifier.
GoName string
// Summary is the authored operation summary.
Summary string
// Description is the authored operation description.
Description string
// Tags contains the operation tag names in source order.
Tags []string
// Deprecated reports whether the operation is deprecated.
Deprecated bool
// Parameters contains inherited path-item and operation parameters.
Parameters []Parameter
// RequestBody is the operation request body, if any.
RequestBody *RequestBody
// Responses contains responses sorted by status code.
Responses []StatusResponse
}
Operation is a normalized HTTP operation.
type Options ¶
type Options struct {
// PackageName is the Go package name used by the rendered design. It
// defaults to design.
PackageName string
}
Options configures deterministic Loom design rendering.
type Parameter ¶
type Parameter struct {
// Ref is the authored local component reference, when retained as a reference.
Ref string
// Name is the wire parameter name.
Name string
// In is path, query, header, or cookie.
In string
// Description is the parameter description.
Description string
// Required reports whether the parameter is required.
Required bool
// Deprecated reports whether the parameter is deprecated.
Deprecated bool
// AllowEmptyValue reports whether an empty parameter value is permitted.
AllowEmptyValue bool
// Schema describes the parameter value.
Schema *Schema
}
Parameter describes a path, query, header, or cookie parameter. Ref is set instead of the remaining fields for a component reference.
type RequestBody ¶
type RequestBody struct {
// Ref is the authored local component reference, when retained as a reference.
Ref string
// Description is the request body description.
Description string
// Required reports whether the request body is required.
Required bool
// ContentType is the single supported JSON media type.
ContentType string
// Schema describes the request body.
Schema *Schema
}
RequestBody describes a request body. Ref is set instead of the remaining fields for a component reference.
type Response ¶
type Response struct {
// Ref is the authored local component reference, when retained as a reference.
Ref string
// Description is the response description.
Description string
// ContentType is the single supported JSON media type, if the response has a body.
ContentType string
// Schema describes the response body.
Schema *Schema
// Headers contains response headers sorted by wire name.
Headers []NamedHeader
}
Response describes an HTTP response. Ref is set instead of the remaining fields for a component reference.
type Schema ¶
type Schema struct {
// Ref is the authored local schema component reference.
Ref string
// Type is the single JSON Schema type.
Type string
// Format is the authored schema format.
Format string
// Title is the schema title.
Title string
// Description is the schema description.
Description string
// Properties contains object properties sorted by wire name.
Properties []NamedProperty
// Required contains sorted required property names.
Required []string
// Items describes array elements.
Items *Schema
// AdditionalProperties describes map values or object openness.
AdditionalProperties *AdditionalProperties
// Enum contains decoded scalar enum values.
Enum []any
// Pattern is the string validation pattern.
Pattern string
// Minimum is the inclusive numeric lower bound.
Minimum *float64
// Maximum is the inclusive numeric upper bound.
Maximum *float64
// ExclusiveMinimum is the exclusive numeric lower bound.
ExclusiveMinimum *float64
// ExclusiveMaximum is the exclusive numeric upper bound.
ExclusiveMaximum *float64
// MinLength is the minimum string or collection length.
MinLength *int64
// MaxLength is the maximum string or collection length.
MaxLength *int64
// MinItems is the minimum array length.
MinItems *int64
// MaxItems is the maximum array length.
MaxItems *int64
}
Schema is the normalized JSON Schema subset expressible by the first import phase. Ref is set instead of the remaining fields for a component reference.
type StatusResponse ¶
type StatusResponse struct {
// Status is a concrete three-digit HTTP status code.
Status string
// Response is the normalized response definition.
Response Response
}
StatusResponse associates an HTTP response with its status code.