parser

package
v0.0.0-...-baa1f0e Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NexusRestApiGenAnnotation  = "nexus-rest-api-gen"
	NexusDescriptionAnnotation = "nexus-description"
	NexusGraphqlAnnotation     = "nexus-graphql-query"
	NexusSecretSpecAnnotation  = "nexus-secret-spec"
	NexusGraphqlSpecAnnotation = "nexus-graphql-spec"
)
View Source
const (
	GRAPHQL_ARGS_ANNOTATION          = FieldAnnotation("nexus-graphql-args")
	GRAPHQL_ALIAS_NAME_ANNOTATION    = FieldAnnotation("nexus-alias-name")
	GRAPHQL_ALIAS_TYPE_ANNOTATION    = FieldAnnotation("nexus-alias-type")
	GRAPHQL_TSM_DIRECTIVE_ANNOTATION = FieldAnnotation("nexus-graphql-tsm-directive")
	GRAPHQL_NULLABLE_ANNOTATION      = FieldAnnotation("nexus-graphql-nullable")
	GRAPHQL_TS_TYPE_ANNOTATION       = FieldAnnotation("nexus-graphql-ts-type")
	GRAPHQL_JSONENCODED_ANNOTATION   = FieldAnnotation("nexus-graphql-jsonencoded")
	GRAPHQL_RELATION_NAME            = FieldAnnotation("nexus-graphql-relation-name")
	GRAPHQL_RELATION_PARAMETERS      = FieldAnnotation("nexus-graphql-relation-parameters")
	GRAPHQL_RELATION_UUIDKEY         = FieldAnnotation("nexus-graphql-relation-uuidkey")
	GRAPHQL_TYPE_NAME                = FieldAnnotation("nexus-graphql-type-name")
	GRAPHQL_PROTOBUF_NAME            = FieldAnnotation("nexus-graphql-protobuf-name")
	GRAPHQL_PROTOBUF_FILE            = FieldAnnotation("nexus-graphql-protobuf-file")
)

Variables

View Source
var ReservedTypeNames = []string{"ResourceVersion", "SchemeGroupVersion", "Kind", "Resource", "SchemeBuilder",
	"AddToScheme", "Child", "Link", "NexusStatus"}

Functions

func CheckValueSpec

func CheckValueSpec(valueSpec *ast.ValueSpec) bool

func CreateParentsMap

func CreateParentsMap(graph map[string]Node) map[string]NodeHelper

func FillEmptyTag

func FillEmptyTag(ts *structtag.Tags, n, tag string) *structtag.Tags

func GetChildFields

func GetChildFields(n *ast.TypeSpec) []*ast.Field

func GetFieldAnnotationString

func GetFieldAnnotationString(f *ast.Field, annotation FieldAnnotation) string

func GetFieldAnnotationVal

func GetFieldAnnotationVal(f *ast.Field, annotation FieldAnnotation) string

func GetFieldJsonTag

func GetFieldJsonTag(f *ast.Field) *structtag.Tag

func GetFieldName

func GetFieldName(f *ast.Field) (string, error)

func GetFieldNameJsonTag

func GetFieldNameJsonTag(f *ast.Field) string

func GetFieldTags

func GetFieldTags(f *ast.Field) *structtag.Tags

func GetFieldType

func GetFieldType(f *ast.Field) string

func GetGraphqlQuerySpecs

func GetGraphqlQuerySpecs(queryMap map[string]nexus.GraphQLQuerySpec, p Package)

func GetGraphqlSpecs

func GetGraphqlSpecs(graphQLSpecMap map[string]nexus.GraphQLSpec, p Package)

func GetLinkFields

func GetLinkFields(n *ast.TypeSpec) []*ast.Field

func GetModulePath

func GetModulePath(startPath string) string

func GetNexusDescriptionAnnotation

func GetNexusDescriptionAnnotation(pkg Package, name string) (string, bool)

func GetNexusFields

func GetNexusFields(n *ast.TypeSpec) []*ast.Field

