generator

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//TypeNameObject represents an object
	TypeNameObject propertyTypeName = iota //object
	//TypeNameString represents an string
	TypeNameString //string
	//TypeNameBool represents an boolean
	TypeNameBool //boolean
	//TypeNameInteger represents an integer
	TypeNameInteger //integer
	//TypeNameNumber represents a number (float or integer)
	TypeNameNumber //number
	//TypeNameArray represents and object
	TypeNameArray //array
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeGenerator

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

CodeGenerator creates following struct methods

`IsSet() bool` `Reset()` `validate() error` `validate() error` `processNestedSource() error`

on all exported and anonymous structs that are referenced by at least one of the root types

func NewCodeGenerator

func NewCodeGenerator(parsed *Parsed, rootTypes []string) (*CodeGenerator, error)

NewCodeGenerator takes an importPath and the package name for which the type definitions should be loaded. The nullableTypePath is used to implement validation rules specific to types of the nullable package. The generator creates methods only for types referenced directly or indirectly by any of the root types.

func (*CodeGenerator) Generate

func (g *CodeGenerator) Generate() (bytes.Buffer, error)

Generate generates the code for given root structs and all dependencies and returns it as bytes.Buffer

type JSONSchemaGenerator

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

JSONSchemaGenerator holds the parsed package information from which it can generate a JSON schema

func NewJSONSchemaGenerator

func NewJSONSchemaGenerator(parsed *Parsed) (*JSONSchemaGenerator, error)

NewJSONSchemaGenerator takes a parsed package information as input parameter and returns a JSONSchemaGenerator instance

func (*JSONSchemaGenerator) Generate

func (g *JSONSchemaGenerator) Generate(idPath string, rootType string) (bytes.Buffer, error)

Generate creates a JSON schema for the given root type, based on the parsed information from the JSONSchemaGenerator. The schema is returned as bytes.Buffer

type Parsed

type Parsed struct {
	// Dir holds the filesystem directory holding the parsed Go package.
	Dir string
	// contains filtered or unexported fields
}

Parsed contains information about a parsed package, including the package name, type information and some pre-defined variables

func Parse

func Parse(pkgPattern string) (*Parsed, error)

Parse loads the Go package named by the given package pattern and creates a parsed struct containing the package name, type information and some pre-defined variables It returns an error if the package cannot be successfully loaded or parsed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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