compiler

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddFields

type AddFields struct {
	Object ObjectReference
	Fields []ast.StructField
}

AddFields rewrites the definition of an object to add new fields. Note: existing fields will not be overwritten.

func (*AddFields) Process

func (pass *AddFields) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type AddObject added in v0.0.5

type AddObject struct {
	Object ObjectReference
	As     ast.Type
}

AddObject adds a new object to a schema.

func (*AddObject) Process added in v0.0.5

func (pass *AddObject) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type AnonymousEnumToExplicitType

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

AnonymousEnumToExplicitType turns "anonymous enums" into a named object.

Example:

```
Panel struct {
	Type enum(Foo, Bar, Baz)
}
```

Will become:

```
Panel struct {
	Type PanelType
}

PanelType enum(Foo, Bar, Baz)
```

Note: this compiler pass looks for anonymous enums in structs and arrays only.

func (*AnonymousEnumToExplicitType) Process

func (pass *AnonymousEnumToExplicitType) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type AnonymousStructsToNamed

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

AnonymousStructsToNamed turns "anonymous structs" into a named object.

Example:

```
Panel struct {
	Options struct {
		Title string
	}
}
```

Will become:

```
Panel struct {
	Options PanelOptions
}

PanelOptions struct {
	Title string
}
```

func (*AnonymousStructsToNamed) Process

func (pass *AnonymousStructsToNamed) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type AppendCommentObjects

type AppendCommentObjects struct {
	Comment string
}

AppendCommentObjects appends the given comment to every object definition.

func (*AppendCommentObjects) Process

func (pass *AppendCommentObjects) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type ConstantToEnum added in v0.0.18

type ConstantToEnum struct {
	Objects ObjectReferences
}

ConstantToEnum turns `string` constants into an enum definition with a single member. This is useful to "future-proof" a schema where a type can have a single value for now but is expected to allow more in the future.

func (*ConstantToEnum) Process added in v0.0.18

func (pass *ConstantToEnum) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type DataqueryIdentification

type DataqueryIdentification struct {
}

func (*DataqueryIdentification) Process

func (pass *DataqueryIdentification) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type DisjunctionInferMapping

type DisjunctionInferMapping struct {
}

DisjunctionInferMapping infers the discriminator field and mapping used to describe a disjunction of references. See https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/

func (*DisjunctionInferMapping) Process

func (pass *DisjunctionInferMapping) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type DisjunctionOfAnonymousStructsToExplicit

type DisjunctionOfAnonymousStructsToExplicit struct {
}

DisjunctionOfAnonymousStructsToExplicit looks for anonymous structs used as branches of disjunctions and turns them into explicitly named types.

func (*DisjunctionOfAnonymousStructsToExplicit) Process

func (pass *DisjunctionOfAnonymousStructsToExplicit) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type DisjunctionToType

type DisjunctionToType struct {
}

DisjunctionToType transforms disjunction into a struct, mapping disjunction branches to an optional and nullable field in that struct.

Example:

	```
	SomeType: {
		type: "some-type"
 	}
	SomeOtherType: {
		type: "other-type"
 	}
	SomeStruct: {
		foo: string | bool
	}
	OtherStruct: {
		bar: SomeType | SomeOtherType
	}
	```

Will become:

	```
	SomeType: {
		type: "some-type"
 	}
	SomeOtherType: {
		type: "other-type"
 	}
	StringOrBool: {
		string: *string
		bool: *string
	}
	SomeStruct: {
		foo: StringOrBool
	}
	SomeTypeOrSomeOtherType: {
		SomeType: *SomeType
		SomeOtherType: *SomeOtherType
	}
	OtherStruct: {
		bar: SomeTypeOrSomeOtherType
	}
	```

func (*DisjunctionToType) Process

func (pass *DisjunctionToType) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type DisjunctionWithConstantToDefault

type DisjunctionWithConstantToDefault struct {
}

func (*DisjunctionWithConstantToDefault) Process

func (pass *DisjunctionWithConstantToDefault) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type DisjunctionWithNullToOptional

type DisjunctionWithNullToOptional struct {
}

DisjunctionWithNullToOptional simplifies disjunctions with two branches, where one is `null`. For those, it transforms `type | null` into `*type` (optional, nullable reference to `type`).

Example:

```
MaybeString: string | null
```

Will become:

```
MaybeString?: string
```

func (*DisjunctionWithNullToOptional) Process

func (pass *DisjunctionWithNullToOptional) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type DuplicateObject added in v0.0.3

type DuplicateObject struct {
	Object     ObjectReference
	As         ObjectReference
	OmitFields []string
	// contains filtered or unexported fields
}

DuplicateObject duplicates the source object. The duplicate is created under a different name, possibly in a different package.

Note: if the source object isn't found, this pass does nothing.

func (*DuplicateObject) Process added in v0.0.3

func (pass *DuplicateObject) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type FieldReference

type FieldReference struct {
	Package string
	Object  string
	Field   string
}

func FieldReferenceFromString

func FieldReferenceFromString(ref string) (FieldReference, error)

func (FieldReference) Matches

func (ref FieldReference) Matches(object ast.Object, field ast.StructField) bool

type FieldsSetDefault

type FieldsSetDefault struct {
	DefaultValues map[FieldReference]any
}

FieldsSetDefault sets the default value for the given fields.

func (*FieldsSetDefault) Process

func (pass *FieldsSetDefault) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type FieldsSetNotRequired

type FieldsSetNotRequired struct {
	Fields []FieldReference
}

FieldsSetNotRequired rewrites the definition of given fields to mark them as nullable and not required.

func (*FieldsSetNotRequired) Process

func (pass *FieldsSetNotRequired) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type FieldsSetRequired

type FieldsSetRequired struct {
	Fields []FieldReference
}

FieldsSetRequired rewrites the definition of given fields to mark them as not nullable and required.

func (*FieldsSetRequired) Process

func (pass *FieldsSetRequired) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type FilterSchemas

type FilterSchemas struct {
	AllowedObjects []ObjectReference
}

FilterSchemas filters a schema to only include the allowed objects and their dependencies.

func (*FilterSchemas) Process

func (pass *FilterSchemas) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type FlattenDisjunctions

type FlattenDisjunctions struct {
}

FlattenDisjunctions will traverse all the branches every given disjunctions and, for each disjunction it finds, flatten it into the top-level type.

Example:

```
SomeStruct: {
	foo: string
}
OtherStruct: {
	bar: string
}
LastStruct: {
	hello: string
}
SomeOrOther: SomeStruct | OtherStruct
AnyStruct: SomeOrOther | LastStruct
```

Will become:

```
SomeStruct: {
	foo: string
}
OtherStruct: {
	bar: string
}
LastStruct: {
	hello: string
}
SomeOrOther: SomeStruct | OtherStruct
AnyStruct: SomeStruct | OtherStruct | LastStruct # this disjunction has been flattened
```

func (*FlattenDisjunctions) Process

func (pass *FlattenDisjunctions) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type HintObject

type HintObject struct {
	Object ObjectReference
	Hints  ast.JenniesHints
}

func (*HintObject) Process

func (pass *HintObject) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type InferEntrypoint

type InferEntrypoint struct {
}

func (*InferEntrypoint) Process

func (pass *InferEntrypoint) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type InlineObjectsWithTypes

type InlineObjectsWithTypes struct {
	InlineTypes []ast.Kind
	// contains filtered or unexported fields
}

InlineObjectsWithTypes inlines objects of the given types. This compiler pass is meant to be used to generate code in languages that don't support type aliases on scalars, top-level disjunctions, ...

Note: constants are not impacted.

Example:

```
TimeZone string
Details map[string, any]
Targets []string

Foo struct {
  TimezoneField TimeZone
  DetailsField Details
  TargetsField Targets
}
```

Will become:

```
Foo struct {
  TimezoneField string
  DetailsField map[string, any]
  TargetsField []string
}
```

func (*InlineObjectsWithTypes) Process

func (pass *InlineObjectsWithTypes) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type NameAnonymousStruct

type NameAnonymousStruct struct {
	Field FieldReference
	As    string
}

NameAnonymousStruct rewrites the definition of a struct field typed as an anonymous struct to instead refer to a named type.

func (*NameAnonymousStruct) Process

func (pass *NameAnonymousStruct) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type NotRequiredFieldAsNullableType

type NotRequiredFieldAsNullableType struct {
}

NotRequiredFieldAsNullableType identifies all the struct fields marked as not `Required` and rewrites their `Type` to be `Nullable`.

func (*NotRequiredFieldAsNullableType) Process

func (pass *NotRequiredFieldAsNullableType) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type ObjectReference

type ObjectReference struct {
	Package string
	Object  string
}

func ObjectReferenceFromString

func ObjectReferenceFromString(ref string) (ObjectReference, error)

func (ObjectReference) AsRef added in v0.0.3

func (ref ObjectReference) AsRef() ast.RefType

func (ObjectReference) Matches

func (ref ObjectReference) Matches(object ast.Object) bool

func (ObjectReference) MatchesRef added in v0.0.19

func (ref ObjectReference) MatchesRef(refType ast.RefType) bool

func (ObjectReference) String

func (ref ObjectReference) String() string

type ObjectReferences added in v0.0.18

type ObjectReferences []ObjectReference

func (ObjectReferences) Matches added in v0.0.18

func (refs ObjectReferences) Matches(object ast.Object) bool

type Omit

type Omit struct {
	Objects []ObjectReference
}

Omit rewrites schemas to omit the configured objects.

func (*Omit) Process

func (pass *Omit) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type OmitFields added in v0.0.20

type OmitFields struct {
	Fields []FieldReference
}

OmitFields removes the selected fields from their object definition.

func (*OmitFields) Process added in v0.0.20

func (pass *OmitFields) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type Pass

type Pass interface {
	Process(schemas []*ast.Schema) ([]*ast.Schema, error)
}

type Passes

type Passes []Pass

func (Passes) Concat

func (passes Passes) Concat(other Passes) Passes

func (Passes) Process

func (passes Passes) Process(schemas ast.Schemas) (ast.Schemas, error)

type PrefixEnumValues

type PrefixEnumValues struct {
}

PrefixEnumValues prefixes enum members with the name of the enum object in which they are defined.

Example:

```
VariableRefresh enum(Never: "never", Always: "always")
```

Will become:

```
VariableRefresh enum(VariableRefreshNever: "never", VariableRefreshAlways: "always")
```

func (*PrefixEnumValues) Process

func (pass *PrefixEnumValues) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type PrefixObjectNames

type PrefixObjectNames struct {
	Prefix string
}

PrefixObjectNames adds the given prefix to every object's name.

func (*PrefixObjectNames) Process

func (pass *PrefixObjectNames) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type RemoveIntersections

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

func (RemoveIntersections) Process

func (r RemoveIntersections) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type RenameNumericEnumValues

type RenameNumericEnumValues struct {
}

RenameNumericEnumValues turns any numeric enum member name to an alphanumeric name.

Example:

```
Position enum(0: 0, 1: 1, 2: 2)
```

Will become:

```
Position enum(N0: 0, N1: 1, N2: 2)
```

func (*RenameNumericEnumValues) Process

func (pass *RenameNumericEnumValues) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type RenameObject

type RenameObject struct {
	From ObjectReference
	To   string
}

func (*RenameObject) Process

func (pass *RenameObject) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type ReplaceReference added in v0.0.19

type ReplaceReference struct {
	From ObjectReference
	To   ObjectReference
}

ReplaceReference replaces any usage of the `From` reference by the one given in `To`.

func (*ReplaceReference) Process added in v0.0.19

func (pass *ReplaceReference) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type RetypeField

type RetypeField struct {
	Field    FieldReference
	As       ast.Type
	Comments []string
}

func (*RetypeField) Process

func (pass *RetypeField) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type RetypeObject

type RetypeObject struct {
	Object   ObjectReference
	As       ast.Type
	Comments []string
}

func (*RetypeObject) Process

func (pass *RetypeObject) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type SanitizeEnumMemberNames

type SanitizeEnumMemberNames struct {
}

func (*SanitizeEnumMemberNames) Process

func (pass *SanitizeEnumMemberNames) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type SchemaSetEntrypoint added in v0.0.5

type SchemaSetEntrypoint struct {
	Package    string // we don't have a "clear" identifier, so we use the package to identify a schema.
	EntryPoint string
}

func (*SchemaSetEntrypoint) Process added in v0.0.5

func (pass *SchemaSetEntrypoint) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type SchemaSetIdentifier

type SchemaSetIdentifier struct {
	Package    string // we don't have a "clear" identifier, so we use the package to identify a schema.
	Identifier string
}

SchemaSetIdentifier overwrites the Metadata.Identifier field of a schema.

func (*SchemaSetIdentifier) Process

func (pass *SchemaSetIdentifier) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type TrimEnumValues added in v0.0.10

type TrimEnumValues struct {
}

