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 AnalyzePartial(source []byte, selection Selection, allowLossy bool) (*PartialAnalysis, SelectionReport, error)
- func AnalyzeSelected(source []byte, selection Selection) (*Document, Diagnostics, SelectionReport, error)
- func Render(document *Document, options Options) ([]byte, error)
- type AdditionalProperties
- type Components
- type Diagnostic
- type Diagnostics
- type Document
- type Example
- type Header
- type NamedHeader
- type NamedParameter
- type NamedProperty
- type NamedRequestBody
- type NamedResponse
- type NamedSchema
- type Operation
- type Options
- type Parameter
- type PartialAnalysis
- type RequestBody
- type Response
- type Schema
- type SchemaDefault
- type SecurityRequirement
- type SecurityRequirementScheme
- type SecurityRequirements
- type SecurityScheme
- type Selection
- type SelectionReport
- type SkippedOperation
- type StatusResponse
- type TagSummary
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedVersion = errors.New("unsupported OpenAPI version")
ErrUnsupportedVersion indicates that the input is not an OpenAPI 3.0, 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.
func AnalyzePartial ¶
func AnalyzePartial(source []byte, selection Selection, allowLossy bool) (*PartialAnalysis, SelectionReport, error)
AnalyzePartial returns the largest operation subset that can be rendered. Lossy diagnostics are warnings only when allowLossy is true.
func AnalyzeSelected ¶
func AnalyzeSelected(source []byte, selection Selection) (*Document, Diagnostics, SelectionReport, error)
AnalyzeSelected parses source and retains operations that match selection. It returns tag counts and paths that do not match the requested tags.
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 {
// SecuritySchemes contains supported reusable security schemes.
SecuritySchemes []SecurityScheme
// 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 ¶
type Diagnostic struct {
// Code identifies the importer limit class, for example "media-type".
Code string
// Path is the JSON Pointer of the offending construct in the source document.
Path string
// Message explains why the construct cannot be imported faithfully.
Message string
}
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
// Extensions contains document-level vendor extensions.
Extensions map[string]any
// SecurityDefined reports whether the source declares the security member.
SecurityDefined bool
// Security contains root security requirement alternatives in source order.
Security SecurityRequirements
// 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 Example ¶
type Example struct {
// Name is the authored media example key or a deterministic schema example name.
Name string
// Summary is the authored media example summary.
Summary string
// Description is the authored example description.
Description string
// Value is the decoded example value.
Value any
}
Example is an example value retained from a schema or media type.
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
// Extensions contains operation-level vendor extensions.
Extensions map[string]any
// SecurityDefined reports whether the operation overrides root security.
SecurityDefined bool
// Security contains operation security requirement alternatives.
Security SecurityRequirements
// 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
// Extensions contains parameter-level vendor extensions.
Extensions map[string]any
// 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 PartialAnalysis ¶
type PartialAnalysis struct {
// Document contains all operations that pass strict analysis.
Document *Document
// Blocked contains the grouped refusal source before operations are skipped.
Blocked Diagnostics
// Warnings contains allowed lossy diagnostics for retained operations.
Warnings Diagnostics
// Omitted contains document-level constructs skipped by partial import.
Omitted Diagnostics
// OperationOmissions contains metadata omitted from retained operations.
OperationOmissions []SkippedOperation
// Skipped contains operations that cannot be rendered and their diagnostics.
Skipped []SkippedOperation
// TotalOperations is the number of operations before partial analysis.
TotalOperations int
// TotalSchemas is the number of reachable schemas before partial analysis.
TotalSchemas int
}
PartialAnalysis contains the renderable subset of an OpenAPI document.
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
// ContentTypes are the request media types that share Schema and Examples.
ContentTypes []string
// Schema describes the request body.
Schema *Schema
// Examples contains examples declared on the request media type.
Examples []Example
// Extensions contains request-body-level vendor extensions.
Extensions map[string]any
}
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 response media type, if the response has a body.
ContentType string
// Schema describes the response body.
Schema *Schema
// Examples contains examples declared on the response media type.
Examples []Example
// Headers contains response headers sorted by wire name.
Headers []NamedHeader
// Extensions contains response-level vendor extensions.
Extensions map[string]any
}
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
// Unconstrained reports that the schema accepts every JSON value.
Unconstrained bool
// Type is the single JSON Schema type.
Type string
// Nullable reports that the schema also accepts the JSON null value.
Nullable bool
// Format is the authored schema format.
Format string
// Title is the schema title.
Title string
// Description is the schema description.
Description string
// Bases contains local object schemas extended by this schema.
Bases []*Schema
// 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
// Deprecated reports whether the schema declares the JSON Schema
// deprecated keyword.
Deprecated bool
// ReadOnly reports whether the schema declares the JSON Schema readOnly
// keyword.
ReadOnly bool
// WriteOnly reports whether the schema declares the JSON Schema writeOnly
// keyword.
WriteOnly bool
// Default holds the decoded JSON Schema default value, or nil when the
// schema declares no default.
Default *SchemaDefault
// Examples contains decoded examples declared by example or examples.
Examples []Example
// Extensions contains schema-level vendor extensions.
Extensions map[string]any
// contains filtered or unexported fields
}
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 SchemaDefault ¶
type SchemaDefault struct {
// Value is the decoded default value.
Value any
}
SchemaDefault holds a decoded JSON Schema default value together with its presence, distinguishing an authored default from no default at all.
type SecurityRequirement ¶
type SecurityRequirement struct {
// Schemes lists required schemes in source order. An empty list permits
// anonymous access as one alternative.
Schemes []SecurityRequirementScheme
}
SecurityRequirement lists schemes that must all succeed for one alternative.
type SecurityRequirementScheme ¶
type SecurityRequirementScheme struct {
// Name is the referenced security scheme component key.
Name string
// Scopes contains the authored scopes. Supported API-key schemes require
// this list to be empty.
Scopes []string
}
SecurityRequirementScheme references one component security scheme.
type SecurityRequirements ¶
type SecurityRequirements []SecurityRequirement
SecurityRequirements lists alternative OpenAPI security requirement objects.
type SecurityScheme ¶
type SecurityScheme struct {
// Name is the authored component key.
Name string
// GoName is the deterministic collision-safe variable identifier.
GoName string
// Type is the OpenAPI security scheme type.
Type string
// Description describes the credential contract.
Description string
// In identifies the credential location: header, query, or cookie.
In string
// ParameterName is the authored wire name of the credential.
ParameterName string
// Extensions contains scheme-level vendor extensions.
Extensions map[string]any
}
SecurityScheme is a supported reusable OpenAPI security scheme.
type Selection ¶
type Selection struct {
// Tags selects operations with at least one exact tag match.
Tags []string
// PathPrefixes selects operations whose path starts with a prefix.
PathPrefixes []string
// Paths selects operations whose path matches a path.Match pattern.
Paths []string
}
Selection identifies the union of OpenAPI operations to import.
type SelectionReport ¶
type SelectionReport struct {
// Tags contains deterministic operation and path counts by tag.
Tags []TagSummary
// UnclaimedPaths lists paths that do not use a requested tag.
UnclaimedPaths []string
}
SelectionReport describes the available tags and paths excluded by tag filters.
type SkippedOperation ¶
type SkippedOperation struct {
// Method is the uppercase HTTP method.
Method string
// Path is the authored OpenAPI path.
Path string
// Diagnostics explains why the operation cannot be rendered.
Diagnostics Diagnostics
}
SkippedOperation describes one operation omitted from a partial import.
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.
type TagSummary ¶
type TagSummary struct {
// Name is the exact OpenAPI tag name.
Name string
// Operations is the number of operations assigned to the tag.
Operations int
// Paths is the number of distinct paths assigned to the tag.
Paths int
}
TagSummary reports the number of operations and paths assigned to a tag.
Source Files
¶
- analyze.go
- analyze_examples.go
- analyze_extensions.go
- analyze_request_content.go
- analyze_schema_composition.go
- diagnostics.go
- model.go
- names.go
- partial.go
- plan.go
- render.go
- render_index.go
- render_media.go
- render_nullable.go
- render_request_body.go
- render_response.go
- render_schema.go
- schema_classification.go
- security.go
- selection.go