Skip to content

Commit

Permalink
[codegen/pcl] Allow missing object properties.
Browse files Browse the repository at this point in the history
Add an option to allow missing object properties. This will prevent us
from losing examples once resource typechecking is fixed (it is
currently unintentionally disabled because the resource inputs object
type has an unexpected shape).
  • Loading branch information
pgavlin committed Jun 14, 2021
1 parent 63e129a commit 47df4ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions pkg/codegen/hcl2/binder.go
Expand Up @@ -29,9 +29,10 @@ import (
)

type bindOptions struct {
allowMissingVariables bool
loader schema.Loader
packageCache *PackageCache
allowMissingVariables bool
allowMissingProperties bool
loader schema.Loader
packageCache *PackageCache
}

func (opts bindOptions) modelOptions() []model.BindOption {
Expand All @@ -58,6 +59,10 @@ func AllowMissingVariables(options *bindOptions) {
options.allowMissingVariables = true
}

func AllowMissingProperties(options *bindOptions) {
options.allowMissingProperties = true
}

func PluginHost(host plugin.Host) BindOption {
return Loader(schema.NewPluginLoader(host))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/codegen/hcl2/binder_schema.go
Expand Up @@ -168,7 +168,7 @@ func (b *binder) schemaTypeToTypeImpl(src schema.Type, seen map[schema.Type]mode
seen[src] = objType
for _, prop := range src.Properties {
t := b.schemaTypeToTypeImpl(prop.Type, seen)
if !prop.IsRequired {
if !prop.IsRequired || b.options.allowMissingProperties {
t = model.NewOptionalType(t)
}
if prop.ConstValue != nil {
Expand Down

0 comments on commit 47df4ca

Please sign in to comment.