Documentation
¶
Index ¶
- Constants
- func FixRequiredProperties(schema *Schema) error
- func Worker(dryRun, uncomment, addSchemaReference, keepFullComment, ... bool, ...)
- type BoolOrArrayOfString
- type CircularError
- type Result
- type Schema
- type SchemaOrBool
- type SkipAutoGenerationConfig
- type StringOrArrayOfString
- func (s *StringOrArrayOfString) IsEmpty() bool
- func (s *StringOrArrayOfString) MarshalJSON() ([]byte, error)
- func (s *StringOrArrayOfString) Matches(typeString string) bool
- func (s *StringOrArrayOfString) UnmarshalJSON(value []byte) error
- func (s *StringOrArrayOfString) UnmarshalYAML(value *yaml.Node) error
- func (s *StringOrArrayOfString) Validate() error
Constants ¶
const ( SchemaPrefix = "# @schema" CommentPrefix = "#" // CustomAnnotationPrefix marks custom annotations. // Custom annotations are extensions to the JSON Schema specification // See: https://json-schema.org/blog/posts/custom-annotations-will-continue CustomAnnotationPrefix = "x-" )
SchemaPrefix and CommentPrefix define the markers used for schema annotations in comments
const ( FormatDateTime = "date-time" FormatTime = "time" FormatDate = "date" FormatDuration = "duration" FormatEmail = "email" FormatIDNEmail = "idn-email" FormatHostname = "hostname" FormatIDNHostname = "idn-hostname" FormatIPv4 = "ipv4" FormatIPv6 = "ipv6" FormatUUID = "uuid" FormatURI = "uri" FormatURIReference = "uri-reference" FormatIRI = "iri" FormatIRIReference = "iri-reference" FormatURITemplate = "uri-template" FormatJSONPointer = "json-pointer" FormatRelJSONPointer = "relative-json-pointer" FormatRegex = "regex" )
Supported format values according to JSON Schema specification
Variables ¶
This section is empty.
Functions ¶
func FixRequiredProperties ¶
FixRequiredProperties iterates over the properties and checks if required has a boolean value. Then the property is added to the parents required property list
Types ¶
type BoolOrArrayOfString ¶
BoolOrArrayOfString represents a JSON Schema field that can be either a boolean or an array of strings Used primarily for the "required" field which can be either true/false or an array of required property names
func NewBoolOrArrayOfString ¶
func NewBoolOrArrayOfString(arr []string, b bool) BoolOrArrayOfString
func (*BoolOrArrayOfString) MarshalJSON ¶
func (s *BoolOrArrayOfString) MarshalJSON() ([]byte, error)
func (*BoolOrArrayOfString) UnmarshalJSON ¶
func (s *BoolOrArrayOfString) UnmarshalJSON(value []byte) error
func (*BoolOrArrayOfString) UnmarshalYAML ¶
func (s *BoolOrArrayOfString) UnmarshalYAML(value *yaml.Node) error
type CircularError ¶
type CircularError struct {
// contains filtered or unexported fields
}
func (*CircularError) Error ¶
func (e *CircularError) Error() string
type Result ¶
type Schema ¶
type Schema struct { AdditionalProperties SchemaOrBool `yaml:"additionalProperties,omitempty" json:"additionalProperties,omitempty"` Default interface{} `yaml:"default,omitempty" json:"default,omitempty"` Then *Schema `yaml:"then,omitempty" json:"then,omitempty"` PatternProperties map[string]*Schema `yaml:"patternProperties,omitempty" json:"patternProperties,omitempty"` Properties map[string]*Schema `yaml:"properties,omitempty" json:"properties,omitempty"` If *Schema `yaml:"if,omitempty" json:"if,omitempty"` Minimum *int `yaml:"minimum,omitempty" json:"minimum,omitempty"` MultipleOf *int `yaml:"multipleOf,omitempty" json:"multipleOf,omitempty"` ExclusiveMaximum *int `yaml:"exclusiveMaximum,omitempty" json:"exclusiveMaximum,omitempty"` Items *Schema `yaml:"items,omitempty" json:"items,omitempty"` ExclusiveMinimum *int `yaml:"exclusiveMinimum,omitempty" json:"exclusiveMinimum,omitempty"` Maximum *int `yaml:"maximum,omitempty" json:"maximum,omitempty"` Else *Schema `yaml:"else,omitempty" json:"else,omitempty"` Pattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"` Const interface{} `yaml:"const,omitempty" json:"const,omitempty"` Ref string `yaml:"$ref,omitempty" json:"$ref,omitempty"` Schema string `yaml:"$schema,omitempty" json:"$schema,omitempty"` Id string `yaml:"$id,omitempty" json:"$id,omitempty"` Format string `yaml:"format,omitempty" json:"format,omitempty"` Description string `yaml:"description,omitempty" json:"description,omitempty"` Title string `yaml:"title,omitempty" json:"title,omitempty"` Type StringOrArrayOfString `yaml:"type,omitempty" json:"type,omitempty"` AnyOf []*Schema `yaml:"anyOf,omitempty" json:"anyOf,omitempty"` AllOf []*Schema `yaml:"allOf,omitempty" json:"allOf,omitempty"` OneOf []*Schema `yaml:"oneOf,omitempty" json:"oneOf,omitempty"` Not *Schema `yaml:"not,omitempty" json:"not,omitempty"` Examples []string `yaml:"examples,omitempty" json:"examples,omitempty"` Enum []string `yaml:"enum,omitempty" json:"enum,omitempty"` HasData bool `yaml:"-" json:"-"` Deprecated bool `yaml:"deprecated,omitempty" json:"deprecated,omitempty"` ReadOnly bool `yaml:"readOnly,omitempty" json:"readOnly,omitempty"` WriteOnly bool `yaml:"writeOnly,omitempty" json:"writeOnly,omitempty"` Required BoolOrArrayOfString `yaml:"required,omitempty" json:"required,omitempty"` CustomAnnotations map[string]interface{} `yaml:"-" json:",omitempty"` MinLength *int `yaml:"minLength,omitempty" json:"minLength,omitempty"` MaxLength *int `yaml:"maxLength,omitempty" json:"maxLength,omitempty"` MinItems *int `yaml:"minItems,omitempty" json:"minItems,omitempty"` MaxItems *int `yaml:"maxItems,omitempty" json:"maxItems,omitempty"` }
Schema struct contains yaml tags for reading, json for writing (creating the jsonschema)
func GetSchemaFromComment ¶
GetSchemaFromComment parses the annotations from the given comment
func YamlToSchema ¶
func YamlToSchema( valuesPath string, node *yaml.Node, keepFullComment bool, helmDocsCompatibilityMode bool, dontRemoveHelmDocsPrefix bool, dontAddGlobal bool, skipAutoGeneration *SkipAutoGenerationConfig, parentRequiredProperties *[]string, ) *Schema
YamlToSchema recursively parses a YAML node and creates a JSON Schema from it Parameters:
- valuesPath: path to the values file being processed
- node: current YAML node being processed
- keepFullComment: whether to preserve all comment text
- helmDocsCompatibilityMode: whether to parse helm-docs annotations
- dontRemoveHelmDocsPrefix: whether to keep helm-docs prefixes in comments
- skipAutoGeneration: configuration for which fields should not be auto-generated
- parentRequiredProperties: list of required properties to populate in parent
func (*Schema) DisableRequiredProperties ¶
func (s *Schema) DisableRequiredProperties()
DisableRequiredProperties recursively disables all required property validations throughout the schema. This includes: - Setting the root schema's required field to an empty array - Recursively disabling required properties in all nested schemas (properties, items, etc.) - Handling all conditional schemas (if/then/else) - Processing all composition schemas (anyOf/oneOf/allOf)
func (*Schema) MarshalJSON ¶
MarshalJSON custom marshal method for Schema. It inlines the CustomAnnotations fields
func (*Schema) UnmarshalYAML ¶
UnmarshalYAML implements custom YAML unmarshaling for Schema objects. It handles both standard schema fields and custom annotations (prefixed with "x-"). Custom annotations are stored in the CustomAnnotations map while standard fields are unmarshaled directly into the Schema struct.
type SchemaOrBool ¶
type SchemaOrBool interface{}
SchemaOrBool represents a JSON Schema field that can be either a boolean or a Schema object
type SkipAutoGenerationConfig ¶
type SkipAutoGenerationConfig struct {
Type, Title, Description, Required, Default, AdditionalProperties bool
}
func NewSkipAutoGenerationConfig ¶
func NewSkipAutoGenerationConfig(flag []string) (*SkipAutoGenerationConfig, error)
type StringOrArrayOfString ¶
type StringOrArrayOfString []string
func (*StringOrArrayOfString) IsEmpty ¶
func (s *StringOrArrayOfString) IsEmpty() bool
func (*StringOrArrayOfString) MarshalJSON ¶
func (s *StringOrArrayOfString) MarshalJSON() ([]byte, error)
func (*StringOrArrayOfString) Matches ¶
func (s *StringOrArrayOfString) Matches(typeString string) bool
func (*StringOrArrayOfString) UnmarshalJSON ¶
func (s *StringOrArrayOfString) UnmarshalJSON(value []byte) error
func (*StringOrArrayOfString) UnmarshalYAML ¶
func (s *StringOrArrayOfString) UnmarshalYAML(value *yaml.Node) error
func (*StringOrArrayOfString) Validate ¶
func (s *StringOrArrayOfString) Validate() error