schema

package
v1.18.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package schema defines helpers for working with JSON schema. As defined by https://datatracker.ietf.org/doc/html/draft-zyp-json-schema-04

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromKnownJSONType

func FromKnownJSONType(t KnownJSONType) (v1.TransformIOType, error)

FromKnownJSONType returns the TransformIOType for the given KnownJSONType.

func IsValid

func IsValid(t string) bool

IsValid returns true if the supplied string is a known JSON type.

Types

type KnownJSONType

type KnownJSONType string

KnownJSONType is all the known JSON types. See https://datatracker.ietf.org/doc/html/draft-zyp-json-schema-04#section-3.5

const (
	// KnownJSONTypeArray is the JSON type for arrays.
	KnownJSONTypeArray KnownJSONType = "array"
	// KnownJSONTypeBoolean is the JSON type for booleans.
	KnownJSONTypeBoolean KnownJSONType = "boolean"
	// KnownJSONTypeInteger is the JSON type for integers.
	KnownJSONTypeInteger KnownJSONType = "integer"
	// KnownJSONTypeNull is the JSON type for null.
	KnownJSONTypeNull KnownJSONType = "null"
	// KnownJSONTypeNumber is the JSON type for numbers.
	KnownJSONTypeNumber KnownJSONType = "number"
	// KnownJSONTypeObject is the JSON type for objects.
	KnownJSONTypeObject KnownJSONType = "object"
	// KnownJSONTypeString is the JSON type for strings.
	KnownJSONTypeString KnownJSONType = "string"
)

func FromTransformIOType

func FromTransformIOType(c v1.TransformIOType) KnownJSONType

FromTransformIOType returns the matching JSON type for the given TransformIOType. It returns an empty string if the type is not valid, call IsValid() before calling this method.

func (KnownJSONType) IsEquivalent

func (t KnownJSONType) IsEquivalent(t2 KnownJSONType) bool

IsEquivalent returns true if the two supplied types are equal, or if the first type is an integer and the second is a number. This is because the JSON schema spec allows integers to be used in place of numbers.

Jump to

Keyboard shortcuts

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