# README
show output schemas generation
These schemas are necessary to include SHOW output in every resource and datasource. The work is repetitive, so it's easier to just generate all the needed schemas and mappers.
Description
File generate.go invokes the generation logic from main.go. By default, all SDK show output struct are used (listed in sdk_show_result_structs.go). After successful generation all SDK objects will have:
- show output schema that can be used in the resource/datasource (e.g. warehouse_gen)
- mapper from the SDK object to the generated schema (e.g. warehouse_gen)
How it works
Invoking the generation
To generate all show outputs (with a cleanup first) run:
make clean-show-output-schemas generate-show-output-schemas
To generate only chosen subset of all objects run:
make clean-show-output-schemas generate-show-output-schemas SF_TF_GENERATOR_EXT_ALLOWED_OBJECT_NAMES="sdk.Warehouse,sdk.User"
Supported types
The following types are supported currently in the generator (schema and mappings):
- basic types (
string
,int
,float64
,bool
) - pointers to basic types (the same as above)
time.Time
(pointer too)- enums based on
string
andint
likesdk.WarehouseType
orsdk.ResourceMonitorLevel
(pointers too) - identifiers (pointers too):
sdk.AccountIdentifier
sdk.ExternalObjectIdentifier
sdk.AccountObjectIdentifier
sdk.DatabaseObjectIdentifier
sdk.SchemaObjectIdentifier
sdk.TableColumnIdentifier
sdk.ObjectIdentifier
interface
To schema mappings
Given SDK struct field can be mapped to the generated schema depending on its type:
- no mapping (
Identity
) - used forstring
and other basic types - string value mapping (
ToString
) - used e.g. fortime.Time
- fully qualified name mapping (
FullyQualifiedName
) - used for all identifiers andsdk.ObjectIdentifier
interface - casting (
CastToString
andCastToInt
) - used for enums with underlying typestring
orint
Changing the SDK object's show output
If you change the show output struct in the SDK:
- Check if you don't introduce a type that is unsupported (check supported types and known limitations).
- Run generation according to instructions.
Adding a new object to the SDK
- Add the new show output struct to sdk_show_result_structs.go.
- Check if you don't introduce a type that is unsupported (check supported types and known limitations).
- Run generation according to instructions.
Next steps
Known limitations
- The following types (already existing in the SDK show output structs) are not yet supported (for all of them the
schema will be generated with
schema.TypeInvalid
:- other basic types (e.g.
int8
, etc.) - slices of basic types (
[]int
,[]string
) - slices of identifiers (
[]sdk.AccountIdentifier
,[]sdk.SchemaObjectIdentifier
) - slices of enums (
[]sdk.IntegrationType
,[]sdk.PluralObjectType
) - structs (
sdk.FileFormatTypeOptions
)
- other basic types (e.g.
Improvements
Functional improvements:
- handle the missing types (TODOs in schema_field_mapper.go)
- parametrize the generation, e.g.:
- (optional) parametrize the output directory - currently, it's always written to
schemas
package
- (optional) parametrize the output directory - currently, it's always written to
- discover a change and generate as part of a
make pre-push
Implementation improvements:
- (optional) consider different implementations of
Mapper
(e.g. TODO in schema_field_mapper_test.go:ugly comparison of functions with the current implementation of mapper
and not ideal implementation in the to_schema_mapper.tmpl:runMapper .Mapper $nameLowerCase "." .OriginalName
)