Skip to content

Commit

Permalink
Ensure enum names are prefixed with the resource name from the context (
Browse files Browse the repository at this point in the history
  • Loading branch information
praneetloke authored May 17, 2024
1 parent fea6fa7 commit 7268a52
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,33 @@ func (o *OpenAPIContext) gatherResourceProperties(resourceName string, requestBo
addNameOverride(propName, sdkName, o.apiToSDKNameMap)
}

// If the cloud API nests the response inside a property
// using the name of the resource, it'll certainly cause
// a failure in generating the .NET SDK but we don't set
// the Pulumi languageOverride for them because it doesn't
// make sense from an end-user perspective to nest the output
// inside another property. It lends to a bad dev UX.
// So providers should actually pluck the nested property
// in both the OpenAPI spec, as well as in the provider
// callbacks.
//
// For example, say, you have a resource called `Database`
// and the response from the API looks like this:
// ```json
// {
// "database":{...}
// }
// ```
// If left unmodified, then the Pulumi resource would
// have an output property called `database` in addition
// to all the input properties also being outputs.
// That means, the user would get this:
// ```typescript
// const db = new Database("db", {someProp:""}); <-- someProp could be an input
// db.database.someProp; <-- someProp is returned by the API in response to create the resource, which is normal.
// db.someProp; <-- input property again accessible as output.
// ```

// Don't add `id` to the output properties since Pulumi
// automatically adds that via `CustomResource` which
// is what all resources in the SDK will extend.
Expand Down Expand Up @@ -1322,6 +1349,9 @@ func (ctx *resourceContext) genEnumType(enumName string, propSchema openapi3.Sch
}

typName := ToPascalCase(enumName)
if !strings.HasPrefix(typName, ctx.resourceName) {
typName = ctx.resourceName + enumName
}
tok := fmt.Sprintf("%s:%s:%s", ctx.pkg.Name, ctx.mod, typName)

enumSpec := &pschema.ComplexTypeSpec{
Expand Down

0 comments on commit 7268a52

Please sign in to comment.