Documentation
¶
Overview ¶
Package openapi provides the active schema model and shared helpers used to generate OpenAPI 3.1 and 3.2 specifications from Loom designs.
The exported schema, tag, and external-documentation types are part of the v3 document model. Rendering starts with the v3 package and keeps schema analysis state per invocation in internal/ir. This package intentionally does not provide the legacy JSON Hyper-Schema generator, global definitions registry, or compatibility aliases for those removed entry points.
Index ¶
- Constants
- func AdditionalPropertiesFromExpr(meta expr.MetaExpr) any
- func ClosedObjectModeFromExpr(meta expr.MetaExpr) bool
- func ExtensionsFromExpr(mdata expr.MetaExpr) map[string]any
- func MarshalJSON(v any, extensions map[string]any) ([]byte, error)
- func MarshalYAML(v any, extensions map[string]any) (any, error)
- func MergeExtensions(extensionSets ...map[string]any) map[string]any
- func MustGenerate(meta expr.MetaExpr) bool
- func ScopedExtensionsFromExpr(mdata expr.MetaExpr, scope string) map[string]any
- func TagNamesFromExpr(mdata expr.MetaExpr) (tagNames []string)
- type Discriminator
- type ExternalDocs
- type Schema
- type Tag
- type Type
- type XML
Constants ¶
const ( // Array represents a JSON array. Array Type = "array" // Boolean represents a JSON boolean. Boolean = "boolean" // Integer represents a JSON number without a fraction or exponent part. Integer = "integer" // Number represents any JSON number. Number includes integer. Number = "number" // Null represents the JSON null value. Null = "null" // Object represents a JSON object. Object = "object" // String represents a JSON string. String = "string" )
Variables ¶
This section is empty.
Functions ¶
func AdditionalPropertiesFromExpr ¶
AdditionalPropertiesFromExpr extracts the OpenAPI additionalProperties.
func ClosedObjectModeFromExpr ¶
ClosedObjectModeFromExpr reports whether OpenAPI closed object mode is enabled via metadata.
func ExtensionsFromExpr ¶
ExtensionsFromExpr generates openapi extensions from the given meta expression.
func MarshalJSON ¶
MarshalJSON produces the JSON resulting from encoding an object composed of the fields in v (which must me a struct) and the keys in extensions.
func MarshalYAML ¶
MarshalYAML produces the JSON resulting from encoding an object composed of the fields in v (which must me a struct) and the keys in extensions.
func MergeExtensions ¶ added in v1.8.0
MergeExtensions combines extension maps, with later maps taking precedence.
func MustGenerate ¶
MustGenerate returns true if the meta indicates that a OpenAPI specification should be generated, false otherwise.
func ScopedExtensionsFromExpr ¶ added in v1.8.0
ScopedExtensionsFromExpr returns OpenAPI extensions declared for scope. Scoped extension metadata uses openapi:<scope>:extension:<x-name> keys.
func TagNamesFromExpr ¶
TagNamesFromExpr computes the names of the OpenAPI tags specified in the given metadata expressions.
Types ¶
type Discriminator ¶
type Discriminator struct {
// PropertyName names the object property that selects the union branch.
PropertyName string `json:"propertyName" yaml:"propertyName"`
// Mapping maps discriminator values to schema references.
Mapping map[string]string `json:"mapping,omitzero,omitempty" yaml:"mapping,omitempty"`
// DefaultMapping identifies the fallback schema reference.
DefaultMapping string `json:"defaultMapping,omitzero" yaml:"defaultMapping,omitempty"`
// Optional records that the discriminator property may be omitted in OpenAPI 3.2.
Optional bool `json:"-" yaml:"-"`
}
Discriminator represents an OpenAPI discriminator object.
type ExternalDocs ¶
type ExternalDocs struct {
Description string `json:"description,omitzero"`
URL string `json:"url,omitzero"`
Extensions map[string]any `json:"-" yaml:"-"`
}
ExternalDocs represents an OpenAPI External Documentation object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#externalDocumentationObject
func DocsFromExpr ¶
func DocsFromExpr(docs *expr.DocsExpr, meta expr.MetaExpr) *ExternalDocs
DocsFromExpr builds a ExternalDocs from the Loom docs expression.
type Schema ¶
type Schema struct {
// Schema identifies the JSON Schema dialect for this schema node.
Schema string `json:"$schema,omitzero" yaml:"$schema,omitempty"`
// ID identifies this schema node.
ID string `json:"id,omitzero" yaml:"id,omitempty"`
// Title is the display name of the schema.
Title string `json:"title,omitzero" yaml:"title,omitempty"`
// Type is the JSON value type accepted by the schema.
Type Type `json:"type,omitzero" yaml:"type,omitempty"`
// Items describes array members.
Items *Schema `json:"items,omitzero" yaml:"items,omitempty"`
// Properties describes named object members.
Properties map[string]*Schema `json:"properties,omitzero,omitempty" yaml:"properties,omitempty"`
// Defs contains schema-local reusable definitions.
Defs map[string]*Schema `json:"$defs,omitzero,omitempty" yaml:"$defs,omitempty"`
// Description explains the schema contract.
Description string `json:"description,omitzero" yaml:"description,omitempty"`
// DefaultValue is the schema default.
DefaultValue any `json:"default,omitzero" yaml:"default,omitempty"`
// Example is an example value accepted by the schema.
Example any `json:"example,omitzero" yaml:"example,omitempty"`
// ReadOnly marks a value as response-only.
ReadOnly bool `json:"readOnly,omitzero" yaml:"readOnly,omitempty"`
// WriteOnly marks a value as request-only.
WriteOnly bool `json:"writeOnly,omitzero" yaml:"writeOnly,omitempty"`
// Deprecated marks the schema contract as deprecated.
Deprecated bool `json:"deprecated,omitzero" yaml:"deprecated,omitempty"`
// ContentEncoding identifies the encoding applied to string content.
ContentEncoding string `json:"contentEncoding,omitzero" yaml:"contentEncoding,omitempty"`
// ContentMediaType identifies the media type of encoded string content.
ContentMediaType string `json:"contentMediaType,omitzero" yaml:"contentMediaType,omitempty"`
// ContentSchema describes content after decoding ContentEncoding and ContentMediaType.
ContentSchema *Schema `json:"contentSchema,omitzero" yaml:"contentSchema,omitempty"`
// Ref references another schema.
Ref string `json:"$ref,omitzero" yaml:"$ref,omitempty"`
// Enum lists the accepted values.
Enum []any `json:"enum,omitzero,omitempty" yaml:"enum,omitempty"`
// Format refines the semantic format of a value.
Format string `json:"format,omitzero" yaml:"format,omitempty"`
// Pattern constrains string values with a regular expression.
Pattern string `json:"pattern,omitzero" yaml:"pattern,omitempty"`
// ExclusiveMinimum is the exclusive numeric lower bound.
ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitzero" yaml:"exclusiveMinimum,omitempty"`
// Minimum is the inclusive numeric lower bound.
Minimum *float64 `json:"minimum,omitzero" yaml:"minimum,omitempty"`
// ExclusiveMaximum is the exclusive numeric upper bound.
ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitzero" yaml:"exclusiveMaximum,omitempty"`
// Maximum is the inclusive numeric upper bound.
Maximum *float64 `json:"maximum,omitzero" yaml:"maximum,omitempty"`
// MinLength is the minimum string length.
MinLength *int `json:"minLength,omitzero" yaml:"minLength,omitempty"`
// MaxLength is the maximum string length.
MaxLength *int `json:"maxLength,omitzero" yaml:"maxLength,omitempty"`
// MinItems is the minimum array length.
MinItems *int `json:"minItems,omitzero" yaml:"minItems,omitempty"`
// MaxItems is the maximum array length.
MaxItems *int `json:"maxItems,omitzero" yaml:"maxItems,omitempty"`
// Required lists required object property names.
Required []string `json:"required,omitzero,omitempty" yaml:"required,omitempty"`
// AdditionalProperties controls values for otherwise unnamed properties.
AdditionalProperties any `json:"additionalProperties,omitzero" yaml:"additionalProperties,omitempty"`
// UnevaluatedProperties controls properties not covered by another keyword.
UnevaluatedProperties any `json:"unevaluatedProperties,omitzero" yaml:"unevaluatedProperties,omitempty"`
// AllOf requires every listed schema to match.
AllOf []*Schema `json:"allOf,omitzero,omitempty" yaml:"allOf,omitempty"`
// AnyOf requires at least one listed schema to match.
AnyOf []*Schema `json:"anyOf,omitzero,omitempty" yaml:"anyOf,omitempty"`
// OneOf requires exactly one listed schema to match.
OneOf []*Schema `json:"oneOf,omitzero,omitempty" yaml:"oneOf,omitempty"`
// Discriminator describes union branch selection.
Discriminator *Discriminator `json:"discriminator,omitzero" yaml:"discriminator,omitempty"`
// XML describes XML serialization metadata.
XML *XML `json:"xml,omitzero" yaml:"xml,omitempty"`
// Extensions contains OpenAPI extension properties.
Extensions map[string]any `json:"-" yaml:"-"`
}
Schema represents the JSON Schema vocabulary used by generated OpenAPI documents.
func NewSchema ¶
func NewSchema() *Schema
NewSchema instantiates an empty schema with writable property and definition maps.
func (*Schema) MarshalJSON ¶
MarshalJSON returns the JSON encoding of s, including extensions.
func (*Schema) MarshalYAML ¶
MarshalYAML returns the YAML representation of s, including extensions.
type Tag ¶
type Tag struct {
// Name of the tag.
Name string `json:"name,omitzero" yaml:"name,omitempty"`
// Summary is the short display label for the tag in OpenAPI 3.2.
Summary string `json:"summary,omitzero" yaml:"summary,omitempty"`
// Description is a short description of the tag.
// GFM syntax can be used for rich text representation.
Description string `json:"description,omitzero" yaml:"description,omitempty"`
// Parent names the tag that contains this tag in OpenAPI 3.2.
Parent string `json:"parent,omitzero" yaml:"parent,omitempty"`
// Kind classifies the tag in OpenAPI 3.2.
Kind string `json:"kind,omitzero" yaml:"kind,omitempty"`
// ExternalDocs is additional external documentation for this tag.
ExternalDocs *ExternalDocs `json:"externalDocs,omitzero" yaml:"externalDocs,omitempty"`
// Extensions defines the OpenAPI extensions.
Extensions map[string]any `json:"-" yaml:"-"`
}
Tag allows adding meta data to a single tag that is used by the Operation Object. It is not mandatory to have a Tag Object per tag used there.
func TagsFromExpr ¶
TagsFromExpr extracts the OpenAPI related metadata from the given expression.
func (Tag) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (Tag) MarshalYAML ¶
MarshalYAML returns value which marshaled in place of the original value
type XML ¶ added in v1.8.0
type XML struct {
// Name overrides the XML node name.
Name string `json:"name,omitzero" yaml:"name,omitempty"`
// Namespace is the absolute XML namespace URI.
Namespace string `json:"namespace,omitzero" yaml:"namespace,omitempty"`
// Prefix is the XML namespace prefix.
Prefix string `json:"prefix,omitzero" yaml:"prefix,omitempty"`
// NodeType identifies the OpenAPI 3.2 XML node kind.
NodeType string `json:"nodeType,omitzero" yaml:"nodeType,omitempty"`
// Attribute emits the value as an XML attribute.
Attribute bool `json:"attribute,omitzero" yaml:"attribute,omitempty"`
// Wrapped emits an array through a wrapping XML element.
Wrapped bool `json:"wrapped,omitzero" yaml:"wrapped,omitempty"`
}
XML describes how a schema maps to XML nodes.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
Package openapiv3 contains the algorithms and data structures used to generate OpenAPI 3.1 and 3.2 specifications from Loom designs.
|
Package openapiv3 contains the algorithms and data structures used to generate OpenAPI 3.1 and 3.2 specifications from Loom designs. |