generate

package
v0.0.0-...-18043a3 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	// The golang name, e.g. "Address1"
	Name string
	// The JSON name, e.g. "address1"
	JSONName string
	// The golang type of the field, e.g. a built-in type like "string" or the name of a struct generated
	// from the JSON schema.
	Type string
	// Required is set to true when the field is required.
	Required    bool
	Description string
}

Field defines the data required to generate a field in Go.

type Generator

type Generator struct {
	Structs map[string]Struct
	Aliases map[string]Field
	// contains filtered or unexported fields
}

Generator will produce structs from the JSON schema.

func New

func New(schemas ...*jsonschema.Schema) *Generator

New creates an instance of a generator which will produce structs.

func (*Generator) CreateTypes

func (g *Generator) CreateTypes() (err error)

CreateTypes creates types from the JSON schemas, keyed by the golang name.

type RefResolver

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

RefResolver allows references to be resolved.

func NewRefResolver

func NewRefResolver(schemas []*jsonschema.Schema) *RefResolver

NewRefResolver creates a reference resolver.

func (*RefResolver) GetPath

func (r *RefResolver) GetPath(schema *jsonschema.Schema) string

GetPath generates a path to given schema.

func (*RefResolver) GetSchemaByReference

func (r *RefResolver) GetSchemaByReference(schema *jsonschema.Schema) (*jsonschema.Schema, error)

GetSchemaByReference returns the schema.

func (*RefResolver) Init

func (r *RefResolver) Init() error

Init the resolver.

func (*RefResolver) InsertURI

func (r *RefResolver) InsertURI(uri string, schema *jsonschema.Schema) error

InsertURI to the references.

type Struct

type Struct struct {
	// The ID within the JSON schema, e.g. #/definitions/address
	ID string
	// The golang name, e.g. "Address"
	Name string
	// Description of the struct
	Description string
	Fields      map[string]Field

	GenerateCode   bool
	AdditionalType string
}

Struct defines the data required to generate a struct in Go.

Jump to

Keyboard shortcuts

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