ccschema

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HandlerTypeCreate = "create"
	HandlerTypeDelete = "delete"
	HandlerTypeList   = "list"
	HandlerTypeRead   = "read"
	HandlerTypeUpdate = "update"
)
View Source
const (
	PropertyArrayTypeAttributeList = "AttributeList"
	PropertyArrayTypeStandard      = "Standard"
)
View Source
const (
	PropertyFormatDate                = "date"
	PropertyFormatDateTime            = "date-time"
	PropertyFormatEmail               = "email"
	PropertyFormatHostname            = "hostname"
	PropertyFormatIdnEmail            = "idn-email"
	PropertyFormatIdnHostname         = "idn-hostname"
	PropertyFormatIpv4                = "ipv4"
	PropertyFormatIpv6                = "ipv6"
	PropertyFormatIri                 = "iri"
	PropertyFormatIriReference        = "iri-reference"
	PropertyFormatJsonPointer         = "json-pointer"
	PropertyFormatRegex               = "regex"
	PropertyFormatRelativeJsonPointer = "relative-json-pointer"
	PropertyFormatTime                = "time"
	PropertyFormatUri                 = "uri"
	PropertyFormatUriReference        = "uri-reference"
	PropertyFormatUriTemplate         = "uri-templates"
)
View Source
const (
	PropertyTypeArray   = "array"
	PropertyTypeBoolean = "boolean"
	PropertyTypeInteger = "integer"
	PropertyTypeNull    = "null"
	PropertyTypeNumber  = "number"
	PropertyTypeObject  = "object"
	PropertyTypeString  = "string"
)
View Source
const (
	JsonPointerReferenceTokenSeparator  = "/"
	PropertiesJsonPointerReferenceToken = "properties"
	PropertiesJsonPointerPrefix         = JsonPointerReferenceTokenSeparator + PropertiesJsonPointerReferenceToken
)
View Source
const (
	ReferenceAnchor          = "#"
	ReferenceSeparator       = "/"
	ReferenceTypeDefinitions = "definitions"
	ReferenceTypeProperties  = "properties"
)
View Source
const (
	ReplacementStrategyCreateThenDelete = "create_then_delete"
	ReplacementStrategyDeleteThenCreate = "delete_then_create"
)

Variables

This section is empty.

Functions

func Sanitize

func Sanitize(document string) (string, error)

Sanitize returns a sanitized copy of the specified JSON Schema document. The sanitized copy works around any problems with JSON Schema regex validation by

  • Rewriting all patternProperty regexes to the empty string (the regex is never used anyway)
  • Rewriting all unsupported (valid for ECMA-262 but not for Go) pattern regexes to the empty string

Types

type Handler

type Handler struct {
	HandlerSchema    *HandlerSchema `json:"handlerSchema,omitempty"`
	Permissions      []string       `json:"permissions,omitempty"`
	TimeoutInMinutes int            `json:"timeoutInMinutes,omitempty"`
}

type HandlerSchema

type HandlerSchema struct {
	AllOf      []*PropertySubschema `json:"allOf,omitempty"`
	AnyOf      []*PropertySubschema `json:"anyOf,omitempty"`
	OneOf      []*PropertySubschema `json:"oneOf,omitempty"`
	Properties map[string]*Property `json:"properties,omitempty"`
	Required   []string             `json:"required,omitempty"`
}

type MetaJsonSchema

type MetaJsonSchema struct {
	// contains filtered or unexported fields
}

MetaJsonSchema represents the meta-schema for resource schemas

func NewMetaJsonSchemaDocument

func NewMetaJsonSchemaDocument(document string) (*MetaJsonSchema, error)

NewMetaJsonSchemaDocument returns a MetaJsonSchema or any errors from the provided document.

func NewMetaJsonSchemaPath

func NewMetaJsonSchemaPath(path string) (*MetaJsonSchema, error)

NewMetaJsonSchemaPath returns a MetaJsonSchema or any errors from the provided document at the file path.

func (*MetaJsonSchema) ValidateResourceDocument

func (s *MetaJsonSchema) ValidateResourceDocument(document string) error

ValidateResourceDocument validates the provided document against the meta-schema.

func (*MetaJsonSchema) ValidateResourceJsonSchema

func (s *MetaJsonSchema) ValidateResourceJsonSchema(resourceJsonSchema *ResourceJsonSchema) error

ValidateResourceJsonSchema validates the provided ResourceJsonSchema against the meta-schema.

func (*MetaJsonSchema) ValidateResourcePath

func (s *MetaJsonSchema) ValidateResourcePath(path string) error

ValidateResourcePath validates the provided document at the file path against the meta-schema.

type Property

