Documentation
¶
Index ¶
- type AddFields
- type AnonymousEnumToExplicitType
- type AnonymousStructsToNamed
- type AppendCommentObjects
- type Cloudwatch
- type DashboardPanelsRewrite
- type DataqueryIdentification
- type DisjunctionInferMapping
- type DisjunctionOfAnonymousStructsToExplicit
- type DisjunctionToType
- type DisjunctionWithConstantToDefault
- type DisjunctionWithNullToOptional
- type FieldReference
- type FieldsSetDefault
- type FieldsSetNotRequired
- type FieldsSetRequired
- type FilterSchemas
- type FlattenDisjunctions
- type GoogleCloudMonitoring
- type HintObject
- type InferEntrypoint
- type InlineObjectsWithTypes
- type LibraryPanels
- type NameAnonymousStruct
- type NotRequiredFieldAsNullableType
- type ObjectReference
- type Omit
- type Pass
- type Passes
- type PrefixEnumValues
- type PrefixObjectNames
- type RemoveIntersections
- type RenameNumericEnumValues
- type RenameObject
- type RetypeField
- type RetypeObject
- type SanitizeEnumMemberNames
- type SchemaSetIdentifier
- type SetDatasourceToDataquery
- 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 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 Cloudwatch ¶
type Cloudwatch struct { }
Cloudwatch rewrites a part of the cloudwatch schema.
In that schema, the `QueryEditorExpression` type is defined as a disjunction for which the discriminator and mapping can not be inferred. This compiler pass is here to define that mapping.
The `QueryEditorArrayExpression` struct type is also modified to simplify the definition of its `expression` field from `[...#QueryEditorExpression] | [...#QueryEditorArrayExpression]` to `[...#QueryEditorExpression]`. This should be semantically equivalent since `#QueryEditorExpression` is a union type that includes `#QueryEditorArrayExpression`.
The Cloudwatch pass also alerts the definition of the `#CloudWatchMetricsQuery`, `#CloudWatchLogsQuery` and `#CloudWatchAnnotationQuery` types. It removes the "dataquery variant" hint they carry, and defines a `CloudWatchQuery` type instead as a disjunction. That disjunction serves as "dataquery entrypoint" for cloudwatch.
type DashboardPanelsRewrite ¶
type DashboardPanelsRewrite struct { }
DashboardPanelsRewrite rewrites the definition of "panels" fields in the "dashboard" package.
In the original schema, panels are defined as follows:
``` # In the Dashboard object panels?: [...#Panel | #RowPanel | #GraphPanel | #HeatmapPanel] # In the RowPanel object panels: [...#Panel | #GraphPanel | #HeatmapPanel] ```
These definitions become:
``` # In the Dashboard object panels?: [...#Panel | #RowPanel] # In the RowPanel object panels: [...#Panel] ```
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 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 GoogleCloudMonitoring ¶
type GoogleCloudMonitoring struct { }
GoogleCloudMonitoring rewrites a part of the googlecloudmonitoring schema.
Older schemas (pre 10.2.x) define `CloudMonitoringQuery.timeSeriesList` as a disjunction that cog can't handle: `timeSeriesList?: #TimeSeriesList | #AnnotationQuery`, where `AnnotationQuery` is a type that extends `TimeSeriesList` to add two fields.
This compiler pass checks for the presence of that disjunction, and rewrites it as a reference to `TimeSeriesList`. It also adds the two missing fields to this type if they aren't already defined.
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 LibraryPanels ¶
type LibraryPanels struct { }
LibraryPanels rewrites the definition of the "LibraryPanel" object in the "librarypanel" package.
In the original schema, the "model" field is left mainly undefined but a comment indicates that it should be the same panel schema defined in dashboard with a few fields omitted.
This compiler pass implements the modifications described in that comment to define the "model" field as:
``` # In the LibraryPanel object model: Omit<dashboard.Panel, 'gridPos' | 'id' | 'libraryPanel'> ```
Note: this pass needs the "dashboard.Panel" schema to be parsed. Barring that, it leaves the schemas untouched.
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) String ¶
func (ref ObjectReference) String() string
type Omit ¶
type Omit struct {
Objects []ObjectReference
}
Omit rewrites schemas to omit the configured objects.
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 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 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 SetDatasourceToDataquery ¶
type SetDatasourceToDataquery struct { }
SetDatasourceToDataquery uses dashboard.DataSourceRef reference for the datasource field in each dataquery.
Depending on the type of schema, this value can be an any or an internal Datasource struct generating an inconsistency between them.
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
- anonymous_enum.go
- anonymous_structs_to_named.go
- append_comment_objects.go
- cloudwatch.go
- compiler.go
- constants.go
- dashboardpanels.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
- fields_set_default.go
- fields_set_not_required.go
- fields_set_required.go
- filter_schemas.go
- flatten_disjunctions.go
- googlecloudmonitoring.go
- hint_object.go
- infer_entrypoint.go
- inline_objects_with_types.go
- librarypanels.go
- name_anonymous_struct.go
- not_required_as_nullable.go
- omit.go
- prefix_enum_values.go
- prefix_objects_names.go
- remove_intersections.go
- rename_numeric_enum_values.go
- rename_object.go
- retype_field.go
- retype_object.go
- sanitize_enum_member_names.go
- schema_set_identifier.go
- set_datasource_to_dataquery.go
- types.go
- undiscriminated_disjunctions_to_any.go
- unspec.go
- visitor.go