generator

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseNexemaValueType

type BaseNexemaValueType struct {
	Kind     string `json:"$type"`    // NexemaPrimitiveValueType or NexemaTypeValueType
	Nullable bool   `json:"nullable"` // True if the type is nullable
}

BaseNexemaValueType is a base struct for every Nexema's type

type EnumFieldTemplateData

type EnumFieldTemplateData struct {
	LowerName string
	Name      string
	Index     int64
}

type EnumTemplateData

type EnumTemplateData struct {
	TypeName      string
	LowerTypeName string
	Fields        []EnumFieldTemplateData
	Documentation []string
	HasDocs       bool
}

type GeneratedFile

type GeneratedFile struct {
	Path    string
	Content []byte
}

type Generator

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

Generator is the main entry point of the Nexema's Go generator

func NewGenerator

func NewGenerator(cfg *PluginConfig) *Generator

NewGenerator creates a new Generator instance

func (*Generator) Generate

func (g *Generator) Generate(input []byte) ([]*GeneratedFile, error)

Generate takes an input buffer which represents a NexemaDefinition and outputs a list of files to be generated

type NexemaDefinition

type NexemaDefinition struct {
	Version  int          `json:"version"`  // The Nexema specification's version used to build this definition
	Hashcode uint64       `json:"hashcode"` // Hashcode of the current generation
	Files    []NexemaFile `json:"files"`    // A list of nexema files
}

NexemaDefinition represents an analyzed and built list of Ast. This type is next sent to a plugin to generate source code.

type NexemaFile

type NexemaFile struct {
	Name  string                 `json:"name"`  // The relative path to the file. Its relative to nexema.yaml
	Types []NexemaTypeDefinition `json:"types"` // The list of types declared in this file
}

NexemaFile represents a .nex file with many NexemaTypeDefinition's

type NexemaPrimitiveValueType

type NexemaPrimitiveValueType struct {
	BaseNexemaValueType `json:",inline"`
	Primitive           string            `json:"primitive"`     // Value's type primitive
	TypeArguments       []NexemaValueType `json:"typeArguments"` // Any generic type argument
}

NexemaPrimitiveValueType represents the value type of a NexemaTypeFieldDefinition which has a primitive type.

type NexemaTypeDefinition

type NexemaTypeDefinition struct {
	Id            string                      `json:"id"`            // An id generated for this type. It's: sha256(NexemaFilePath-TypeName)
	Name          string                      `json:"name"`          // The name of the type
	Modifier      string                      `json:"modifier"`      // The type's modifier
	Documentation []string                    `json:"documentation"` // The documentation for the type
	Fields        []NexemaTypeFieldDefinition `json:"fields"`        // The list of fields declared in this type
}

NexemaTypeDefinition contains information about a parsed Nexema type

type NexemaTypeFieldDefinition

type NexemaTypeFieldDefinition struct {
	Index        int64           `json:"index"`        // The field's index
	Name         string          `json:"name"`         // The field's name
	Metadata     map[string]any  `json:"metadata"`     // The field's metadata
	DefaultValue any             `json:"defaultValue"` // The field's default value
	Type         NexemaValueType `json:"type"`         // The field's value type
}

NexemaTypeFieldDefinition contains information about a field declared in a Nexema type

func (*NexemaTypeFieldDefinition) UnmarshalJSON

func (n *NexemaTypeFieldDefinition) UnmarshalJSON(b []byte) error

type NexemaTypeValueType

type NexemaTypeValueType struct {
	BaseNexemaValueType `json:",inline"`
	TypeId              string  `json:"typeId"`      // The imported type's id
	ImportAlias         *string `json:"importAlias"` // the import alias, if specified
}

NexemaTypeValueType represents the value type of a NexemaTypeFieldDefinition which has another Nexema type as value type.

type NexemaValueType

type NexemaValueType interface {
	// contains filtered or unexported methods
}

type PluginConfig

type PluginConfig struct {
	OutputPath string // Files output folder path
	ModuleName string // Go's module name
}

type PluginOpts

type PluginOpts struct {
	// EnforceBuilder tells the generator to generate unexported fields for structs and
	// generate instead getter and setter, enforcing to only use NewX method for creating X instances
	EnforceBuilder bool `json:"enforceBuilder"`

	// Go's module name of the current project
	ModuleName string `json:"moduleName"`
}

type StructFieldTemplateData

type StructFieldTemplateData struct {
	FieldName      string // FieldName is field's name but in Go (CamelCase)
	LowerFieldName string // LowerFieldName is field's name in Go, but lowerCamelCase
	Index          int64
	TypeName       string
	IsNullable     bool
	ImportTypeName string // the same as TypeName but with import e.x: models.User
	TypeId         string
	FieldDef       *NexemaTypeFieldDefinition
}

type StructTemplateData

type StructTemplateData struct {
	TypeName      string
	Documentation []string
	HasDocs       bool
	Fields        []TypeFieldTemplateData
}

type TypeFieldTemplateData

type TypeFieldTemplateData struct {
	FieldName       string // FieldName is field's name but in Go (CamelCase)
	LowerFieldName  string // LowerFieldName is field's name in Go, but lowerCamelCase
	FieldIndex      int64
	IsFromUnion     bool
	ValueType       TypeFieldValueKindTemplate
	DefaultValue    interface{}
	HasDefaultValue bool
}

type TypeFieldValueKindTemplate

type TypeFieldValueKindTemplate struct {
	IsNullable     bool
	IsList         bool
	IsMap          bool
	IsEnum         bool
	IsPrimitive    bool
	IsType         bool
	ImportTypeName string // Field type's name but with import, if neccessary (ex: models.User)
	IsNumeric      bool
	TypeArguments  []TypeFieldValueKindTemplate
}

TypeFieldValueKindTemplate contains information about the field's value type. ex: string, MyStruct, MyEnum, list(string), map(int64, MyEnum), etc

type UnionTemplateData

type UnionTemplateData struct {
	TypeName      string
	Documentation []string
	HasDocs       bool
	LowerName     string
	Fields        []TypeFieldTemplateData
}

Jump to

Keyboard shortcuts

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