func GetNexusGraphqlAnnotation

func GetNexusGraphqlAnnotation(pkg Package, name string) (string, bool)

func GetNexusGraphqlSpecAnnotation

func GetNexusGraphqlSpecAnnotation(pkg Package, name string) (string, bool)

func GetNexusRestAPIGenAnnotation

func GetNexusRestAPIGenAnnotation(pkg Package, name string) (string, bool)

func GetNexusSecretSpecAnnotation

func GetNexusSecretSpecAnnotation(pkg Package, name string) (string, bool)

func GetNodeFieldName

func GetNodeFieldName(f *ast.Field) (string, error)

func GetSpecFields

func GetSpecFields(n *ast.TypeSpec) []*ast.Field

func GetStatusField

func GetStatusField(n *ast.TypeSpec) *ast.Field

func GetTypeName

func GetTypeName(n *ast.TypeSpec) string

func IgnoreField

func IgnoreField(f *ast.Field) bool

func IsArrayField

func IsArrayField(f *ast.Field) bool

func IsChildField

func IsChildField(f *ast.Field) bool

func IsFieldAnnotationPresent

func IsFieldAnnotationPresent(f *ast.Field, annotation FieldAnnotation) bool

func IsFieldPointer

func IsFieldPointer(f *ast.Field) bool

func IsJsonStringField

func IsJsonStringField(f *ast.Field) bool

func IsLinkField

func IsLinkField(f *ast.Field) bool

func IsMapField

func IsMapField(f *ast.Field) bool
func IsNamedChildOrLink(f *ast.Field) bool

func IsNexusField

func IsNexusField(f *ast.Field) bool

func IsNexusGraphqlNullField

func IsNexusGraphqlNullField(f *ast.Field) bool

func IsNexusNode

func IsNexusNode(n *ast.TypeSpec) bool

func IsNexusTypeField

func IsNexusTypeField(f *ast.Field) bool

func IsOnlyChildField

func IsOnlyChildField(f *ast.Field) bool

func IsOnlyChildrenField

func IsOnlyChildrenField(f *ast.Field) bool

func IsOnlyLinkField

func IsOnlyLinkField(f *ast.Field) bool

func IsPointerToArrayField

func IsPointerToArrayField(f *ast.Field) bool

func IsSingletonNode

func IsSingletonNode(n *ast.TypeSpec) bool

func IsStatusField

func IsStatusField(f *ast.Field) bool

func ParseFieldTags

func ParseFieldTags(tag string) *structtag.Tags

func ParseGenDecls

func ParseGenDecls(v *ast.Package, pkg *Package)

func ParseGraphQLFiles

func ParseGraphQLFiles(startPath string) map[string]string

ParseDSLNodes walks recursively through given path and looks for structs types definitions to add them to graph

func ParseGraphqlQuerySpecs

func ParseGraphqlQuerySpecs(pkgs Packages) map[string]nexus.GraphQLQuerySpec

func ParseGraphqlSpecs

func ParseGraphqlSpecs(pkgs Packages) map[string]nexus.GraphQLSpec

func SpecialCharsPresent

func SpecialCharsPresent(name string) bool

Types

type FieldAnnotation

type FieldAnnotation string

type GraphQlArg

type GraphQlArg struct {
	Name      string
	Type      string
	AliasType bool
}

type HTTPCodesResponse

type HTTPCodesResponse map[ResponseCode]HTTPResponse

HTTPCodesResponse code to response type.

type HTTPMethod

type HTTPMethod string

HTTPMethod type.

type HTTPMethodsResponses

type HTTPMethodsResponses map[HTTPMethod]HTTPCodesResponse

HTTPMethodsResponses to response mapping.

type HTTPResponse

type HTTPResponse struct {
	Description string `json:"description"`
}

HTTPResponse type.

type NexusSpec

type NexusSpec struct {
	Name  string
	Value *ast.CompositeLit
}

func GetNexusSpecs

func GetNexusSpecs(p Package, nexusType string) (specs []NexusSpec)

type Node

