Skip to content

Commit

Permalink
[schema] Add IsOverlay option to disable codegen for particular resou…
Browse files Browse the repository at this point in the history
…rces
  • Loading branch information
lblackstone committed Nov 2, 2021
1 parent e629bc3 commit 9a11f17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/codegen/nodejs/gen.go
Expand Up @@ -1599,6 +1599,11 @@ func (mod *modContext) gen(fs fs) error {

// Resources
for _, r := range mod.resources {
if r.IsOverlay {
// This resource code is generated by the provider, so no further action is required.
return nil
}

externalImports, imports := codegen.NewStringSet(), map[string]codegen.StringSet{}
referencesNestedTypes := mod.getImportsForResource(r, externalImports, imports, r)

Expand Down Expand Up @@ -2225,6 +2230,11 @@ func LanguageResources(pkg *schema.Package) (map[string]LanguageResource, error)

for modName, mod := range modules {
for _, r := range mod.resources {
if r.IsOverlay {
// This resource code is generated by the provider, so no further action is required.
continue
}

packagePath := strings.Replace(modName, "/", ".", -1)
lr := LanguageResource{
Resource: r,
Expand Down
6 changes: 6 additions & 0 deletions pkg/codegen/schema/schema.go
Expand Up @@ -398,6 +398,8 @@ type Resource struct {
IsComponent bool
// Methods is the list of methods for the resource.
Methods []*Method
// IsOverlay indicates whether the resource code is an overlay provided by the package.
IsOverlay bool
}

// The set of resource paths where ReplaceOnChanges is true.
Expand Down Expand Up @@ -1046,6 +1048,7 @@ func (pkg *Package) marshalResource(r *Resource) (ResourceSpec, error) {
DeprecationMessage: r.DeprecationMessage,
IsComponent: r.IsComponent,
Methods: methods,
IsOverlay: r.IsOverlay,
}, nil
}

Expand Down Expand Up @@ -1429,6 +1432,8 @@ type ResourceSpec struct {
IsComponent bool `json:"isComponent,omitempty" yaml:"isComponent,omitempty"`
// Methods maps method names to functions in this schema.
Methods map[string]string `json:"methods,omitempty" yaml:"methods,omitempty"`
// IsOverlay indicates whether the resource code is an overlay provided by the package.
IsOverlay bool `json:"is_overlay,omitempty" yaml:"isOverlay,omitempty"`
}

// FunctionSpec is the serializable form of a function description.
Expand Down Expand Up @@ -2590,6 +2595,7 @@ func bindResource(path, token string, spec ResourceSpec, types *types,
Language: language,
IsComponent: spec.IsComponent,
Methods: methods,
IsOverlay: spec.IsOverlay,
}, diags, nil
}

Expand Down

0 comments on commit 9a11f17

Please sign in to comment.