Documentation
¶
Overview ¶
Package schema derives a strict JSON Schema for the values artifact of one frozen graph.
Generation is pure with respect to the filesystem and network. Element descriptor ConfigSchema strings are opaque contract references: the package never guesses configuration fields from them. Callers that own the actual schema documents may provide a Resolver. Otherwise the generated schema is an honest, incomplete envelope and node-index schema.
Index ¶
Constants ¶
const Draft202012 = "https://json-schema.org/draft/2020-12/schema"
Variables ¶
var ( // ErrSchemaNotFound is returned by a Resolver when it has no document for // an opaque descriptor reference. It is non-fatal unless RequireResolved // is enabled. ErrSchemaNotFound = errors.New("config schema not found") ErrUnknownDescriptor = errors.New("unknown exact element descriptor") ErrDescriptorContractMismatch = errors.New("graph IR and descriptor contract mismatch") ErrUnknownConfigContract = errors.New("config schema contract is unresolved") ErrInvalidResolvedSchema = errors.New("invalid resolved config schema") ErrInvalidSchemaID = errors.New("invalid schema ID") ErrSchemaIDCollision = errors.New("schema ID collision") ErrLimitExceeded = errors.New("schema generation limit exceeded") ErrInvalidOptions = errors.New("invalid schema generation options") )
Functions ¶
This section is empty.
Types ¶
type Bundle ¶
type Bundle struct {
Schema json.RawMessage `json:"schema"`
Digest string `json:"digest"`
Complete bool `json:"complete"`
Nodes []NodeContract `json:"nodes"`
Contracts []ContractResolution `json:"contracts"`
Unresolved []string `json:"unresolved"`
}
Bundle is an immutable generation result. Schema is deterministic, newline-terminated JSON; Digest is its sha256 content identity. Complete is false exactly when at least one opaque config reference was unresolved.
type ContractResolution ¶
type ContractResolution struct {
Reference string `json:"reference"`
Status ContractStatus `json:"status"`
SchemaID string `json:"schema_id,omitempty"`
Definition string `json:"definition,omitempty"`
NodeIDs []string `json:"node_ids"`
}
ContractResolution reports one distinct, non-empty descriptor ConfigSchema reference and every graph node that uses it.
type ContractStatus ¶
type ContractStatus string
ContractStatus describes how a node's configuration contract is modeled.
const ( ContractEmptyObject ContractStatus = "empty-object-only" ContractResolved ContractStatus = "resolved" ContractUnresolved ContractStatus = "unresolved" )
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator owns one exact descriptor and schema snapshot. It is read-only after New and safe for concurrent Bundle calls.
type Limits ¶
type Limits struct {
MaxGraphNodes int
MaxGraphEdges int
MaxGraphBoundaries int
MaxGraphScopes int
MaxGraphPorts int
MaxGraphBytes int
MaxTypeDepth int
MaxDistinctDescriptors int
MaxDescriptorBytes int
MaxTotalDescriptorBytes int
MaxConfigContracts int
MaxResolvedSchemas int
MaxResolvedSchemaBytes int
MaxTotalResolvedSchemaBytes int
MaxSchemaDepth int
MaxSchemaValues int
MaxStringBytes int
MaxGeneratedSchemaBytes int
}
Limits bounds attacker-controlled graph, descriptor, resolver, and output work. Zero fields use DefaultLimits; negative fields are invalid.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits returns a fresh copy of the production defaults. There is no exported mutable default value.
type NodeContract ¶
type NodeContract struct {
NodeID string `json:"node_id"`
Element element.Identity `json:"element"`
ConfigReference string `json:"config_reference,omitempty"`
Status ContractStatus `json:"status"`
SchemaID string `json:"schema_id,omitempty"`
Definition string `json:"definition,omitempty"`
}
NodeContract is the immutable, deterministic node index represented by the generated values schema.
type Options ¶
type Options struct {
// SchemaID is the absolute ID of the generated values schema. An empty ID
// derives a stable URN from the frozen graph fingerprint.
SchemaID string
Resolver Resolver
// RequireResolved changes an honest unresolved contract report into an
// error. It is useful for release/deployment gates.
RequireResolved bool
Limits Limits
}
Options controls one immutable generation snapshot.
type PropertyMetadata ¶
type PropertyMetadata struct {
Name string `json:"name"`
Pointer string `json:"pointer"`
Required bool `json:"required,omitempty"`
Types []string `json:"types,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Format string `json:"format,omitempty"`
Default json.RawMessage `json:"default,omitempty"`
Enum []json.RawMessage `json:"enum,omitempty"`
Schema json.RawMessage `json:"schema"`
}
PropertyMetadata is a deterministic, renderer-neutral view of one directly declared root configuration property. Schema retains the exact canonical subschema so a future renderer need not rely on this convenience projection.
type PropertyOptions ¶
PropertyOptions bounds one schema resolution and metadata projection.
type PropertyReport ¶
type PropertyReport struct {
Reference string `json:"reference"`
SchemaID string `json:"schema_id"`
Digest string `json:"digest"`
SchemaBytes int `json:"schema_bytes"`
Complete bool `json:"complete"`
Properties []PropertyMetadata `json:"properties"`
AdditionalProperties json.RawMessage `json:"additional_properties,omitempty"`
}
PropertyReport is one immutable resolved schema snapshot. Complete is false when object properties are selected through composition or a root $ref; in that case Properties remains an honest list of only directly declared fields and consumers must not treat it as a complete form model.
func ResolvePropertyMetadata ¶
func ResolvePropertyMetadata( ctx context.Context, reference string, options PropertyOptions, ) (PropertyReport, error)
ResolvePropertyMetadata resolves and fully validates one self-contained Draft 2020-12 config schema before returning any field metadata. It performs no fallback I/O and never follows a non-local reference.
type ResolvedSchema ¶
type ResolvedSchema struct {
ID string `json:"id"`
Document json.RawMessage `json:"document"`
}
ResolvedSchema is one self-contained Draft 2020-12 schema resource. ID must be an absolute canonical URI without a fragment. The generator copies Document as soon as ResolveConfigSchema returns.
type Resolver ¶
type Resolver interface {
ResolveConfigSchema(ctx context.Context, reference string) (ResolvedSchema, error)
}
Resolver supplies the actual JSON Schema behind an opaque descriptor ConfigSchema reference. Implementations should honor ctx. The generator never performs fallback I/O or external reference resolution.