schema

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyDefaults

func ApplyDefaults(target map[string]any, structural *apiextschema.Structural) map[string]any

ApplyDefaults applies schema default values to a target object using Kubernetes defaulting logic.

This function walks the structural schema and target object in parallel, filling in default values for missing fields. The defaulting algorithm follows the same rules as Kubernetes API server defaulting for CustomResourceDefinitions.

Behavior:

  • Missing fields with defaults are added
  • Existing fields are not overwritten (even if they differ from the default)
  • Nested objects are defaulted recursively

The target map is modified in place and also returned for convenience.

Example:

Schema: {replicas: {type: "integer", default: 1}, image: {type: "string"}}
Input:  {image: "nginx"}
Output: {image: "nginx", replicas: 1}

func OpenAPIV3ToJSONSchema added in v1.0.0

func OpenAPIV3ToJSONSchema(rawSchema map[string]any) (*extv1.JSONSchemaProps, error)

OpenAPIV3ToJSONSchema resolves $refs and converts an openAPIV3Schema to v1 JSONSchemaProps for API responses. Note: arbitrary vendor extensions (x-*) are NOT preserved because extv1.JSONSchemaProps does not support them. Use OpenAPIV3ToResolvedSchema for API responses that need vendor extensions.

func OpenAPIV3ToResolvedSchema added in v1.0.0

func OpenAPIV3ToResolvedSchema(rawSchema map[string]any) (map[string]any, error)

OpenAPIV3ToResolvedSchema resolves $refs and removes $defs, returning the resolved schema as a raw map. Unlike OpenAPIV3ToJSONSchema, this preserves all vendor extensions (x-*) since it does not convert through extv1.JSONSchemaProps. Use this for API responses where vendor extensions must be returned to the frontend.

func OpenAPIV3ToStructural added in v1.0.0

func OpenAPIV3ToStructural(rawSchema map[string]any) (*apiextschema.Structural, error)

OpenAPIV3ToStructural resolves $refs and converts an openAPIV3Schema to a Kubernetes structural schema. Used by webhooks and pipeline for validation and defaulting.

func OpenAPIV3ToStructuralAndJSONSchema added in v1.0.0

func OpenAPIV3ToStructuralAndJSONSchema(rawSchema map[string]any) (*apiextschema.Structural, *extv1.JSONSchemaProps, error)

OpenAPIV3ToStructuralAndJSONSchema returns both structural and JSON schema formats from an openAPIV3Schema in one pass. Used by pipeline context (BuildStructuralSchemas).

func ResolveRefs added in v1.0.0

func ResolveRefs(schema map[string]any) (map[string]any, error)

ResolveRefs inlines all $ref references in a JSON Schema so that downstream code never sees $ref. Supports both $defs (JSON Schema 2020-12) and definitions (Draft 4/7). Circular references and remote refs are rejected with descriptive errors. The input is not mutated; a deep copy is returned. Only $defs (JSON Schema 2020-12) is supported; the older "definitions" keyword is not.

func ResolveSectionToBundle added in v1.0.0

func ResolveSectionToBundle(section *v1alpha1.SchemaSection) (*apiextschema.Structural, *extv1.JSONSchemaProps, error)

ResolveSectionToBundle converts a SchemaSection into both structural and JSON schema formats. Returns nil for both if the section is nil or empty.

func ResolveSectionToStructural added in v1.0.0

func ResolveSectionToStructural(section *v1alpha1.SchemaSection) (*apiextschema.Structural, error)

ResolveSectionToStructural converts a SchemaSection into a Kubernetes structural schema. Returns nil if the section is nil or empty.

func SectionToJSONSchema added in v1.0.0

func SectionToJSONSchema(section *v1alpha1.SchemaSection) (*extv1.JSONSchemaProps, error)

SectionToJSONSchema converts a SchemaSection to JSON Schema for API responses.

func SectionToRawJSONSchema added in v1.0.0

func SectionToRawJSONSchema(section *v1alpha1.SchemaSection) (map[string]any, error)

SectionToRawJSONSchema converts a SchemaSection to a raw map for API responses. This preserves vendor extensions (x-*) that are lost when converting through extv1.JSONSchemaProps.

func StripVendorExtensions added in v1.0.0

func StripVendorExtensions(schema map[string]any) map[string]any

StripVendorExtensions recursively removes vendor extension keys (x-*) from a schema tree, but preserves x-kubernetes-* keys which are supported by Kubernetes structural schemas.

func ValidateWithJSONSchema added in v0.6.0

func ValidateWithJSONSchema(values map[string]any, jsonSchema *extv1.JSONSchemaProps) error

ValidateWithJSONSchema validates values against a JSONSchemaProps using Kubernetes validation. This properly validates required fields, types, constraints, patterns, and all other JSON Schema validations.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL