Documentation
¶
Index ¶
- type AddFields
- type AddObject
- type AnonymousEnumToExplicitType
- type AnonymousStructsToNamed
- type AppendCommentObjects
- type ConstantToEnum
- type DataqueryIdentification
- type DisjunctionInferMapping
- type DisjunctionOfAnonymousStructsToExplicit
- type DisjunctionToType
- type DisjunctionWithConstantToDefault
- type DisjunctionWithNullToOptional
- type DuplicateObject
- type FieldReference
- type FieldsSetDefault
- type FieldsSetNotRequired
- type FieldsSetRequired
- type FilterSchemas
- type FlattenDisjunctions
- type HintObject
- type InferEntrypoint
- type InlineObjectsWithTypes
- type NameAnonymousStruct
- type NotRequiredFieldAsNullableType
- type ObjectReference
- type ObjectReferences
- type Omit
- type OmitFields
- type Pass
- type Passes
- type PrefixEnumValues
- type PrefixObjectNames
- type RemoveIntersections
- type RenameNumericEnumValues
- type RenameObject
- type ReplaceReference
- type RetypeField
- type RetypeObject
- type SanitizeEnumMemberNames
- type SchemaSetEntrypoint
- type SchemaSetIdentifier
- type TrimEnumValues
- type UndiscriminatedDisjunctionToAny
- type Unspec
- type VisitObjectFunc
- type VisitSchemaFunc
- type VisitStructFieldFunc
- type VisitTypeFunc
- type Visitor
- func (visitor *Visitor) HasNewObject(ref ast.RefType) bool
- func (visitor *Visitor) RegisterNewObject(object ast.Object)
- func (visitor *Visitor) VisitArray(schema *ast.Schema, def ast.Type) (ast.Type, error)
- func (visitor *Visitor) VisitDisjunction(schema *ast.Schema, def ast.Type) (ast.Type, error)
- func (visitor *Visitor) VisitEnum(schema *ast.Schema, def ast.Type) (ast.Type, error)
- func (visitor *Visitor) VisitIntersection(schema *ast.Schema, def ast.Type) (ast.Type, error)
- func (visitor *Visitor) VisitMap(schema *ast.Schema, def ast.Type) (ast.Type, error)
- func (visitor *Visitor) VisitObject(schema *ast.Schema, object ast.Object) (ast.Object, error)
- func (visitor *Visitor) VisitRef(schema *ast.Schema, def ast.Type) (ast.Type, error)
- func (visitor *Visitor) VisitScalar(schema *ast.Schema, def ast.Type) (ast.Type, error)
- func (visitor *Visitor) VisitSchema(schema *ast.Schema) (*ast.Schema, error)
- func (visitor *Visitor) VisitSchemas(schemas ast.Schemas) (ast.Schemas, error)
- func (visitor *Visitor) VisitStruct(schema *ast.Schema, def ast.Type) (ast.Type, error)
- func (visitor *Visitor) VisitStructField(schema *ast.Schema, field ast.StructField) (ast.StructField, error)
- func (visitor *Visitor) VisitType(schema *ast.Schema, def ast.Type) (ast.Type, error)
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.
type AddObject ¶ added in v0.0.5
type AddObject struct {
Object ObjectReference
As ast.Type
}
AddObject adds a new object to a schema.
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.
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
}
```
type AppendCommentObjects ¶
type AppendCommentObjects struct {
Comment string
}
AppendCommentObjects appends the given comment to every object definition.
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.
type DataqueryIdentification ¶
type DataqueryIdentification struct {
}
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/
type DisjunctionOfAnonymousStructsToExplicit ¶
type DisjunctionOfAnonymousStructsToExplicit struct {
}
DisjunctionOfAnonymousStructsToExplicit looks for anonymous structs used as branches of disjunctions and turns them into explicitly named types.
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
}
```
type DisjunctionWithConstantToDefault ¶
type DisjunctionWithConstantToDefault struct {
}
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 ```
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.
type FieldReference ¶
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.
type FieldsSetNotRequired ¶
type FieldsSetNotRequired struct {
Fields []FieldReference
}
FieldsSetNotRequired rewrites the definition of given fields to mark them as nullable and not required.
type FieldsSetRequired ¶
type FieldsSetRequired struct {
Fields []FieldReference
}
FieldsSetRequired rewrites the definition of given fields to mark them as not nullable and required.
type FilterSchemas ¶
type FilterSchemas struct {
AllowedObjects []ObjectReference
}
FilterSchemas filters a schema to only include the allowed objects and their dependencies.
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
```
type HintObject ¶
type HintObject struct {
Object ObjectReference
Hints ast.JenniesHints
}
type InferEntrypoint ¶
type InferEntrypoint struct {
}
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
}
```
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.
type NotRequiredFieldAsNullableType ¶
type NotRequiredFieldAsNullableType struct {
}
NotRequiredFieldAsNullableType identifies all the struct fields marked as not `Required` and rewrites their `Type` to be `Nullable`.
type ObjectReference ¶
func ObjectReferenceFromString ¶
func ObjectReferenceFromString(ref string) (ObjectReference, error)
func (ObjectReference) AsRef ¶ added in v0.0.3
func (ref ObjectReference) AsRef() ast.RefType
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
type Omit ¶
type Omit struct {
Objects []ObjectReference
}
Omit rewrites schemas to omit the configured objects.
type OmitFields ¶ added in v0.0.20
type OmitFields struct {
Fields []FieldReference
}
OmitFields removes the selected fields from their object definition.
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") ```
type PrefixObjectNames ¶
type PrefixObjectNames struct {
Prefix string
}
PrefixObjectNames adds the given prefix to every object's name.
type RemoveIntersections ¶
type RemoveIntersections struct {
// contains filtered or unexported fields
}
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) ```
type RenameObject ¶
type RenameObject struct {
From ObjectReference
To string
}
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`.
type RetypeField ¶
type RetypeField struct {
Field FieldReference
As ast.Type
Comments []string
}
type RetypeObject ¶
type RetypeObject struct {
Object ObjectReference
As ast.Type
Comments []string
}
type SanitizeEnumMemberNames ¶
type SanitizeEnumMemberNames struct {
}
type SchemaSetEntrypoint ¶ added in v0.0.5
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.
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
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.
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.
type VisitObjectFunc ¶
type VisitSchemaFunc ¶
type VisitStructFieldFunc ¶
type VisitStructFieldFunc func(visitor *Visitor, schema *ast.Schema, field ast.StructField) (ast.StructField, error)
type VisitTypeFunc ¶
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) RegisterNewObject ¶
func (*Visitor) VisitArray ¶
func (*Visitor) VisitDisjunction ¶
func (*Visitor) VisitIntersection ¶
func (*Visitor) VisitObject ¶
func (*Visitor) VisitScalar ¶
func (*Visitor) VisitSchema ¶
func (*Visitor) VisitSchemas ¶
func (*Visitor) VisitStruct ¶
func (*Visitor) VisitStructField ¶
func (visitor *Visitor) VisitStructField(schema *ast.Schema, field ast.StructField) (ast.StructField, error)
Source Files
¶
- add_fields.go
- add_object.go
- anonymous_enum.go
- anonymous_structs_to_named.go
- append_comment_objects.go
- compiler.go
- constant_to_enum.go
- dataquery_identification.go
- disjunction_with_constant_to_default.go
- disjunctions.go
- disjunctions_infer_mapping.go
- disjunctions_of_anonymous_to_explicit.go
- disjunctions_with_null_to_optional.go
- duplicate_object.go
- fields_set_default.go
- fields_set_not_required.go
- fields_set_required.go
- filter_schemas.go
- flatten_disjunctions.go
- hint_object.go
- infer_entrypoint.go
- inline_objects_with_types.go
- name_anonymous_struct.go
- not_required_as_nullable.go
- omit.go
- omit_fields.go
- prefix_enum_values.go
- prefix_objects_names.go
- remove_intersections.go
- rename_numeric_enum_values.go
- rename_object.go
- replace_reference.go
- retype_field.go
- retype_object.go
- sanitize_enum_member_names.go
- schema_set_entrypoint.go
- schema_set_identifier.go
- trim_enum_values.go
- types.go
- undiscriminated_disjunctions_to_any.go
- unspec.go
- visitor.go