Source files with header names that are reserved by the type system


#1

We have data source files where one of the headers is named type.

We created canonicals that have a field to match this header:

type Foo mixes Canonical<Foo> {
  type: string
}

However, we get this error when we try to provision:
[Message] Invalid metadata in tag Slooz in tenant project: in "?": Field type declared in Foo in module -type-Foo is reserved by the type system. Please use another name.

What’s the best way to resolve this?


#2

As the provisioning error says, type is a field name reserved by the type system. Just use a different name for that field.


#3

Our data source files have a header/field named type.

I believe the field within the canonical must match the name of the header/field within the data source files, and I can’t change the name of the type header/field within the data source files. Thus, I believe the field has to be named type within the .c3typ canonical.

I heard that there’s an annotation for this.


#4

You can use the ser annotation with it’s name field to resolve this.

For example:

type Foo mixes Canonical<Foo> {
  @ser(name='type')
  fooType: string
}

This will map the type field from the source file to the fooType field in the canonical.