Documentation
¶
Overview ¶
package schemautil contains utilities for working with JSON Schemas.
Index ¶
- Constants
- func FalseSchema() *jsonschema.Schema
- func GetExtensionInt(schema *jsonschema.Schema, extension string) (int, bool)
- func GetExtensionString(schema *jsonschema.Schema, extension string) string
- func GetPropertyOrder(schema *jsonschema.Schema) []string
- func GetXAdditionalPropertiesName(addPropSchema *jsonschema.Schema) string
- func IsFalseSchema(schema *jsonschema.Schema) bool
- func IsTrueSchema(schema *jsonschema.Schema) bool
- func OrderedProperties(schema *jsonschema.Schema) iter.Seq2[string, *jsonschema.Schema]
- func OrderedPropertyNames(schema *jsonschema.Schema) iter.Seq[string]
- func SetPropertyOrder(schema *jsonschema.Schema)
- func TrueSchema() *jsonschema.Schema
- func WalkSchema(in *jsonschema.Schema, cb WalkSchemaFunc) (*jsonschema.Schema, error)
- func WalkSchemaWithLocation(loc string, in *jsonschema.Schema, cb WalkSchemaFunc) (*jsonschema.Schema, error)
- type ExampleGenerator
- type MapRegistry
- type Registry
- type WalkSchemaFunc
Constants ¶
const ( // Display a field name for an additionalProperties description. XAdditionalPropertiesName = "x-additionalPropertiesName" // Add visible badges as indicators to API operations. XBadges = "x-badges" // Provide the code sample to display for an operation. XCodeSamples = "x-codeSamples" // Readable labels for enum values. XEnumDescriptions = "x-enumDescriptions" // Promote or exclude description files, operations, or tags in search results for specified keywords. XKeywords = "x-keywords" // Add custom metadata at the top of the info section. XMetadata = "x-metadata" // Specify order of properties in an object schema for documentation purposes only. XOrder = "x-order" // Add individual schemas to navigation sections alongside operations. XTags = "x-tags" // Add short summary of the response. XSummary = "x-summary" )
Known OpenAPI and JSON Schema extensions.
From OpenAPI Initiative: https://spec.openapis.org/registry/index.html From Redocly: https://redocly.com/docs/realm/content/api-docs/openapi-extensions
const ( TypeArray = "array" TypeBoolean = "boolean" TypeInteger = "integer" TypeNull = "null" TypeNumber = "number" TypeObject = "object" TypeString = "string" )
JSON Schema type values.
const ( FormatDate = "date" FormatDateTime = "date-time" FormatTime = "time" FormatInt32 = "int32" FormatInt64 = "int64" FormatFloat = "float" FormatDouble = "double" )
JSON Schema format values.
const ( ContentEncodingQuotedPrintable = "quoted-printable" ContentEncodingBase16 = "base16" ContentEncodingBase32 = "base32" ContentEncodingBase64 = "base64" )
JSON Schema content encoding values. https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-8.3
Variables ¶
This section is empty.
Functions ¶
func FalseSchema ¶
func FalseSchema() *jsonschema.Schema
FalseSchema returns a Schema that validates no JSON value. It is equivalent to the schema {"not": {}}, which marshals to the JSON literal false.
func GetExtensionInt ¶
func GetExtensionInt(schema *jsonschema.Schema, extension string) (int, bool)
GetExtensionInt checks the schema for the extension and returns its value as an int if it is present. If the extension is not present, or could not be cast to an int, the boolean value will be false.
func GetExtensionString ¶
func GetExtensionString(schema *jsonschema.Schema, extension string) string
GetExtensionString checks the schema for the extension and returns its value as a string if it is present. If the extension is not present, or could not be cast to a string, the empty string is returned.
func GetPropertyOrder ¶
func GetPropertyOrder(schema *jsonschema.Schema) []string
GetPropertyOrder produces a canonical order of the schema's properties based on the "x-order" extension, with alphabetical sorting as a fallback.
func GetXAdditionalPropertiesName ¶
func GetXAdditionalPropertiesName(addPropSchema *jsonschema.Schema) string
GetXAdditionalPropertiesName returns the value of the "x-additionalPropertiesName" extension or the empty string.
func IsFalseSchema ¶
func IsFalseSchema(schema *jsonschema.Schema) bool
IsFalseSchema reports whether the schema is the false schema, as defined by FalseSchema.
func IsTrueSchema ¶
func IsTrueSchema(schema *jsonschema.Schema) bool
IsTrueSchema reports whether the schema is the true schema, as defined by TrueSchema.
func OrderedProperties ¶
func OrderedProperties(schema *jsonschema.Schema) iter.Seq2[string, *jsonschema.Schema]
OrderedProperties returns an iterator over the properties of a schema in their defined order, if they are defined with an order.
func OrderedPropertyNames ¶
func OrderedPropertyNames(schema *jsonschema.Schema) iter.Seq[string]
OrderedPropertyNames returns an iterator over the property names of a schema in their defined order, if they are defined with an order.
func SetPropertyOrder ¶
func SetPropertyOrder(schema *jsonschema.Schema)
SetPropertyOrder sets the property order for a schema.
func TrueSchema ¶
func TrueSchema() *jsonschema.Schema
TrueSchema returns a Schema that validates any JSON value. It is equivalent to the empty schema ({}), which marshals to the JSON literal true.
func WalkSchema ¶
func WalkSchema(in *jsonschema.Schema, cb WalkSchemaFunc) (*jsonschema.Schema, error)
WalkSchema walks all subschemas of a JSON Schema.
func WalkSchemaWithLocation ¶
func WalkSchemaWithLocation(loc string, in *jsonschema.Schema, cb WalkSchemaFunc) (*jsonschema.Schema, error)
WalkSchemaWithLocation walks all subschemas of a JSON Schema.
Types ¶
type ExampleGenerator ¶
type ExampleGenerator struct {
// contains filtered or unexported fields
}
ExampleGenerator generates example data from JSON Schemas.
func NewExampleGenerator ¶
func NewExampleGenerator(reg Registry) *ExampleGenerator
NewExampleGenerator creates a new ExampleGenerator for a schema registry.
func (*ExampleGenerator) GetExample ¶
func (gen *ExampleGenerator) GetExample(ref string) (any, bool)
GetExample gets the example value for the reference.
type MapRegistry ¶
type MapRegistry map[string]*jsonschema.Schema
MapRegistry is a Registry in a map.
func (MapRegistry) GetSchema ¶
func (reg MapRegistry) GetSchema(ref string) (*jsonschema.Schema, bool)
GetSchema implements Registry.
type Registry ¶
type Registry interface {
// GetSchema returns the JSON Schema at the given reference.
GetSchema(ref string) (*jsonschema.Schema, bool)
}
Registry defines a registry of JSON Schemas.
type WalkSchemaFunc ¶
type WalkSchemaFunc func(loc string, schema *jsonschema.Schema) (*jsonschema.Schema, error)
WalkSchemaFunc is called for each subschema node while walking a JSON Schema.
Directories
¶
| Path | Synopsis |
|---|---|
|
adapters
|
|
|
invopopadapter
package invopopadapter converts schemas between github.com/invopop/jsonschema and github.com/google/jsonschema-go/jsonschema.
|
package invopopadapter converts schemas between github.com/invopop/jsonschema and github.com/google/jsonschema-go/jsonschema. |
|
Package schemamd renders Markdown documentation from JSON Schemas.
|
Package schemamd renders Markdown documentation from JSON Schemas. |