TrimEnumValues removes leading and trailing spaces from string values. It could happen when they add them by mistake in jsonschema/openapi when they define the enums

func (TrimEnumValues) Process added in v0.0.10

func (t TrimEnumValues) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type UndiscriminatedDisjunctionToAny

type UndiscriminatedDisjunctionToAny struct {
}

UndiscriminatedDisjunctionToAny turns any undiscriminated disjunction into the `any` type. Disjunctions of scalars are not impacted, disjunctions having a configured discriminator field and mapping are not impacted (see DisjunctionInferMapping). Note: this pass _should_ run after DisjunctionInferMapping.

func (*UndiscriminatedDisjunctionToAny) Process

func (pass *UndiscriminatedDisjunctionToAny) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type Unspec

type Unspec struct {
}

Unspec removes the Kubernetes-style envelope added by kindsys.

Objects named "spec" will be renamed, using the package as new name.

func (*Unspec) Process

func (pass *Unspec) Process(schemas []*ast.Schema) ([]*ast.Schema, error)

type VisitObjectFunc

type VisitObjectFunc func(visitor *Visitor, schema *ast.Schema, object ast.Object) (ast.Object, error)

type VisitSchemaFunc

type VisitSchemaFunc func(visitor *Visitor, schema *ast.Schema) (*ast.Schema, error)

type VisitStructFieldFunc

type VisitStructFieldFunc func(visitor *Visitor, schema *ast.Schema, field ast.StructField) (ast.StructField, error)

type VisitTypeFunc

type VisitTypeFunc func(visitor *Visitor, schema *ast.Schema, def ast.Type) (ast.Type, error)

type Visitor

type Visitor struct {
	OnSchema       VisitSchemaFunc
	OnObject       VisitObjectFunc
	OnStructField  VisitStructFieldFunc
	OnArray        VisitTypeFunc
	OnMap          VisitTypeFunc
	OnStruct       VisitTypeFunc
	OnDisjunction  VisitTypeFunc
	OnIntersection VisitTypeFunc
	OnEnum         VisitTypeFunc
	OnScalar       VisitTypeFunc
	OnRef          VisitTypeFunc
	// contains filtered or unexported fields
}

func (*Visitor) HasNewObject

func (visitor *Visitor) HasNewObject(ref ast.RefType) bool

func (*Visitor) RegisterNewObject

func (visitor *Visitor) RegisterNewObject(object ast.Object)

func (*Visitor) VisitArray

func (visitor *Visitor) VisitArray(schema *ast.Schema, def ast.Type) (ast.Type, error)

func (*Visitor) VisitDisjunction

func (visitor *Visitor) VisitDisjunction(schema *ast.Schema, def ast.Type) (ast.Type, error)

func (*Visitor) VisitEnum

func (visitor *Visitor) VisitEnum(schema *ast.Schema, def ast.Type) (ast.Type, error)

func (*Visitor) VisitIntersection

func (visitor *Visitor) VisitIntersection(schema *ast.Schema, def ast.Type) (ast.Type, error)

func (*Visitor) VisitMap

func (visitor *Visitor) VisitMap(schema *ast.Schema, def ast.Type) (ast.Type, error)

func (*Visitor) VisitObject

func (visitor *Visitor) VisitObject(schema *ast.Schema, object ast.Object) (ast.Object, error)

func (*Visitor) VisitRef

func (visitor *Visitor) VisitRef(schema *ast.Schema, def ast.Type) (ast.Type, error)

func (*Visitor) VisitScalar

func (visitor *Visitor) VisitScalar(schema *ast.Schema, def ast.Type) (ast.Type, error)

func (*Visitor) VisitSchema

func (visitor *Visitor) VisitSchema(schema *ast.Schema) (*ast.Schema, error)

func (*Visitor) VisitSchemas

func (visitor *Visitor) VisitSchemas(schemas ast.Schemas) (ast.Schemas, error)

func (*Visitor) VisitStruct

func (visitor *Visitor) VisitStruct(schema *ast.Schema, def ast.Type) (ast.Type, error)

func (*Visitor) VisitStructField

func (visitor *Visitor) VisitStructField(schema *ast.Schema, field ast.StructField) (ast.StructField, error)

func (*Visitor) VisitType

func (visitor *Visitor) VisitType(schema *ast.Schema, def ast.Type) (ast.Type, error)

Jump to

Keyboard shortcuts

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