type Property struct {
	AdditionalProperties *bool                    `json:"additionalProperties,omitempty"`
	AllOf                []*PropertySubschema     `json:"allOf,omitempty"`
	AnyOf                []*PropertySubschema     `json:"anyOf,omitempty"`
	ArrayType            *string                  `json:"arrayType,omitempty"`
	Comment              *string                  `json:"$comment,omitempty"`
	Default              interface{}              `json:"default,omitempty"`
	Description          *string                  `json:"description,omitempty"`
	Enum                 []interface{}            `json:"enum,omitempty"`
	Examples             []interface{}            `json:"examples,omitempty"`
	Format               *string                  `json:"format,omitempty"`
	InsertionOrder       *bool                    `json:"insertionOrder,omitempty"`
	Items                *Property                `json:"items,omitempty"`
	Maximum              *json.Number             `json:"maximum,omitempty"`
	MaxItems             *int                     `json:"maxItems,omitempty"`
	MaxLength            *int                     `json:"maxLength,omitempty"`
	Minimum              *json.Number             `json:"minimum,omitempty"`
	MinItems             *int                     `json:"minItems,omitempty"`
	MinLength            *int                     `json:"minLength,omitempty"`
	OneOf                []*PropertySubschema     `json:"oneOf,omitempty"`
	Pattern              *string                  `json:"pattern,omitempty"`
	PatternProperties    map[string]*Property     `json:"patternProperties,omitempty"`
	Properties           map[string]*Property     `json:"properties,omitempty"`
	Ref                  *Reference               `json:"$ref,omitempty"`
	RelationshipRef      *PropertyRelationshipRef `json:"relationshipRef,omitempty"`
	Required             []string                 `json:"required,omitempty"`
	Type                 *Type                    `json:"type,omitempty"`
	UniqueItems          *bool                    `json:"uniqueItems,omitempty"`
}

Property represents the Cloud Control Resource Schema customization for Definitions and Properties.

func (*Property) IsRequired

func (p *Property) IsRequired(name string) bool

func (*Property) String

func (p *Property) String() string

String returns a string representation of Property.

type PropertyJsonPointer

type PropertyJsonPointer string

PropertyJsonPointer is a simplistic RFC 6901 handler for properties JSON Pointers.

func (*PropertyJsonPointer) EqualsPath

func (p *PropertyJsonPointer) EqualsPath(other []string) bool

EqualsPath returns true if all path parts match.

This automatically handles stripping the /properties prefix.

func (*PropertyJsonPointer) EqualsStringPath

func (p *PropertyJsonPointer) EqualsStringPath(path string) bool

EqualsStringPath returns true if the path string matches.

This automatically handles stripping the /properties prefix.

func (*PropertyJsonPointer) Path

func (p *PropertyJsonPointer) Path() []string

Path returns the path parts.

This automatically handles stripping the /properties path part.

func (*PropertyJsonPointer) String

func (p *PropertyJsonPointer) String() string

String returns a string representation of the PropertyJsonPointer.

type PropertyJsonPointers

type PropertyJsonPointers []PropertyJsonPointer

PropertyJsonPointers is a list of PropertyJsonPointer.

func (PropertyJsonPointers) ContainsPath

func (ptrs PropertyJsonPointers) ContainsPath(path []string) bool

ContainsPath returns true if an element matches the path.

type PropertyRelationshipRef

type PropertyRelationshipRef struct {
	PropertyPath *PropertyJsonPointer `json:"propertyPath,omitempty"`
	TypeName     *string              `json:"typeName,omitempty"`
}

type PropertySubschema

type PropertySubschema struct {
	AllOf      []*PropertySubschema `json:"allOf,omitempty"`
	AnyOf      []*PropertySubschema `json:"anyOf,omitempty"`
	OneOf      []*PropertySubschema `json:"oneOf,omitempty"`
	Properties map[string]*Property `json:"properties,omitempty"`
	Required   []string             `json:"required,omitempty"`
}

type PropertyTransform

type PropertyTransform map[string]string

PropertyTransform represents property transform values.

func (PropertyTransform) Value

func (p PropertyTransform) Value(path []string) (string, bool)

Value returns the value for a specified property path.

type Reference

type Reference string

Reference is an internal implementation for RFC 6901 JSON Pointer values.

func (Reference) Field

func (r Reference) Field() (string, error)

Field returns the JSON Pointer string path after the type.

func (Reference) String

func (r Reference) String() string

String returns the string representation of a Reference.

func (Reference) Type

func (r Reference) Type() (string, error)

Type returns the first path part of the JSON Pointer.

In Cloud Control Resources, this should be definitions or properties.

type Resource

