[schema] Add enum overlay support. (#8425)

And update the metaschema to accommodate the `isOverlay` properties
added in #8338. Overlay enums, like other overlay members, are
implemented out-of-band by the declaring package. Code generators should
not generate declarations for overlay enums.
This commit is contained in:
Pat Gavlin 2021-11-16 15:53:28 -08:00 committed by GitHub
parent ed769377dc
commit a1339277f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 173 additions and 22 deletions

View File

@ -11,6 +11,7 @@
- [schema] Add IsOverlay option to disable codegen for particular types
[#8338](https://github.com/pulumi/pulumi/pull/8338)
[#8425](https://github.com/pulumi/pulumi/pull/8425)
- [sdk/dotnet] - Marshal output values.
[#8316](https://github.com/pulumi/pulumi/pull/8316)

View File

@ -57,6 +57,14 @@ The description of the package. Descriptions are interpreted as Markdown.
---
### `displayName`
The human-friendly name of the package.
`string`
---
### `functions`
A map from token to functionSpec that describes the set of functions defined by this package.
@ -159,6 +167,14 @@ The provider type for this package.
---
### `publisher`
The name of the person or organization that authored and published the package.
`string`
---
### `repository`
The URL at which the package's sources can be found.
@ -361,6 +377,14 @@ The bag of input values for the function, if any.
---
#### `isOverlay`
Indicates that the implementation of the function should not be generated from the schema, and is instead provided out-of-band by the package author
`boolean`
---
#### `language`
Additional language-specific data about the function.
@ -661,7 +685,7 @@ Indicates whether the resource is a component.
#### `isOverlay`
Indicates whether the resource is an overlay (code is generated by the package rather than by the core Pulumi codegen).
Indicates that the implementation of the resource should not be generated from the schema, and is instead provided out-of-band by the package author
`boolean`
@ -699,7 +723,7 @@ An optional objectTypeSpec that describes additional inputs that mau be necessar
`string`
Pattern: `^[a-zA-Z][-a-zA-Z0-9_]*:([^0-9][a-zA-Z0-9._/]*)?:[^0-9][a-zA-Z0-9._/]*$`
Pattern: `^[a-zA-Z][-a-zA-Z0-9_]*:([^0-9][a-zA-Z0-9._/-]*)?:[^0-9][a-zA-Z0-9._/]*$`
## Type Definition
@ -721,6 +745,14 @@ The description of the type, if any. Interpreted as Markdown.
---
#### `isOverlay`
Indicates that the implementation of the type should not be generated from the schema, and is instead provided out-of-band by the package author
`boolean`
---
#### `language`
Additional language-specific data about the type.

View File

@ -2352,8 +2352,10 @@ func generateModuleContextMap(tool string, pkg *schema.Package) (map[string]*mod
mod := getModFromToken(typ.Token, pkg)
mod.types = append(mod.types, typ)
case *schema.EnumType:
mod := getModFromToken(typ.Token, pkg)
mod.enums = append(mod.enums, typ)
if !typ.IsOverlay {
mod := getModFromToken(typ.Token, pkg)
mod.enums = append(mod.enums, typ)
}
default:
continue
}

View File

@ -2769,8 +2769,10 @@ func generatePackageContextMap(tool string, pkg *schema.Package, goInfo GoPackag
}
populateDetailsForPropertyTypes(seenMap, typ.Properties, false)
case *schema.EnumType:
pkg := getPkgFromToken(typ.Token)
pkg.enums = append(pkg.enums, typ)
if !typ.IsOverlay {
pkg := getPkgFromToken(typ.Token)
pkg.enums = append(pkg.enums, typ)
}
}
}

View File

@ -10,6 +10,16 @@
},
"type": "object"
},
"example::EnumOverlay": {
"type": "string",
"enum": [
{
"name": "SomeEnumValue",
"value": "SOME_ENUM_VALUE"
}
],
"isOverlay": true
},
"example::ConfigMapOverlay": {
"isOverlay": true,
"properties": {
@ -25,11 +35,17 @@
"properties": {
"foo": {
"$ref": "#/types/example::ConfigMapOverlay"
},
"bar": {
"$ref": "#/types/example::EnumOverlay"
}
},
"inputProperties": {
"foo": {
"$ref": "#/types/example::ConfigMapOverlay"
},
"bar": {
"$ref": "#/types/example::EnumOverlay"
}
},
"type": "object"
@ -39,11 +55,17 @@
"properties": {
"foo": {
"$ref": "#/types/example::ConfigMapOverlay"
},
"bar": {
"$ref": "#/types/example::EnumOverlay"
}
},
"inputProperties": {
"foo": {
"$ref": "#/types/example::ConfigMapOverlay"
},
"bar": {
"$ref": "#/types/example::EnumOverlay"
}
},
"type": "object"

View File

@ -27,6 +27,7 @@ no_edit_this_page: true
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class=nd>@overload</span>
<span class="k">def </span><span class="nx">OverlayResource</span><span class="p">(</span><span class="nx">resource_name</span><span class="p">:</span> <span class="nx">str</span><span class="p">,</span>
<span class="nx">opts</span><span class="p">:</span> <span class="nx"><a href="/docs/reference/pkg/python/pulumi/#pulumi.ResourceOptions">Optional[ResourceOptions]</a></span> = None<span class="p">,</span>
<span class="nx">bar</span><span class="p">:</span> <span class="nx">Optional[EnumOverlay]</span> = None<span class="p">,</span>
<span class="nx">foo</span><span class="p">:</span> <span class="nx">Optional[ConfigMapOverlayArgs]</span> = None<span class="p">)</span>
<span class=nd>@overload</span>
<span class="k">def </span><span class="nx">OverlayResource</span><span class="p">(</span><span class="nx">resource_name</span><span class="p">:</span> <span class="nx">str</span><span class="p">,</span>
@ -157,6 +158,14 @@ The OverlayResource resource accepts the following [input]({{< relref "/docs/int
{{% choosable language csharp %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="bar_csharp">
<a href="#bar_csharp" style="color: inherit; text-decoration: inherit;">Bar</a>
</span>
<span class="property-indicator"></span>
<span class="property-type"><a href="#enumoverlay">Pulumi.<wbr>Example.<wbr>Enum<wbr>Overlay</a></span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd><dt class="property-optional"
title="Optional">
<span id="foo_csharp">
<a href="#foo_csharp" style="color: inherit; text-decoration: inherit;">Foo</a>
</span>
@ -169,6 +178,14 @@ The OverlayResource resource accepts the following [input]({{< relref "/docs/int
{{% choosable language go %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="bar_go">
<a href="#bar_go" style="color: inherit; text-decoration: inherit;">Bar</a>
</span>
<span class="property-indicator"></span>
<span class="property-type"><a href="#enumoverlay">Enum<wbr>Overlay</a></span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd><dt class="property-optional"
title="Optional">
<span id="foo_go">
<a href="#foo_go" style="color: inherit; text-decoration: inherit;">Foo</a>
</span>
@ -181,6 +198,14 @@ The OverlayResource resource accepts the following [input]({{< relref "/docs/int
{{% choosable language nodejs %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="bar_nodejs">
<a href="#bar_nodejs" style="color: inherit; text-decoration: inherit;">bar</a>
</span>
<span class="property-indicator"></span>
<span class="property-type"><a href="#enumoverlay">Enum<wbr>Overlay</a></span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd><dt class="property-optional"
title="Optional">
<span id="foo_nodejs">
<a href="#foo_nodejs" style="color: inherit; text-decoration: inherit;">foo</a>
</span>
@ -193,6 +218,14 @@ The OverlayResource resource accepts the following [input]({{< relref "/docs/int
{{% choosable language python %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="bar_python">
<a href="#bar_python" style="color: inherit; text-decoration: inherit;">bar</a>
</span>
<span class="property-indicator"></span>
<span class="property-type"><a href="#enumoverlay">Enum<wbr>Overlay</a></span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd><dt class="property-optional"
title="Optional">
<span id="foo_python">
<a href="#foo_python" style="color: inherit; text-decoration: inherit;">foo</a>
</span>
@ -317,6 +350,28 @@ All [input](#inputs) properties are implicitly available as output properties. A
<dd>{{% md %}}{{% /md %}}</dd></dl>
{{% /choosable %}}
<h4 id="enumoverlay">Enum<wbr>Overlay</h4>
{{% choosable language csharp %}}
<dl class="tabular"><dt>Some<wbr>Enum<wbr>Value</dt>
<dd>SOME_ENUM_VALUE</dd></dl>
{{% /choosable %}}
{{% choosable language go %}}
<dl class="tabular"><dt>Enum<wbr>Overlay<wbr>Some<wbr>Enum<wbr>Value</dt>
<dd>SOME_ENUM_VALUE</dd></dl>
{{% /choosable %}}
{{% choosable language nodejs %}}
<dl class="tabular"><dt>Some<wbr>Enum<wbr>Value</dt>
<dd>SOME_ENUM_VALUE</dd></dl>
{{% /choosable %}}
{{% choosable language python %}}
<dl class="tabular"><dt>SOME_ENUM_VALUE</dt>
<dd>SOME_ENUM_VALUE</dd></dl>
{{% /choosable %}}
<h2 id="package-details">Package Details</h2>
<dl class="package-details">

View File

@ -66,6 +66,16 @@
},
"type": "object"
},
"example::EnumOverlay": {
"type": "string",
"enum": [
{
"name": "SomeEnumValue",
"value": "SOME_ENUM_VALUE"
}
],
"isOverlay": true
},
"example::ConfigMapOverlay": {
"isOverlay": true,
"properties": {
@ -128,11 +138,17 @@
"properties": {
"foo": {
"$ref": "#/types/example::ConfigMapOverlay"
},
"bar": {
"$ref": "#/types/example::EnumOverlay"
}
},
"inputProperties": {
"foo": {
"$ref": "#/types/example::ConfigMapOverlay"
},
"bar": {
"$ref": "#/types/example::EnumOverlay"
}
},
"type": "object"

View File

@ -2200,9 +2200,11 @@ func generateModuleContextMap(tool string, pkg *schema.Package, extraFiles map[s
case *schema.ObjectType:
types.types = append(types.types, typ)
case *schema.EnumType:
info.ContainsEnums = true
mod := getModFromToken(typ.Token)
mod.enums = append(mod.enums, typ)
if !typ.IsOverlay {
info.ContainsEnums = true
mod := getModFromToken(typ.Token)
mod.enums = append(mod.enums, typ)
}
default:
continue
}

View File

@ -2722,8 +2722,10 @@ func generateModuleContextMap(tool string, pkg *schema.Package, info PackageInfo
mod.types = append(mod.types, typ)
}
case *schema.EnumType:
mod := getModFromToken(typ.Token, pkg)
mod.enums = append(mod.enums, typ)
if !typ.IsOverlay {
mod := getModFromToken(typ.Token, pkg)
mod.enums = append(mod.enums, typ)
}
default:
continue
}

View File

@ -311,7 +311,7 @@
"required": ["environment"]
},
"deprecationMessage": {
"description": "Indicates whether or not the property is deprecated",
"description": "Indicates whether the property is deprecated",
"type": "string"
},
"language": {
@ -340,6 +340,10 @@
"language": {
"description": "Additional language-specific data about the type.",
"type": "object"
},
"isOverlay": {
"description": "Indicates that the implementation of the type should not be generated from the schema, and is instead provided out-of-band by the package author",
"type": "boolean"
}
},
"oneOf": [
@ -409,7 +413,7 @@
"type": ["boolean", "integer", "number", "string"]
},
"deprecationMessage": {
"description": "Indicates whether or not the value is deprecated.",
"description": "Indicates whether the value is deprecated.",
"type": "string"
}
},
@ -472,11 +476,11 @@
}
},
"deprecationMessage": {
"description": "Indicates whether or not the resource is deprecated",
"description": "Indicates whether the resource is deprecated",
"type": "string"
},
"isComponent": {
"description": "Indicates whether or not the resource is a component.",
"description": "Indicates whether the resource is a component.",
"type": "boolean"
},
"methods": {
@ -485,6 +489,10 @@
"additionalProperties": {
"type": "string"
}
},
"isOverlay": {
"description": "Indicates that the implementation of the resource should not be generated from the schema, and is instead provided out-of-band by the package author",
"type": "boolean"
}
}
},
@ -506,12 +514,16 @@
"$ref": "#/$defs/objectTypeSpec"
},
"deprecationMessage": {
"description": "Indicates whether or not the function is deprecated",
"description": "Indicates whether the function is deprecated",
"type": "string"
},
"language": {
"description": "Additional language-specific data about the function.",
"type": "object"
},
"isOverlay": {
"description": "Indicates that the implementation of the function should not be generated from the schema, and is instead provided out-of-band by the package author",
"type": "boolean"
}
}
}

View File

@ -166,6 +166,10 @@ type EnumType struct {
Elements []*Enum
// ElementType is the underlying type for the enum.
ElementType Type
// IsOverlay indicates whether the type is an overlay provided by the package. Overlay code is generated by the
// package rather than using the core Pulumi codegen libraries.
IsOverlay bool
}
// Enum contains information about an enum.
@ -968,8 +972,8 @@ func (pkg *Package) MarshalYAML() ([]byte, error) {
return b.Bytes(), nil
}
func (pkg *Package) marshalObjectData(
comment string, properties []*Property, language map[string]interface{}, plain bool) (ObjectTypeSpec, error) {
func (pkg *Package) marshalObjectData(comment string, properties []*Property, language map[string]interface{},
plain, isOverlay bool) (ObjectTypeSpec, error) {
required, props, err := pkg.marshalProperties(properties, plain)
if err != nil {
@ -987,11 +991,12 @@ func (pkg *Package) marshalObjectData(
Type: "object",
Required: required,
Language: lang,
IsOverlay: isOverlay,
}, nil
}
func (pkg *Package) marshalObject(t *ObjectType, plain bool) (ComplexTypeSpec, error) {
data, err := pkg.marshalObjectData(t.Comment, t.Properties, t.Language, plain)
data, err := pkg.marshalObjectData(t.Comment, t.Properties, t.Language, plain, t.IsOverlay)
if err != nil {
return ComplexTypeSpec{}, err
}
@ -1010,17 +1015,16 @@ func (pkg *Package) marshalEnum(t *EnumType) ComplexTypeSpec {
}
return ComplexTypeSpec{
ObjectTypeSpec: ObjectTypeSpec{Type: pkg.marshalType(t.ElementType, false).Type},
ObjectTypeSpec: ObjectTypeSpec{Type: pkg.marshalType(t.ElementType, false).Type, IsOverlay: t.IsOverlay},
Enum: values,
}
}
func (pkg *Package) marshalResource(r *Resource) (ResourceSpec, error) {
object, err := pkg.marshalObjectData(r.Comment, r.Properties, r.Language, true)
object, err := pkg.marshalObjectData(r.Comment, r.Properties, r.Language, true, r.IsOverlay)
if err != nil {
return ResourceSpec{}, fmt.Errorf("marshaling properties: %w", err)
}
object.IsOverlay = r.IsOverlay
requiredInputs, inputs, err := pkg.marshalProperties(r.InputProperties, false)
if err != nil {
@ -2409,6 +2413,7 @@ func (t *types) bindEnumTypeDetails(enum *EnumType, token string, spec ComplexTy
enum.Elements = values
enum.ElementType = typ
enum.Comment = spec.Description
enum.IsOverlay = spec.IsOverlay
return diags
}