jsonschema

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldVisibility added in v0.1.5

type FieldVisibility int
const (
	FieldVisible FieldVisibility = iota
	FieldHide
	FieldIgnore
)

type Generator added in v0.5.0

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

Generator is a JSON schema generator for protobuf messages.

func NewGenerator added in v0.5.0

func NewGenerator(opts ...GeneratorOption) *Generator

NewGenerator creates a new JSON schema generator with the given options.

func (*Generator) Add added in v0.5.0

Add adds a message descriptor to the generator.

func (*Generator) Generate added in v0.5.0

func (p *Generator) Generate() map[protoreflect.FullName]map[string]any

Generate returns the generated JSON schema for all added message descriptors (and their dependencies if not bundling).

type GeneratorOption added in v0.1.5

type GeneratorOption func(*Generator)

func WithAdditionalProperties added in v0.4.0

func WithAdditionalProperties() GeneratorOption

WithAdditionalProperties sets the generator to allow additional properties on messages.

func WithBundle added in v0.5.0

func WithBundle() GeneratorOption

WithBundle sets the generator to bundle all schemas references into the same file.

func WithJSONNames added in v0.1.5

func WithJSONNames() GeneratorOption

WithJSONNames sets the generator to use JSON field names as the primary name.

func WithStrict added in v0.4.0

func WithStrict() GeneratorOption

WithStrict sets the generator to require input be pre-normalized.

When a JSON value is converted to protobuf, the converter uses the protobuf schema to normalize and validate it further. The default generated schema takes this into account, allowing for implicit default values, aliases, and other leniencies.

When strict is enabled, the generated schema will not allow these leniencies. Specifically, the JSON schema:

  • Requires implicit default values be explicitly set. These fields are automatically populated in protobuf.
  • Does not allow aliases for field names.
  • Does not allow numbers to be represented as strings.
  • Requires Infinity and NaN values to be exactly capitalized.
  • Does not allow integers to be represented as strings.

The "always emit fields without presence" option must be set for ProtoJSON to output to be valid when strict is enabled. See https://protobuf.dev/programming-guides/json/#json-options

Jump to

Keyboard shortcuts

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