type Resource struct {
	AdditionalIdentifiers           []PropertyJsonPointers `json:"additionalIdentifiers,omitempty"`
	AdditionalProperties            *bool                  `json:"additionalProperties,omitempty"`
	AllOf                           []*PropertySubschema   `json:"allOf,omitempty"`
	AnyOf                           []*PropertySubschema   `json:"anyOf,omitempty"`
	ConditionalCreateOnlyProperties PropertyJsonPointers   `json:"conditionalCreateOnlyProperties,omitempty"`
	CreateOnlyProperties            PropertyJsonPointers   `json:"createOnlyProperties,omitempty"`
	Definitions                     map[string]*Property   `json:"definitions,omitempty"`
	DeprecatedProperties            PropertyJsonPointers   `json:"deprecatedProperties,omitempty"`
	Description                     *string                `json:"description,omitempty"`
	Handlers                        map[string]*Handler    `json:"handlers,omitempty"`
	NonPublicDefinitions            PropertyJsonPointers   `json:"nonPublicDefinitions,omitempty"`
	NonPublicProperties             PropertyJsonPointers   `json:"nonPublicProperties,omitempty"`
	OneOf                           []*PropertySubschema   `json:"oneOf,omitempty"`
	PrimaryIdentifier               PropertyJsonPointers   `json:"primaryIdentifier,omitempty"`
	Properties                      map[string]*Property   `json:"properties,omitempty"`
	PropertyTransform               PropertyTransform      `json:"propertyTransform,omitempty"`
	ReadOnlyProperties              PropertyJsonPointers   `json:"readOnlyProperties,omitempty"`
	ReplacementStrategy             *string                `json:"replacementStrategy,omitempty"`
	Required                        []string               `json:"required,omitempty"`
	ResourceLink                    *ResourceLink          `json:"resourceLink,omitempty"`
	SourceURL                       *string                `json:"sourceUrl,omitempty"`
	Taggable                        *bool                  `json:"taggable,omitempty"`
	Tagging                         *Tagging               `json:"tagging,omitempty"`
	TypeName                        *string                `json:"typeName,omitempty"`
	WriteOnlyProperties             PropertyJsonPointers   `json:"writeOnlyProperties,omitempty"`
}

func (*Resource) Expand

func (r *Resource) Expand() error

Expand replaces all Definition and Property JSON Pointer references with their content. This functionality removes the need for recursive logic when accessing Definitions and Properties. In unresolved form nested properties are not allowed, instead nested properties use a '$ref' JSON Pointer to reference a definition.

func (*Resource) IsCreateOnlyPropertyPath

func (r *Resource) IsCreateOnlyPropertyPath(path string) bool

func (*Resource) IsReadOnleyPropertyPath

func (r *Resource) IsReadOnleyPropertyPath(path string) bool

func (*Resource) IsRequired

func (r *Resource) IsRequired(name string) bool

func (*Resource) ResolveProperties

func (r *Resource) ResolveProperties(properties map[string]*Property) error

ResolveProperties resolves all References in a top-level name-to-property map. In theory unresolved form nested properties are not allowed but in practice they do occur, so support arbitrarily deeply nested references.

func (*Resource) ResolveProperty

func (r *Resource) ResolveProperty(property *Property) (bool, error)

ResolveProperty resolves any Reference (JSON Pointer) in a Property. Returns whether a Reference was resolved.

func (*Resource) ResolveReference

func (r *Resource) ResolveReference(ref Reference) (*Property, error)

ResolveReference resolves a Reference (JSON Pointer) into a Property.

func (*Resource) UnwrapOneOfProperties

func (r *Resource) UnwrapOneOfProperties(property *Property) error

UnwrapOneOfProperties unwraps a set of properties nested in a oneOf element.

type ResourceJsonSchema

type ResourceJsonSchema struct {
	// contains filtered or unexported fields
}

ResourceJsonSchema represents the resource schema.

func NewResourceJsonSchemaDocument

func NewResourceJsonSchemaDocument(document string) (*ResourceJsonSchema, error)

NewResourceJsonSchemaDocument returns a ResourceJsonSchema or any errors from the provided document.

func NewResourceJsonSchemaPath

func NewResourceJsonSchemaPath(path string) (*ResourceJsonSchema, error)

NewResourceJsonSchemaPath returns a ResourceJsonSchema or any errors from the provided document at the file path.

func (*ResourceJsonSchema) Resource

func (s *ResourceJsonSchema) Resource() (*Resource, error)

Resource parses the JSON Schema and returns Resource or an error.

func (*ResourceJsonSchema) ValidateConfigurationDocument

func (s *ResourceJsonSchema) ValidateConfigurationDocument(document string) error

ValidateConfigurationDocument validates the provided document against the resource schema.

func (*ResourceJsonSchema) ValidateConfigurationPath

func (s *ResourceJsonSchema) ValidateConfigurationPath(path string) error

ValidateConfigurationPath validates the provided document at the file path against the resource schema.

type ResourceLink struct {
	Comment     *string           `json:"$comment,omitempty"`
	Mappings    map[string]string `json:"mappings,omitempty"`
	TemplateURI *string           `json:"templateUri,omitempty"`
}

type Tagging

type Tagging struct {
	Taggable     *bool                `json:"taggable,omitempty"`
	TagOnCreate  *bool                `json:"tagOnCreate,omitempty"`
	TagUpdatable *bool                `json:"tagUpdatable,omitempty"`
	TagProperty  *PropertyJsonPointer `json:"tagProperty,omitempty"`
	Permissions  []string             `json:"permissions,omitempty"`
}

type Type

type Type string

func (*Type) String

func (t *Type) String() string

String is a string representation of Type.

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom JSON handler for Type.

Jump to

Keyboard shortcuts

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