type Node struct {
	Name             string
	PkgName          string
	FullName         string
	CrdName          string
	IsSingleton      bool
	Imports          []*ast.ImportSpec
	TypeSpec         *ast.TypeSpec
	Parents          []string
	SingleChildren   map[string]Node
	MultipleChildren map[string]Node
	SingleLink       map[string]Node
	MultipleLink     map[string]Node
	GraphqlQuerySpec nexus.GraphQLQuerySpec
	GraphqlSpec      nexus.GraphQLSpec
}

func (*Node) Walk

func (node *Node) Walk(fn func(node *Node))

type NodeHelper

type NodeHelper struct {
	Name             string
	RestName         string
	Parents          []string
	Children         map[string]NodeHelperChild // CRD Name => NodeHelperChild
	Links            map[string]NodeHelperChild // FieldName => NodeHelperChild
	RestMappings     map[string]string
	IsSingleton      bool
	GraphqlQuerySpec nexus.GraphQLQuerySpec
	GraphqlSpec      nexus.GraphQLSpec
}

type NodeHelperChild

type NodeHelperChild struct {
	FieldName      string `json:"fieldName"`
	FieldNameGvk   string `json:"fieldNameGvk"`
	GoFieldNameGvk string `json:"goFieldNameGvk"`
	IsNamed        bool   `json:"isNamed"`
}

type NonNexusTypes

type NonNexusTypes struct {
	Types         map[string]ast.Decl
	Values        []string
	ExternalTypes []string
}

func ParseDSLNodes

func ParseDSLNodes(startPath string, baseGroupName string, packages Packages,
	graphqlQueries map[string]nexus.GraphQLQuerySpec) (map[string]Node, *NonNexusTypes, *token.FileSet)

ParseDSLNodes walks recursively through given path and looks for structs types definitions to add them to graph

type Package

type Package struct {
	Name     string
	FullName string
	Dir      string

	//new fields
	ModPath  string
	Pkg      ast.Package
	GenDecls []ast.GenDecl
	FileSet  *token.FileSet
}

func (*Package) GenDeclToString

func (p *Package) GenDeclToString(t *ast.GenDecl) (string, error)

func (*Package) GetConsts

func (p *Package) GetConsts() []*ast.ValueSpec

func (*Package) GetImportMap

func (p *Package) GetImportMap() map[string]string

func (*Package) GetImportStrings

func (p *Package) GetImportStrings() []string

func (*Package) GetImports

func (p *Package) GetImports() []*ast.ImportSpec

func (*Package) GetNexusNodes

func (p *Package) GetNexusNodes() []*ast.TypeSpec

func (*Package) GetNodes

func (p *Package) GetNodes() []*ast.TypeSpec

func (*Package) GetNonStructTypes

func (p *Package) GetNonStructTypes() []*ast.TypeSpec

func (*Package) GetStructs

func (p *Package) GetStructs() []*ast.TypeSpec

func (*Package) GetTypes

func (p *Package) GetTypes() []ast.GenDecl

func (*Package) IsVarPresent

func (p *Package) IsVarPresent(varName string) bool

func (*Package) TypeSpecToString

func (p *Package) TypeSpecToString(t *ast.TypeSpec) (string, error)

func (*Package) ValueSpecToString

func (p *Package) ValueSpecToString(t *ast.ValueSpec) (string, error)

type PackageNodeRelation

type PackageNodeRelation struct {
	Name  string
	IsMap bool
	Type  string
}

type Packages

type Packages map[string]Package

func ParseDSLPkg

func ParseDSLPkg(startPath string) Packages

ParseDSLPkg walks recursively through given path and looks for structs types definitions to add them to a Package map

type ResponseCode

type ResponseCode int

ResponseCode type.

type RestAPISpec

type RestAPISpec struct {
	Uris []RestURIs `json:"uris"`
}

type RestURIs

type RestURIs struct {
	Uri     string               `json:"uri"`
	Methods HTTPMethodsResponses `json:"methods"`
}

RestURIs and associated data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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