fix: resolve OpenAPI $ref properties to strongly-typed Pulumi types - #901
fix: resolve OpenAPI $ref properties to strongly-typed Pulumi types#901pierskarsenbarg wants to merge 2 commits into
Conversation
Previously, `openAPIToType` in the REST schema builder immediately
converted any OpenAPI `$ref` property to `pulumi.json#/Any`, causing
SDK inputs/outputs that reference component schemas to be typed as `any`
in all generated SDKs. For example, `AuditLogExportConfiguration.newS3Configuration`
was `any` in TypeScript instead of a typed `AuditLogsExportS3ConfigArgs` interface.
Introduces a `typeBuilder` struct that carries `*Spec` and the output
`types` accumulator through the schema-building call chain. When a `$ref`
is encountered, it resolves the component schema, builds a named Pulumi
`ComplexTypeSpec`, registers it under `{pkg}:api:{Name}`, and returns a
`#/types/...` reference. A placeholder is written before recursing to
handle circular type references. All previously standalone functions
(`openAPIToProperty`, `openAPIToType`) are replaced by methods on
`typeBuilder` and threaded through `buildResource`, `buildAttachmentResource`,
`operationInputs`, `operationOutputs`, and `mergeEmitOnCreateOutputs`.
Regenerates schema.json and all language SDKs to reflect the new types.
Fixes #900
Does the PR have any schema changes?Found 62 breaking changes: Resources
Maintainer note: consult the runbook for dealing with any breaking changes. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #901 +/- ##
==========================================
+ Coverage 53.93% 54.05% +0.11%
==========================================
Files 82 82
Lines 9537 9570 +33
==========================================
+ Hits 5144 5173 +29
- Misses 3946 3948 +2
- Partials 447 449 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
One blocking finding inline: CHANGELOG.md was not updated despite the 69 user-facing schema/SDK changes this PR generates.
Reviewed by Internal Trusted PR Reviewer
Add this agentic workflows to your repo
To install this agentic workflow, run
gh aw add pulumi-labs/gh-aw-internal/.github/workflows/gh-aw-pr-review.md@8a92f53fac170563f7727cacab2dbedb5d5b9e29
|
|
||
| // typeBuilder accumulates Pulumi named types discovered while converting | ||
| // OpenAPI $ref properties, and resolves them recursively. | ||
| type typeBuilder struct { |
There was a problem hiding this comment.
CHANGELOG.md is not updated. Per CLAUDE.md: "Always update CHANGELOG.md when making code changes that affect users." The schema-check bot reported 69 user-facing schema changes here (properties moving from pulumi.json#/Any to typed #/types/... refs), which alter SDK type signatures across every language SDK (e.g. AuditLogExportConfiguration.newS3Configuration is now AuditLogsExportS3ConfigArgs instead of any). Add an entry under ## Unreleased — either ### Improvements (strengthens types on the api: Preview surface) or ### Breaking Changes (existing user code typed against any may need updates), matching the precedent of other pulumiservice:api:* entries.
The discriminator-based schema fix caused PermissionDescriptor (and other discriminated union types) to revert to `pulumi.json#/Any`, while other OpenAPI $ref types became strongly-typed named types. This required updating all language examples in examples/api/ to use the new typed inputs and correct field names. Changes in provider/pkg/rest/schema.go: detect OpenAPI discriminator fields and fall back to Any rather than generating an unusable named type whose Go struct has an unexported __type field that callers cannot set. Regenerated schema.json and all SDKs to remove PermissionDescriptor* types and update fields that changed from any to typed objects (e.g. executorImage is now DockerImageRequest instead of a plain string). Updated all six language examples for audit-log-export (fix s3BucketName / iamRoleArn field names), auth-policy (fix authorizedPermissions array, add rules), service (fix type/name fields on items, add type/order on properties), and deployment-settings (wrap executorImage in DockerImageRequest object).
Summary
OpenAPI
$refproperties on auto-generated REST resources were typed asanyin all generated SDKs because the schema builder discarded the reference without resolving it. This fixes the root cause so that component schema types are properly resolved, registered, and referenced. Fixes #900.Changes
provider/pkg/rest/schema.go: Introduces atypeBuilderstruct that carries*Specand the outputtypesaccumulator through the schema-building call chain. When a$refis encountered, it resolves the component schema, builds a named PulumiComplexTypeSpecunder{pkg}:api:{Name}, and returns a#/types/...reference. A placeholder is written before recursing to handle circular type references. Replaces the standaloneopenAPIToProperty/openAPIToTypefunctions with methods ontypeBuilder, threaded throughbuildResource,buildAttachmentResource,operationInputs,operationOutputs, andmergeEmitOnCreateOutputs.provider/pkg/rest/schema_test.go: AddsTestRefPropertyResolvesToNamedTypeto verify that a$refproperty produces a#/types/...ref and the type is registered in the types map.provider/cmd/pulumi-resource-pulumiservice/schema.json: Regenerated — now includes a populatedtypessection with all component schemas referenced by API resources.sdk/: All language SDKs regenerated. For example,AuditLogExportConfiguration.newS3Configurationis nowpulumi.Input<inputs.api.AuditLogsExportS3ConfigArgs>in TypeScript instead ofany.Test Plan
go test ./provider/pkg/rest/... -count=1passes, including the newTestRefPropertyResolvesToNamedTypetestmise exec -- make lintpasses with 0 issuesmake providerrebuilds successfullyinputs.api.AuditLogsExportS3ConfigArgs), Python (AuditLogsExportS3ConfigArgs), and Go (AuditLogsExportS3Configstruct)