Documentation
¶
Overview ¶
Package jsonschema provides functionality for managing JSON Schema documents.
This package implements various strategies for generating JSON Schemas from different sources.
It also provides utilities for converting:
- Go structs to JSON Schemas.
- JSON Schemas to KCL Schemas.
Index ¶
- Constants
- Variables
- func ConvertToKCLCompatibleJSONSchema(jsonSchemaData []byte) ([]byte, error)
- func ConvertToKCLSchema(jsonSchemaData []byte, removeDefaults bool) ([]byte, error)
- func GetFileFilter(t GeneratorType) func(string) bool
- type AutoGenerator
- type FileGenerator
- type GenOpt
- type GeneratorType
- type NoGenerator
- type PropertyOpt
- type ReaderGenerator
- func (g *ReaderGenerator) FromData(data []byte, refBasePath string) ([]byte, error)
- func (g *ReaderGenerator) FromFile(path string) ([]byte, error)
- func (g *ReaderGenerator) FromPaths(paths ...string) ([]byte, error)
- func (g *ReaderGenerator) FromReader(r io.Reader, refBasePath string) ([]byte, error)
- func (g *ReaderGenerator) FromURL(schemaURL *url.URL) ([]byte, error)
- type Reflected
- type Reflector
- type ValidatorType
- type ValueInferenceConfig
- type ValueInferenceGenerator
Constants ¶
const ( DefaultGeneratorType GeneratorType = "" AutoGeneratorType GeneratorType = "AUTO" ValueInferenceGeneratorType GeneratorType = "VALUE-INFERENCE" URLGeneratorType GeneratorType = "URL" ChartPathGeneratorType GeneratorType = "CHART-PATH" LocalPathGeneratorType GeneratorType = "LOCAL-PATH" NoGeneratorType GeneratorType = "NONE" DefaultValidatorType ValidatorType = "" KCLValidatorType ValidatorType = "KCL" HelmValidatorType ValidatorType = "HELM" )
const EmptySchema string = `` /* 128-byte string literal not displayed */
Variables ¶
var ( GeneratorTypeEnum = []any{ AutoGeneratorType, ValueInferenceGeneratorType, URLGeneratorType, ChartPathGeneratorType, LocalPathGeneratorType, NoGeneratorType, } ValidatorTypeEnum = []any{ KCLValidatorType, HelmValidatorType, } )
var (
DefaultAutoGenerator = NewAutoGenerator()
)
var (
DefaultNoGenerator = NewNoGenerator()
)
var ( // DefaultReaderGenerator is an opinionated [ReaderGenerator]. DefaultReaderGenerator = NewReaderGenerator() )
var ( // DefaultValueInferenceGenerator is an opinionated [ValueInferenceGenerator]. DefaultValueInferenceGenerator = NewValueInferenceGenerator(&ValueInferenceConfig{ SkipRequired: true, }) )
Functions ¶
func ConvertToKCLCompatibleJSONSchema ¶
ConvertToKCLCompatibleJSONSchema converts a JSON schema to a JSON schema that is compatible with KCL schema generation (i.e. removing unsupported fields).
func ConvertToKCLSchema ¶
ConvertToKCLSchema converts a JSON schema to a KCL schema.
func GetFileFilter ¶
func GetFileFilter(t GeneratorType) func(string) bool
Types ¶
type AutoGenerator ¶
type AutoGenerator struct{}
func NewAutoGenerator ¶
func NewAutoGenerator() *AutoGenerator
type FileGenerator ¶
type GeneratorType ¶
type GeneratorType string
func GetGeneratorType ¶
func GetGeneratorType(t string) GeneratorType
type NoGenerator ¶
type NoGenerator struct{}
NoGenerator always returns an empty JSON Schema.
type PropertyOpt ¶
type PropertyOpt func(*invopopjsonschema.Schema)
func WithAllowAdditionalProperties ¶
func WithAllowAdditionalProperties() PropertyOpt
func WithDefault ¶
func WithDefault(defaultValue any) PropertyOpt
func WithEnum ¶
func WithEnum(enum []any) PropertyOpt
func WithNoContent ¶
func WithNoContent() PropertyOpt
func WithType ¶
func WithType(t string) PropertyOpt
type ReaderGenerator ¶
type ReaderGenerator struct{}
ReaderGenerator reads a JSON Schema from a given location and returns corresponding []byte representations.
func NewReaderGenerator ¶
func NewReaderGenerator() *ReaderGenerator
NewReaderGenerator creates a new ReaderGenerator.
func (*ReaderGenerator) FromData ¶
func (g *ReaderGenerator) FromData(data []byte, refBasePath string) ([]byte, error)
func (*ReaderGenerator) FromPaths ¶
func (g *ReaderGenerator) FromPaths(paths ...string) ([]byte, error)
FromPaths reads a JSON Schema from at least one of the given file paths or URLs and returns the corresponding []byte representation. It will return an error only if none of the paths provide a valid JSON Schema.
func (*ReaderGenerator) FromReader ¶
type Reflected ¶
type Reflected struct {
Schema *invopopjsonschema.Schema
// contains filtered or unexported fields
}
func (*Reflected) RemoveProperty ¶
func (*Reflected) SetOrRemoveProperty ¶
func (r *Reflected) SetOrRemoveProperty(key string, setProperty bool, opts ...PropertyOpt)
func (*Reflected) SetProperty ¶
func (r *Reflected) SetProperty(key string, opts ...PropertyOpt)
type Reflector ¶
type Reflector struct {
Reflector *invopopjsonschema.Reflector
}
func NewReflector ¶
func NewReflector() *Reflector
func (*Reflector) AddGoComments ¶
type ValidatorType ¶
type ValidatorType string
func GetValidatorType ¶
func GetValidatorType(t string) ValidatorType
type ValueInferenceConfig ¶
type ValueInferenceConfig struct {
// Consider yaml which is commented out.
UncommentYAMLBlocks bool `json:"uncommentYAMLBlocks,omitempty"`
// Parse and use helm-docs comments.
HelmDocsCompatibilityMode bool `json:"helmDocsCompatibilityMode,omitempty"`
// Keep the helm-docs prefix (--) in the schema.
KeepHelmDocsPrefix bool `json:"keepHelmDocsPrefix,omitempty"`
// Keep the whole leading comment (default: cut at empty line).
KeepFullComment bool `json:"keepFullComment,omitempty"`
// Remove the global key from the schema.
RemoveGlobal bool `json:"removeGlobal,omitempty"`
// Skip auto-generation of Title.
SkipTitle bool `json:"skipTitle,omitempty"`
// Skip auto-generation of Description.
SkipDescription bool `json:"skipDescription,omitempty"`
// Skip auto-generation of Required.
SkipRequired bool `json:"skipRequired,omitempty"`
// Skip auto-generation of Default.
SkipDefault bool `json:"skipDefault,omitempty"`
// Skip auto-generation of AdditionalProperties.
SkipAdditionalProperties bool `json:"skipAdditionalProperties,omitempty"`
}
type ValueInferenceGenerator ¶
type ValueInferenceGenerator struct {
// contains filtered or unexported fields
}
ValueInferenceGenerator is a generator that infers a JSON Schema from one or more Helm values files.
func NewValueInferenceGenerator ¶
func NewValueInferenceGenerator(c *ValueInferenceConfig) *ValueInferenceGenerator
NewValueInferenceGenerator creates a new ValueInferenceGenerator using the given ValueInferenceConfig.
func (*ValueInferenceGenerator) FromData ¶
func (g *ValueInferenceGenerator) FromData(data []byte) ([]byte, error)
func (*ValueInferenceGenerator) FromPaths ¶
func (g *ValueInferenceGenerator) FromPaths(paths ...string) ([]byte, error)
FromPaths generates a JSON Schema from one or more file paths pointing to Helm values files. If multiple file paths are provided, the schemas are merged into a single schema, using defaults from the file matching DefaultFileRegex (usually `values.yaml`).