Documentation
¶
Overview ¶
Package oas3 contains an implementation of the OAS v3.1 JSON Schema specification https://spec.openapis.org/oas/v3.1.0#schema-object
Index ¶
- Constants
- Variables
- func Validate[T Referenceable | Concrete](ctx context.Context, schema *JSONSchema[T], opts ...validation.Option) []error
- func Walk(ctx context.Context, schema *JSONSchemaReferenceable) iter.Seq[SchemaWalkItem]
- func WalkExternalDocs(ctx context.Context, externalDocs *ExternalDocumentation) iter.Seq[SchemaWalkItem]
- type Concrete
- type Discriminator
- func (d *Discriminator) GetExtensions() *extensions.Extensions
- func (d *Discriminator) GetMapping() *sequencedmap.Map[string, string]
- func (d *Discriminator) GetPropertyName() string
- func (d *Discriminator) IsEqual(other *Discriminator) bool
- func (d *Discriminator) Validate(ctx context.Context, opts ...validation.Option) []error
- type ExclusiveMaximum
- type ExclusiveMinimum
- type ExternalDocumentation
- func (e *ExternalDocumentation) GetDescription() string
- func (e *ExternalDocumentation) GetExtensions() *extensions.Extensions
- func (e *ExternalDocumentation) GetURL() string
- func (e *ExternalDocumentation) IsEqual(other *ExternalDocumentation) bool
- func (e *ExternalDocumentation) Validate(ctx context.Context, opts ...validation.Option) []error
- type GetRootNoder
- type InlineOptions
- type JSONSchema
- func ConcreteToReferenceable(concrete *JSONSchema[Concrete]) *JSONSchema[Referenceable]
- func Inline(ctx context.Context, schema *JSONSchema[Referenceable], opts InlineOptions) (*JSONSchema[Referenceable], error)
- func NewJSONSchemaFromBool(value bool) *JSONSchema[Referenceable]
- func NewJSONSchemaFromReference(ref references.Reference) *JSONSchema[Referenceable]
- func NewJSONSchemaFromSchema[T Referenceable | Concrete](value *Schema) *JSONSchema[T]
- func NewReferencedScheme(ctx context.Context, ref references.Reference, ...) *JSONSchema[Referenceable]
- func ReferenceableToConcrete(referenceable *JSONSchema[Referenceable]) *JSONSchema[Concrete]
- func (j *JSONSchema[Referenceable]) GetAbsRef() references.Reference
- func (j *JSONSchema[Concrete]) GetExtensions() *extensions.Extensions
- func (j *JSONSchema[T]) GetParent() *JSONSchema[Referenceable]
- func (j *JSONSchema[Referenceable]) GetRef() references.Reference
- func (j *JSONSchema[Referenceable]) GetReference() references.Reference
- func (r *JSONSchema[Referenceable]) GetReferenceResolutionInfo() *references.ResolveResult[JSONSchemaReferenceable]
- func (s *JSONSchema[Referenceable]) GetResolvedObject() *JSONSchema[Concrete]
- func (s *JSONSchema[Referenceable]) GetResolvedSchema() *JSONSchema[Concrete]
- func (j *JSONSchema[T]) GetTopLevelParent() *JSONSchema[Referenceable]
- func (j *JSONSchema[T]) IsEqual(other *JSONSchema[T]) bool
- func (j *JSONSchema[Referenceable]) IsReference() bool
- func (s *JSONSchema[Referenceable]) IsResolved() bool
- func (s *JSONSchema[Referenceable]) MustGetResolvedSchema() *JSONSchema[Concrete]
- func (j *JSONSchema[T]) PopulateWithParent(source any, parent any) error
- func (s *JSONSchema[Referenceable]) Resolve(ctx context.Context, opts ResolveOptions) ([]error, error)
- func (j *JSONSchema[T]) SetParent(parent *JSONSchema[Referenceable])
- func (j *JSONSchema[T]) SetTopLevelParent(topLevelParent *JSONSchema[Referenceable])
- func (j *JSONSchema[T]) ShallowCopy() *JSONSchema[T]
- func (j *JSONSchema[T]) Validate(ctx context.Context, opts ...validation.Option) []error
- type JSONSchemaReferenceable
- type ParentDocumentVersion
- type Referenceable
- type ResolveOptions
- type Schema
- func (s *Schema) GetAdditionalProperties() *JSONSchema[Referenceable]
- func (s *Schema) GetAllOf() []*JSONSchema[Referenceable]
- func (s *Schema) GetAnchor() string
- func (s *Schema) GetAnyOf() []*JSONSchema[Referenceable]
- func (s *Schema) GetConst() values.Value
- func (s *Schema) GetContains() *JSONSchema[Referenceable]
- func (s *Schema) GetDefault() values.Value
- func (s *Schema) GetDefs() *sequencedmap.Map[string, *JSONSchema[Referenceable]]
- func (s *Schema) GetDependentSchemas() *sequencedmap.Map[string, *JSONSchema[Referenceable]]
- func (s *Schema) GetDeprecated() bool
- func (s *Schema) GetDescription() string
- func (s *Schema) GetDiscriminator() *Discriminator
- func (s *Schema) GetElse() *JSONSchema[Referenceable]
- func (s *Schema) GetEnum() []values.Value
- func (s *Schema) GetExample() values.Value
- func (s *Schema) GetExamples() []values.Value
- func (s *Schema) GetExclusiveMaximum() ExclusiveMaximum
- func (s *Schema) GetExclusiveMinimum() ExclusiveMinimum
- func (s *Schema) GetExtensions() *extensions.Extensions
- func (s *Schema) GetExternalDocs() *ExternalDocumentation
- func (s *Schema) GetFormat() string
- func (s *Schema) GetIf() *JSONSchema[Referenceable]
- func (s *Schema) GetItems() *JSONSchema[Referenceable]
- func (s *Schema) GetMaxContains() *int64
- func (s *Schema) GetMaxItems() *int64
- func (s *Schema) GetMaxLength() *int64
- func (s *Schema) GetMaxProperties() *int64
- func (s *Schema) GetMaximum() *float64
- func (s *Schema) GetMinContains() *int64
- func (s *Schema) GetMinItems() int64
- func (s *Schema) GetMinLength() *int64
- func (s *Schema) GetMinProperties() *int64
- func (s *Schema) GetMinimum() *float64
- func (s *Schema) GetMultipleOf() *float64
- func (s *Schema) GetNot() *JSONSchema[Referenceable]
- func (s *Schema) GetNullable() bool
- func (s *Schema) GetOneOf() []*JSONSchema[Referenceable]
- func (s *Schema) GetParent() *JSONSchema[Referenceable]
- func (s *Schema) GetPattern() string
- func (s *Schema) GetPatternProperties() *sequencedmap.Map[string, *JSONSchema[Referenceable]]
- func (s *Schema) GetPrefixItems() []*JSONSchema[Referenceable]
- func (s *Schema) GetProperties() *sequencedmap.Map[string, *JSONSchema[Referenceable]]
- func (s *Schema) GetPropertyNames() *JSONSchema[Referenceable]
- func (s *Schema) GetReadOnly() bool
- func (s *Schema) GetRef() references.Reference
- func (s *Schema) GetRequired() []string
- func (s *Schema) GetSchema() string
- func (s *Schema) GetThen() *JSONSchema[Referenceable]
- func (s *Schema) GetTitle() string
- func (s *Schema) GetType() []SchemaType
- func (s *Schema) GetUnevaluatedItems() *JSONSchema[Referenceable]
- func (s *Schema) GetUnevaluatedProperties() *JSONSchema[Referenceable]
- func (s *Schema) GetUniqueItems() bool
- func (s *Schema) GetWriteOnly() bool
- func (s *Schema) GetXML() *XML
- func (s *Schema) IsEqual(other *Schema) bool
- func (s *Schema) IsReference() bool
- func (s *Schema) PopulateWithParent(source any, parent any) error
- func (s *Schema) SetParent(parent *JSONSchema[Referenceable])
- func (s *Schema) ShallowCopy() *Schema
- func (js *Schema) Validate(ctx context.Context, opts ...validation.Option) []error
- type SchemaMatchFunc
- type SchemaMatcher
- type SchemaType
- type SchemaWalkItem
- type Type
- type XML
- func (x *XML) GetAttribute() bool
- func (x *XML) GetExtensions() *extensions.Extensions
- func (x *XML) GetName() string
- func (x *XML) GetNamespace() string
- func (x *XML) GetPrefix() string
- func (x *XML) GetWrapped() bool
- func (x *XML) IsEqual(other *XML) bool
- func (x *XML) Validate(ctx context.Context, opts ...validation.Option) []error
Constants ¶
const ( JSONSchema31SchemaID = "https://spec.openapis.org/oas/3.1/dialect/base" JSONSchema30SchemaID = "https://spec.openapis.org/oas/3.0/dialect/2024-10-18" )
Variables ¶
var ( // ErrInlineTimeout is returned when the inline operation times out due to context cancellation or exceeds the maximum number of cycles ErrInlineTimeout = errors.New("inline operation timed out") )
Functions ¶
func Validate ¶
func Validate[T Referenceable | Concrete](ctx context.Context, schema *JSONSchema[T], opts ...validation.Option) []error
func Walk ¶
func Walk(ctx context.Context, schema *JSONSchemaReferenceable) iter.Seq[SchemaWalkItem]
Walk returns an iterator that yields SchemaMatchFunc items for each model in the JSON schema. Users can iterate over the results using a for loop and break out at any time.
func WalkExternalDocs ¶
func WalkExternalDocs(ctx context.Context, externalDocs *ExternalDocumentation) iter.Seq[SchemaWalkItem]
WalkExternalDocs returns an iterator that yields items for external documentation and its extensions.
Types ¶
type Discriminator ¶
type Discriminator struct { marshaller.Model[core.Discriminator] // PropertyName is the name of the property in the payload that will hold the discriminator value. PropertyName string // Mapping is an object to hold mappings between payload values and schema names or references. Mapping *sequencedmap.Map[string, string] // Extensions provides a list of extensions to the Discriminator object. Extensions *extensions.Extensions }
Discriminator is used to aid in serialization, deserialization, and validation of the oneOf, anyOf and allOf schemas.
func (*Discriminator) GetExtensions ¶
func (d *Discriminator) GetExtensions() *extensions.Extensions
GetExtensions returns the value of the Extensions field. Returns an empty extensions map if not set.
func (*Discriminator) GetMapping ¶
func (d *Discriminator) GetMapping() *sequencedmap.Map[string, string]
GetMapping returns the value of the Mapping field. Returns nil if not set.
func (*Discriminator) GetPropertyName ¶
func (d *Discriminator) GetPropertyName() string
GetPropertyName returns the value of the PropertyName field. Returns empty string if not set.
func (*Discriminator) IsEqual ¶
func (d *Discriminator) IsEqual(other *Discriminator) bool
IsEqual compares two Discriminator instances for equality.
func (*Discriminator) Validate ¶
func (d *Discriminator) Validate(ctx context.Context, opts ...validation.Option) []error
Validate will validate the Discriminator object according to the OpenAPI Specification.
type ExclusiveMaximum ¶
func NewExclusiveMaximumFromBool ¶
func NewExclusiveMaximumFromBool(value bool) ExclusiveMaximum
func NewExclusiveMaximumFromFloat64 ¶
func NewExclusiveMaximumFromFloat64(value float64) ExclusiveMaximum
type ExclusiveMinimum ¶
func NewExclusiveMinimumFromBool ¶
func NewExclusiveMinimumFromBool(value bool) ExclusiveMinimum
func NewExclusiveMinimumFromFloat64 ¶
func NewExclusiveMinimumFromFloat64(value float64) ExclusiveMinimum
type ExternalDocumentation ¶
type ExternalDocumentation struct { marshaller.Model[core.ExternalDocumentation] // Description is a description of the target documentation. May contain CommonMark syntax. Description *string // URL is the URL for the target documentation. URL string // Extensions provides a list of extensions to the ExternalDocumentation object. Extensions *extensions.Extensions }
ExternalDocumentation allows referencing external documentation for the associated object.
func (*ExternalDocumentation) GetDescription ¶
func (e *ExternalDocumentation) GetDescription() string
GetDescription returns the value of the Description field. Returns an empty string if not set.
func (*ExternalDocumentation) GetExtensions ¶
func (e *ExternalDocumentation) GetExtensions() *extensions.Extensions
GetExtensions returns the value of the Extensions field. Returns an empty extensions map if not set.
func (*ExternalDocumentation) GetURL ¶
func (e *ExternalDocumentation) GetURL() string
GetURL returns the value of the URL field. Returns an empty string if not set.
func (*ExternalDocumentation) IsEqual ¶
func (e *ExternalDocumentation) IsEqual(other *ExternalDocumentation) bool
IsEqual compares two ExternalDocumentation instances for equality.
func (*ExternalDocumentation) Validate ¶
func (e *ExternalDocumentation) Validate(ctx context.Context, opts ...validation.Option) []error
Validate will validate the ExternalDocumentation object according to the OpenAPI Specification.
type GetRootNoder ¶
type GetRootNoder interface {
GetRootNode() *yaml.Node
}
type InlineOptions ¶
type InlineOptions struct { // ResolveOptions are the options to use when resolving references during inlining. ResolveOptions ResolveOptions // RemoveUnusedDefs determines whether to remove $defs that are no longer referenced after inlining. RemoveUnusedDefs bool // MaxCycles sets the maximum number of analyzeReferences and inlineRecursive calls combined. // If 0, defaults to 5000000. Set to a higher value for complex schemas with many references. MaxCycles int64 }
InlineOptions represents the options available when inlining a JSON Schema.
type JSONSchema ¶
type JSONSchema[T Referenceable | Concrete] struct { values.EitherValue[Schema, core.Schema, bool, bool] // contains filtered or unexported fields }
func ConcreteToReferenceable ¶
func ConcreteToReferenceable(concrete *JSONSchema[Concrete]) *JSONSchema[Referenceable]
ConcreteToReferenceable converts a JSONSchema[Concrete] to JSONSchema[Referenceable] using unsafe pointer casting. This is safe because the underlying structure is identical, only the type parameter differs. This allows for efficient conversion without allocation when you need to walk a concrete schema as if it were a referenceable schema.
func Inline ¶
func Inline(ctx context.Context, schema *JSONSchema[Referenceable], opts InlineOptions) (*JSONSchema[Referenceable], error)
Inline transforms a JSON Schema by replacing all $ref references with their actual schema content, creating a self-contained schema that doesn't depend on external definitions.
Why use Inline?
- **Simplify schema distribution**: Create standalone schemas that can be shared without worrying about missing referenced files or definitions
- **AI and MCP integration**: Provide complete, self-contained schemas to AI systems and Model Context Protocol (MCP) servers that work better with fully expanded schemas
- **Improve tooling compatibility**: Some tools work better with fully expanded schemas rather than ones with references
- **Generate documentation**: Create complete schema representations for API documentation where all types are visible inline
- **Optimize for specific use cases**: Eliminate the need for reference resolution in performance-critical applications
- **Debug schema issues**: See the full expanded schema to understand how references resolve
What you'll get:
Before inlining:
{ "type": "object", "properties": { "user": {"$ref": "#/$defs/User"}, "address": {"$ref": "#/$defs/Address"} }, "$defs": { "User": {"type": "object", "properties": {"name": {"type": "string"}}}, "Address": {"type": "object", "properties": {"street": {"type": "string"}}} } }
After inlining:
{ "type": "object", "properties": { "user": {"type": "object", "properties": {"name": {"type": "string"}}}, "address": {"type": "object", "properties": {"street": {"type": "string"}}} } }
Handling Circular References:
The function intelligently handles circular references (schemas that reference themselves) by preserving them when they're safe to use. A circular reference is considered safe when there's an "escape route" that prevents infinite nesting:
✅ Safe circular reference (optional property):
{ "type": "object", "properties": { "name": {"type": "string"}, "parent": {"$ref": "#/$defs/Node"} // Optional - can be omitted }, "required": ["name"] // parent not required = escape route }
❌ Unsafe circular reference (required property):
{ "type": "object", "properties": { "name": {"type": "string"}, "parent": {"$ref": "#/$defs/Node"} // Required - creates infinite nesting }, "required": ["name", "parent"] // No escape route! }
When circular references are detected, they're preserved in the $defs section and references are rewritten to point to the consolidated definitions.
Example usage:
// Load a schema with references schema := &JSONSchema[Referenceable]{...} // Configure inlining opts := InlineOptions{ ResolveOptions: ResolveOptions{ RootLocation: "schema.json", RootDocument: schema, }, RemoveUnusedDefs: true, // Clean up unused definitions } // Inline all references result, err := Inline(ctx, schema, opts) if err != nil { return fmt.Errorf("failed to inline schema: %w", err) } // result is now a self-contained schema with all references expanded // Safe circular references are preserved in $defs // Unsafe circular references cause an error
Parameters:
- ctx: Context for the operation
- schema: The schema to inline
- opts: Configuration options for inlining
Returns:
- *JSONSchema[Referenceable]: The inlined schema (input schema left unmodified)
- error: Any error that occurred, including invalid circular reference errors
func NewJSONSchemaFromBool ¶
func NewJSONSchemaFromBool(value bool) *JSONSchema[Referenceable]
func NewJSONSchemaFromReference ¶
func NewJSONSchemaFromReference(ref references.Reference) *JSONSchema[Referenceable]
func NewJSONSchemaFromSchema ¶
func NewJSONSchemaFromSchema[T Referenceable | Concrete](value *Schema) *JSONSchema[T]
func NewReferencedScheme ¶
func NewReferencedScheme(ctx context.Context, ref references.Reference, resolvedSchema *JSONSchema[Concrete]) *JSONSchema[Referenceable]
NewReferencedScheme will create a new JSONSchema with the provided reference and and optional pre-resolved schema
func ReferenceableToConcrete ¶ added in v1.0.1
func ReferenceableToConcrete(referenceable *JSONSchema[Referenceable]) *JSONSchema[Concrete]
ReferenceableToConcrete converts a JSONSchema[Referenceable] to JSONSchema[Concrete] using unsafe pointer casting. This is safe because the underlying structure is identical, only the type parameter differs. This allows for efficient conversion without allocation when you need to walk a referenceable schema as if it were a concrete schema.
func (*JSONSchema[Referenceable]) GetAbsRef ¶
func (j *JSONSchema[Referenceable]) GetAbsRef() references.Reference
GetAbsRef returns the absolute reference of the JSONSchema if present, otherwise an empty string
func (*JSONSchema[Concrete]) GetExtensions ¶
func (j *JSONSchema[Concrete]) GetExtensions() *extensions.Extensions
func (*JSONSchema[T]) GetParent ¶
func (j *JSONSchema[T]) GetParent() *JSONSchema[Referenceable]
GetParent returns the immediate parent reference if this schema was resolved via a reference chain.
Returns nil if: - This schema was not resolved via a reference (accessed directly) - This schema is the top-level reference in a chain - The schema was accessed by iterating through document components rather than reference resolution
Example: main.yaml -> external.yaml#/User -> User schema The resolved User schema's GetParent() returns the external.yaml reference.
func (*JSONSchema[Referenceable]) GetRef ¶
func (j *JSONSchema[Referenceable]) GetRef() references.Reference
GetRef returns the reference of the JSONSchema if present, otherwise an empty string This method is identical to GetReference() but was kept for backwards compatibility
func (*JSONSchema[Referenceable]) GetReference ¶ added in v1.7.1
func (j *JSONSchema[Referenceable]) GetReference() references.Reference
GetReference returns the reference of the JSONSchema if present, otherwise an empty string This method is identical to GetRef() but was added to support the Resolvable interface
func (*JSONSchema[Referenceable]) GetReferenceResolutionInfo ¶ added in v1.6.0
func (r *JSONSchema[Referenceable]) GetReferenceResolutionInfo() *references.ResolveResult[JSONSchemaReferenceable]
func (*JSONSchema[Referenceable]) GetResolvedObject ¶ added in v1.6.2
func (s *JSONSchema[Referenceable]) GetResolvedObject() *JSONSchema[Concrete]
GetResolvedObject will return either this schema or the referenced schema if previously resolved. This methods is identical to GetResolvedSchema but was added to support the Resolvable interface
func (*JSONSchema[Referenceable]) GetResolvedSchema ¶
func (s *JSONSchema[Referenceable]) GetResolvedSchema() *JSONSchema[Concrete]
GetResolvedSchema will return either this schema or the referenced schema if previously resolved. This methods is identical to GetResolvedObject but was kept for backwards compatibility
func (*JSONSchema[T]) GetTopLevelParent ¶
func (j *JSONSchema[T]) GetTopLevelParent() *JSONSchema[Referenceable]
GetTopLevelParent returns the top-level parent reference if this schema was resolved via a reference chain.
Returns nil if: - This schema was not resolved via a reference (accessed directly) - This schema is already the top-level reference - The schema was accessed by iterating through document components rather than reference resolution
Example: main.yaml -> external.yaml#/User -> chained.yaml#/User -> final User schema The final User schema's GetTopLevelParent() returns the original main.yaml reference.
func (*JSONSchema[T]) IsEqual ¶
func (j *JSONSchema[T]) IsEqual(other *JSONSchema[T]) bool
IsEqual compares two JSONSchema instances for equality.
func (*JSONSchema[Referenceable]) IsReference ¶
func (j *JSONSchema[Referenceable]) IsReference() bool
IsReference returns true if the JSONSchema is a reference, false otherwise
func (*JSONSchema[Referenceable]) IsResolved ¶
func (s *JSONSchema[Referenceable]) IsResolved() bool
func (*JSONSchema[Referenceable]) MustGetResolvedSchema ¶
func (s *JSONSchema[Referenceable]) MustGetResolvedSchema() *JSONSchema[Concrete]
MustGetResolvedSchema will return the resolved schema. If this is a reference and its unresolved, this will panic. Useful if references have been resolved before hand.
func (*JSONSchema[T]) PopulateWithParent ¶ added in v1.4.0
func (j *JSONSchema[T]) PopulateWithParent(source any, parent any) error
PopulateWithParent implements the ParentAwarePopulator interface to establish parent relationships during population
func (*JSONSchema[Referenceable]) Resolve ¶
func (s *JSONSchema[Referenceable]) Resolve(ctx context.Context, opts ResolveOptions) ([]error, error)
Resolve will fully resolve the reference and return the JSONSchema referenced. This will recursively resolve any intermediate references as well. Validation errors can be skipped by setting the skipValidation flag to true. This will skip the missing field errors that occur during unmarshaling. Resolution doesn't run the Validate function on the resolved object. So if you want to fully validate the object after resolution, you need to call the Validate function manually.
func (*JSONSchema[T]) SetParent ¶
func (j *JSONSchema[T]) SetParent(parent *JSONSchema[Referenceable])
SetParent sets the immediate parent reference for this schema. This is a public API for manually constructing reference chains.
Use this when you need to manually establish parent-child relationships between references, typically when creating reference chains programmatically rather than through the normal resolution process.
func (*JSONSchema[T]) SetTopLevelParent ¶
func (j *JSONSchema[T]) SetTopLevelParent(topLevelParent *JSONSchema[Referenceable])
SetTopLevelParent sets the top-level parent reference for this schema. This is a public API for manually constructing reference chains.
Use this when you need to manually establish the root of a reference chain, typically when creating reference chains programmatically rather than through the normal resolution process.
func (*JSONSchema[T]) ShallowCopy ¶ added in v1.0.1
func (j *JSONSchema[T]) ShallowCopy() *JSONSchema[T]
ShallowCopy creates a shallow copy of the JSONSchema.
func (*JSONSchema[T]) Validate ¶
func (j *JSONSchema[T]) Validate(ctx context.Context, opts ...validation.Option) []error
Validate validates the JSONSchema against the JSON Schema specification. This is a wrapper around calling GetLeft().Validate() for schema objects.
type JSONSchemaReferenceable ¶
type JSONSchemaReferenceable = JSONSchema[Referenceable]
type ParentDocumentVersion ¶ added in v1.7.2
type Referenceable ¶
type Referenceable interface{}
type ResolveOptions ¶
type ResolveOptions = references.ResolveOptions
ResolveOptions represent the options available when resolving a JSON Schema reference.
type Schema ¶
type Schema struct { marshaller.Model[core.Schema] Ref *references.Reference ExclusiveMaximum ExclusiveMaximum ExclusiveMinimum ExclusiveMinimum // Type represents the type of a schema either an array of types or a single type. Type Type AllOf []*JSONSchema[Referenceable] OneOf []*JSONSchema[Referenceable] AnyOf []*JSONSchema[Referenceable] Discriminator *Discriminator Examples []values.Value PrefixItems []*JSONSchema[Referenceable] Contains *JSONSchema[Referenceable] MinContains *int64 MaxContains *int64 If *JSONSchema[Referenceable] Else *JSONSchema[Referenceable] Then *JSONSchema[Referenceable] DependentSchemas *sequencedmap.Map[string, *JSONSchema[Referenceable]] PatternProperties *sequencedmap.Map[string, *JSONSchema[Referenceable]] PropertyNames *JSONSchema[Referenceable] UnevaluatedItems *JSONSchema[Referenceable] UnevaluatedProperties *JSONSchema[Referenceable] Items *JSONSchema[Referenceable] Anchor *string Not *JSONSchema[Referenceable] Properties *sequencedmap.Map[string, *JSONSchema[Referenceable]] Defs *sequencedmap.Map[string, *JSONSchema[Referenceable]] Title *string MultipleOf *float64 Maximum *float64 Minimum *float64 MaxLength *int64 MinLength *int64 Pattern *string Format *string MaxItems *int64 MinItems *int64 UniqueItems *bool MaxProperties *int64 MinProperties *int64 Required []string Enum []values.Value AdditionalProperties *JSONSchema[Referenceable] Description *string Default values.Value Const values.Value Nullable *bool ReadOnly *bool WriteOnly *bool ExternalDocs *ExternalDocumentation Example values.Value Deprecated *bool Schema *string XML *XML Extensions *extensions.Extensions // contains filtered or unexported fields }
func (*Schema) GetAdditionalProperties ¶
func (s *Schema) GetAdditionalProperties() *JSONSchema[Referenceable]
GetAdditionalProperties returns the value of the AdditionalProperties field. Returns nil if not set.
func (*Schema) GetAllOf ¶
func (s *Schema) GetAllOf() []*JSONSchema[Referenceable]
GetAllOf returns the value of the AllOf field. Returns nil if not set.
func (*Schema) GetAnchor ¶
GetAnchor returns the value of the Anchor field. Returns empty string if not set.
func (*Schema) GetAnyOf ¶
func (s *Schema) GetAnyOf() []*JSONSchema[Referenceable]
GetAnyOf returns the value of the AnyOf field. Returns nil if not set.
func (*Schema) GetContains ¶
func (s *Schema) GetContains() *JSONSchema[Referenceable]
GetContains returns the value of the Contains field. Returns nil if not set.
func (*Schema) GetDefault ¶
GetDefault returns the value of the Default field. Returns nil if not set.
func (*Schema) GetDefs ¶
func (s *Schema) GetDefs() *sequencedmap.Map[string, *JSONSchema[Referenceable]]
GetDefs returns the value of the Defs field. Returns nil if not set.
func (*Schema) GetDependentSchemas ¶
func (s *Schema) GetDependentSchemas() *sequencedmap.Map[string, *JSONSchema[Referenceable]]
GetDependentSchemas returns the value of the DependentSchemas field. Returns nil if not set.
func (*Schema) GetDeprecated ¶
GetDeprecated returns the value of the Deprecated field. Returns false if not set.
func (*Schema) GetDescription ¶
GetDescription returns the value of the Description field. Returns empty string if not set.
func (*Schema) GetDiscriminator ¶
func (s *Schema) GetDiscriminator() *Discriminator
GetDiscriminator returns the value of the Discriminator field. Returns nil if not set.
func (*Schema) GetElse ¶
func (s *Schema) GetElse() *JSONSchema[Referenceable]
GetElse returns the value of the Else field. Returns nil if not set.
func (*Schema) GetExample ¶
GetExample returns the value of the Example field. Returns nil if not set.
func (*Schema) GetExamples ¶
GetExamples returns the value of the Examples field. Returns nil if not set.
func (*Schema) GetExclusiveMaximum ¶
func (s *Schema) GetExclusiveMaximum() ExclusiveMaximum
GetExclusiveMaximum returns the value of the ExclusiveMaximum field. Returns nil if not set.
func (*Schema) GetExclusiveMinimum ¶
func (s *Schema) GetExclusiveMinimum() ExclusiveMinimum
GetExclusiveMinimum returns the value of the ExclusiveMinimum field. Returns nil if not set.
func (*Schema) GetExtensions ¶
func (s *Schema) GetExtensions() *extensions.Extensions
GetExtensions returns the value of the Extensions field. Returns an empty extensions map if not set.
func (*Schema) GetExternalDocs ¶
func (s *Schema) GetExternalDocs() *ExternalDocumentation
GetExternalDocs returns the value of the ExternalDocs field. Returns nil if not set.
func (*Schema) GetFormat ¶
GetFormat returns the value of the Format field. Returns empty string if not set.
func (*Schema) GetIf ¶
func (s *Schema) GetIf() *JSONSchema[Referenceable]
GetIf returns the value of the If field. Returns nil if not set.
func (*Schema) GetItems ¶
func (s *Schema) GetItems() *JSONSchema[Referenceable]
GetItems returns the value of the Items field. Returns nil if not set.
func (*Schema) GetMaxContains ¶
GetMaxContains returns the value of the MaxContains field. Returns nil if not set.
func (*Schema) GetMaxItems ¶
GetMaxItems returns the value of the MaxItems field. Returns nil if not set.
func (*Schema) GetMaxLength ¶
GetMaxLength returns the value of the MaxLength field. Returns nil if not set.
func (*Schema) GetMaxProperties ¶
GetMaxProperties returns the value of the MaxProperties field. Returns nil if not set.
func (*Schema) GetMaximum ¶
GetMaximum returns the value of the Maximum field. Returns nil if not set.
func (*Schema) GetMinContains ¶
GetMinContains returns the value of the MinContains field. Returns nil if not set.
func (*Schema) GetMinItems ¶
GetMinItems returns the value of the MinItems field. Returns 0 if not set.
func (*Schema) GetMinLength ¶
GetMinLength returns the value of the MinLength field. Returns nil if not set.
func (*Schema) GetMinProperties ¶
GetMinProperties returns the value of the MinProperties field. Returns nil if not set.
func (*Schema) GetMinimum ¶
GetMinimum returns the value of the Minimum field. Returns nil if not set.
func (*Schema) GetMultipleOf ¶
GetMultipleOf returns the value of the MultipleOf field. Returns nil if not set.
func (*Schema) GetNot ¶
func (s *Schema) GetNot() *JSONSchema[Referenceable]
GetNot returns the value of the Not field. Returns nil if not set.
func (*Schema) GetNullable ¶
GetNullable returns the value of the Nullable field. Returns false if not set.
func (*Schema) GetOneOf ¶
func (s *Schema) GetOneOf() []*JSONSchema[Referenceable]
GetOneOf returns the value of the OneOf field. Returns nil if not set.
func (*Schema) GetParent ¶ added in v1.4.0
func (s *Schema) GetParent() *JSONSchema[Referenceable]
GetParent returns the immediate parent JSONSchema if this schema was populated as a child of another schema. Returns nil if this schema has no parent or was not populated via parent-aware population.
func (*Schema) GetPattern ¶
GetPattern returns the value of the Pattern field. Returns empty string if not set.
func (*Schema) GetPatternProperties ¶
func (s *Schema) GetPatternProperties() *sequencedmap.Map[string, *JSONSchema[Referenceable]]
GetPatternProperties returns the value of the PatternProperties field. Returns nil if not set.
func (*Schema) GetPrefixItems ¶
func (s *Schema) GetPrefixItems() []*JSONSchema[Referenceable]
GetPrefixItems returns the value of the PrefixItems field. Returns nil if not set.
func (*Schema) GetProperties ¶
func (s *Schema) GetProperties() *sequencedmap.Map[string, *JSONSchema[Referenceable]]
GetProperties returns the value of the Properties field. Returns nil if not set.
func (*Schema) GetPropertyNames ¶
func (s *Schema) GetPropertyNames() *JSONSchema[Referenceable]
GetPropertyNames returns the value of the PropertyNames field. Returns nil if not set.
func (*Schema) GetReadOnly ¶
GetReadOnly returns the value of the ReadOnly field. Returns false if not set.
func (*Schema) GetRef ¶
func (s *Schema) GetRef() references.Reference
GetRef returns the value of the Ref field. Returns empty string if not set.
func (*Schema) GetRequired ¶
GetRequired returns the value of the Required field. Returns nil if not set.
func (*Schema) GetSchema ¶
GetSchema returns the value of the Schema field. Returns empty string if not set.
func (*Schema) GetThen ¶
func (s *Schema) GetThen() *JSONSchema[Referenceable]
GetThen returns the value of the Then field. Returns nil if not set.
func (*Schema) GetTitle ¶
GetTitle returns the value of the Title field. Returns empty string if not set.
func (*Schema) GetType ¶
func (s *Schema) GetType() []SchemaType
GetType will resolve the type of the schema to an array of the types represented by this schema.
func (*Schema) GetUnevaluatedItems ¶
func (s *Schema) GetUnevaluatedItems() *JSONSchema[Referenceable]
GetUnevaluatedItems returns the value of the UnevaluatedItems field. Returns nil if not set.
func (*Schema) GetUnevaluatedProperties ¶
func (s *Schema) GetUnevaluatedProperties() *JSONSchema[Referenceable]
GetUnevaluatedProperties returns the value of the UnevaluatedProperties field. Returns nil if not set.
func (*Schema) GetUniqueItems ¶
GetUniqueItems returns the value of the UniqueItems field. Returns false if not set.
func (*Schema) GetWriteOnly ¶
GetWriteOnly returns the value of the WriteOnly field. Returns false if not set.
func (*Schema) IsEqual ¶
IsEqual compares two Schema instances for equality. It performs a deep comparison of all fields, using IsEqual methods on custom types where available.
func (*Schema) IsReference ¶
IsReference returns true if the schema is a reference (via $ref) to another schema.
func (*Schema) PopulateWithParent ¶ added in v1.4.0
PopulateWithParent implements the ParentAwarePopulator interface to establish parent relationships during population
func (*Schema) SetParent ¶ added in v1.4.0
func (s *Schema) SetParent(parent *JSONSchema[Referenceable])
SetParent sets the immediate parent JSONSchema for this schema. This is used during parent-aware population to establish parent relationships.
func (*Schema) ShallowCopy ¶ added in v1.0.1
ShallowCopy creates a shallow copy of the Schema. This copies all struct fields and creates new slices/maps but does not deep copy the referenced objects. The elements within slices and maps are copied by reference, not deep copied.
type SchemaMatchFunc ¶
type SchemaMatchFunc func(SchemaMatcher) error
SchemaMatchFunc represents a particular model in the JSON schema that can be matched. Pass it a SchemaMatcher with the appropriate functions populated to match the model type(s) you are interested in.
type SchemaMatcher ¶
type SchemaMatcher struct { Schema func(*JSONSchemaReferenceable) error Discriminator func(*Discriminator) error XML func(*XML) error ExternalDocs func(*ExternalDocumentation) error Extensions func(*extensions.Extensions) error Any func(any) error // Any will be called along with the other functions above on a match of a model }
SchemaMatcher is a struct that can be used to match specific nodes in the JSON schema.
type SchemaType ¶
type SchemaType string
const ( SchemaTypeArray SchemaType = "array" SchemaTypeBoolean SchemaType = "boolean" SchemaTypeInteger SchemaType = "integer" SchemaTypeNumber SchemaType = "number" SchemaTypeNull SchemaType = "null" SchemaTypeObject SchemaType = "object" SchemaTypeString SchemaType = "string" )
type SchemaWalkItem ¶
type SchemaWalkItem struct { Match SchemaMatchFunc Location walk.Locations[SchemaMatchFunc] Schema *JSONSchemaReferenceable // The root schema being walked }
SchemaWalkItem represents a single item yielded by the WalkSchema iterator.
type Type ¶
type Type = *values.EitherValue[[]SchemaType, []marshaller.Node[string], SchemaType, string]
Type represents the type of a schema either an array of types or a single type.
func NewTypeFromArray ¶
func NewTypeFromArray(value []SchemaType) Type
func NewTypeFromString ¶
func NewTypeFromString(value SchemaType) Type
type XML ¶
type XML struct { marshaller.Model[core.XML] // Name replaces the name of the element/attribute used for the described schema property. Name *string // Namespace defines a URI of the namespace definition. Value MUST be in the form of an absolute URI. Namespace *string // Prefix to be used for the name. Prefix *string // Attribute determines whether the property definition creates an attribute. Attribute *bool // Wrapped determines whether the property definition is wrapped. Wrapped *bool // Extensions provides a list of extensions to the XML object. Extensions *extensions.Extensions }
XML represents the metadata of a schema describing a XML element.
func (*XML) GetAttribute ¶
GetAttribute returns the value of the Attribute field. Returns empty string if not set.
func (*XML) GetExtensions ¶
func (x *XML) GetExtensions() *extensions.Extensions
GetExtensions returns the value of the Extensions field. Returns an empty extensions map if not set.
func (*XML) GetNamespace ¶
GetNamespace returns the value of the Namespace field. Returns empty string if not set.
func (*XML) GetPrefix ¶
GetPrefix returns the value of the Prefix field. Returns empty string if not set.
func (*XML) GetWrapped ¶
GetWrapped returns the value of the Wrapped field. Returns empty string if not set.