Skip to content

Commit 766d3c8

Browse files
Mark up docs schema, and add language specific filter (#3188)
This pull request does several things: 1. Changes the `fixUpPropertyReference` function to mark up any such reference with a <span> tag that contains language-specific keys and values so a language-specific filter function can identify which value should be used for the language selected. The span looks as follows in the schema: `\u003cspan pulumi-lang-nodejs=\"`minUpper`\" pulumi-lang-dotnet=\"`MinUpper`\" pulumi-lang-go=\"`minUpper`\" pulumi-lang-python=\"`min_upper`\" pulumi-lang-yaml=\"`minUpper`\" pulumi-lang-java=\"`minUpper`\"\u003e`min_upper`\u003c/span\u003e` 2. Starts to fix a bug in `fixUpPropertyReference` where Dotnet was generating some property names in `snake_case` (TODO: proper capitalization for these property names is still missing) - see [example](https://github.com/pulumi/pulumi-random/pull/1869/files#diff-81676d671ec0f669c06325b0f7c93214146c124ccbf80cf9a624b183148b6059R51) 3. Creates a filter function that reads the provider's main schema from file and filters it for the correct language selectors on these spans and on the Pulumi Code Chooser (to avoid repeating examples translation), instead of re-generating the schema from scratch. 4. Adds new tests for `fixUpPropertyReference`; adds tests for the filter function. In this [pulumi-random PR](pulumi/pulumi-random#1869), you can see the changes to the SDK are minimal (the azure -> azurerm is unrelated; the Java changes are due to #3184 and haven't been rolled out to providers. Additional benefits: - We could use these spans in registry docsgen to fix up the broken default variable inflections there - Build time for the AWS Node SDK went from 130s to 26s; other SDKs are similar; smaller providers build the SDK almost instantaneously - Prompted us to build the Java SDK via pulumi package gen-sdk, reducing much future maintainer toil - it jsut comes for free with the Pulumi binary! - Paves the way for decoupling SDKgen from the terraform bridge in the future. This pull request does not address the following: - some conversion stat cleanup should happen for the SDK gen pass - we're still seeing conversion stat output, which is nonsensical. This can be in a separate pull request IMO. [I ran this against the AWS provider as well](pulumi/pulumi-aws#5825). The SDK inline documentation has a few extra empty section headers with this change, because we're not running the `description` field through the docs generator twice. **I think this is the correct bargain to make** - after this change, we can fix the docs rendering in _one_ place, and have the schema be the source of truth for everything. Fixes #1918.
1 parent c59b010 commit 766d3c8

File tree

39 files changed

+29664
-28513
lines changed

39 files changed

+29664
-28513
lines changed

dynamic/testdata/TestSchemaGeneration/Backblaze/b2-0.8.9.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
},
132132
"isFileLockEnabled": {
133133
"type": "boolean",
134-
"description": "If present, the boolean value specifies whether bucket is File Lock-enabled. Defaults to `false`.\n"
134+
"description": "If present, the boolean value specifies whether bucket is File Lock-enabled. Defaults to \u003cspan pulumi-lang-nodejs=\"`false`\" pulumi-lang-dotnet=\"`False`\" pulumi-lang-go=\"`false`\" pulumi-lang-python=\"`false`\" pulumi-lang-yaml=\"`false`\" pulumi-lang-java=\"`false`\"\u003e`false`\u003c/span\u003e.\n"
135135
}
136136
},
137137
"type": "object"

dynamic/testdata/TestSchemaGeneration/BunnyWay/bunnynet-0.5.1.golden

Lines changed: 16 additions & 16 deletions
Large diffs are not rendered by default.

dynamic/testdata/TestSchemaGeneration/hashicorp/random-3.3.0.golden

Lines changed: 71 additions & 71 deletions
Large diffs are not rendered by default.

dynamic/testdata/TestSchemaGenerationFullDocs/fortinetdev/fortimanager-1.13.0.golden

Lines changed: 28060 additions & 28060 deletions
Large diffs are not rendered by default.

dynamic/testdata/TestSchemaGenerationFullDocs/hashicorp/random-3.6.3.golden

Lines changed: 81 additions & 81 deletions
Large diffs are not rendered by default.

pkg/pf/tests/internal/testprovider/cmd/pulumi-resource-muxedrandom/schema.json

Lines changed: 79 additions & 79 deletions
Large diffs are not rendered by default.

pkg/pf/tests/internal/testprovider/cmd/pulumi-resource-random/schema.json

Lines changed: 79 additions & 79 deletions
Large diffs are not rendered by default.

pkg/pf/tests/internal/testprovider/cmd/pulumi-resource-testbridge/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@
804804
},
805805
"singleNestedAttrJsonCopy": {
806806
"type": "string",
807-
"description": "Computed as a JSON-ified copy of single_nested_attr input"
807+
"description": "Computed as a JSON-ified copy of\u003cspan pulumi-lang-nodejs=\" singleNestedAttr \" pulumi-lang-dotnet=\" SingleNestedAttr \" pulumi-lang-go=\" singleNestedAttr \" pulumi-lang-python=\" single_nested_attr \" pulumi-lang-yaml=\" singleNestedAttr \" pulumi-lang-java=\" singleNestedAttr \"\u003e single_nested_attr \u003c/span\u003einput"
808808
},
809809
"statedir": {
810810
"type": "string",
@@ -970,7 +970,7 @@
970970
},
971971
"singleNestedAttrJsonCopy": {
972972
"type": "string",
973-
"description": "Computed as a JSON-ified copy of single_nested_attr input"
973+
"description": "Computed as a JSON-ified copy of\u003cspan pulumi-lang-nodejs=\" singleNestedAttr \" pulumi-lang-dotnet=\" SingleNestedAttr \" pulumi-lang-go=\" singleNestedAttr \" pulumi-lang-python=\" single_nested_attr \" pulumi-lang-yaml=\" singleNestedAttr \" pulumi-lang-java=\" singleNestedAttr \"\u003e single_nested_attr \u003c/span\u003einput"
974974
},
975975
"statedir": {
976976
"type": "string",

pkg/pf/tests/internal/testprovider/cmd/pulumi-resource-tls/schema.json

Lines changed: 45 additions & 45 deletions
Large diffs are not rendered by default.

pkg/tests/schema_generation_test.go

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ func skipOnWindows(t *testing.T) {
127127
}
128128
}
129129

130-
func Test_Generate(t *testing.T) {
131-
t.Parallel()
130+
func Test_Generate(t *testing.T) { //nolint:paralleltest // Cannot run in parallel due to shared working directory for schema file
132131
skipOnWindows(t)
133132

134133
p := pulcheck.BridgedProvider(t, "prov", &schema.Provider{
@@ -153,6 +152,39 @@ func Test_Generate(t *testing.T) {
153152
root = afero.NewBasePathFs(afero.NewOsFs(), absOutDir)
154153
}
155154

155+
// First, generate the schema file that the NodeJS generator expects
156+
// Use a separate in-memory filesystem for schema generation to avoid conflicts
157+
schemaRoot := afero.NewMemMapFs()
158+
schemaGen, err := tfgen.NewGenerator(tfgen.GeneratorOptions{
159+
Package: "prov",
160+
Version: "0.0.1",
161+
ProviderInfo: p,
162+
Root: schemaRoot,
163+
Language: tfgen.Schema,
164+
XInMemoryDocs: true,
165+
SkipDocs: true,
166+
SkipExamples: true,
167+
Sink: sink,
168+
Debug: true,
169+
})
170+
require.NoError(t, err)
171+
172+
schemaResult, err := schemaGen.Generate()
173+
require.NoError(t, err)
174+
175+
// Write the schema to the expected location
176+
schemaBytes, err := json.MarshalIndent(schemaResult.PackageSpec, "", " ")
177+
require.NoError(t, err)
178+
179+
t.Chdir(outDir)
180+
// Create the directory structure and write the schema file in the current working directory
181+
// since the Generate() function uses os.ReadFile() which reads from the current working directory
182+
schemaDir := filepath.Join("provider", "cmd", "pulumi-resource-prov")
183+
require.NoError(t, os.MkdirAll(schemaDir, 0o755))
184+
schemaPath := filepath.Join(schemaDir, "schema.json")
185+
require.NoError(t, os.WriteFile(schemaPath, schemaBytes, 0o600))
186+
187+
// Now create the NodeJS generator and run it
156188
gen, err := tfgen.NewGenerator(tfgen.GeneratorOptions{
157189
Package: "prov",
158190
Version: "0.0.1",
@@ -193,8 +225,7 @@ func Test_Generate(t *testing.T) {
193225
require.NoError(t, err)
194226
}
195227

196-
func Test_GenerateWithOverlay(t *testing.T) {
197-
t.Parallel()
228+
func Test_GenerateWithOverlay(t *testing.T) { //nolint:paralleltest // Cannot run in parallel due to shared working directory for schema file
198229
skipOnWindows(t)
199230

200231
p := pulcheck.BridgedProvider(t, "prov", &schema.Provider{
@@ -380,6 +411,38 @@ func Test_GenerateWithOverlay(t *testing.T) {
380411
err = afero.WriteFile(root, filepath.Join(moduleName, tc.overlayModFileName), tc.overlayModFileContent, 0o600)
381412
require.NoError(t, err)
382413

414+
// First, generate the schema file that the language generator expects
415+
schemaRoot := afero.NewMemMapFs()
416+
schemaGen, err := tfgen.NewGenerator(tfgen.GeneratorOptions{
417+
Package: "prov",
418+
Version: "0.0.1",
419+
ProviderInfo: p,
420+
Root: schemaRoot,
421+
Language: tfgen.Schema,
422+
XInMemoryDocs: true,
423+
SkipDocs: true,
424+
SkipExamples: true,
425+
Sink: sink,
426+
Debug: true,
427+
})
428+
require.NoError(t, err)
429+
430+
schemaResult, err := schemaGen.Generate()
431+
require.NoError(t, err)
432+
433+
// Write the schema to the expected location
434+
schemaBytes, err := json.MarshalIndent(schemaResult.PackageSpec, "", " ")
435+
require.NoError(t, err)
436+
437+
t.Chdir(tempDir)
438+
// Create the directory structure and write the schema file in the current working directory
439+
// since the Generate() function uses os.ReadFile() which reads from the current working directory
440+
schemaDir := filepath.Join("provider", "cmd", "pulumi-resource-prov")
441+
require.NoError(t, os.MkdirAll(schemaDir, 0o755))
442+
schemaPath := filepath.Join(schemaDir, "schema.json")
443+
require.NoError(t, os.WriteFile(schemaPath, schemaBytes, 0o600))
444+
445+
// Now create the language-specific generator and run it
383446
gen, err := tfgen.NewGenerator(tfgen.GeneratorOptions{
384447
Package: "prov",
385448
Version: "0.0.1",

0 commit comments

Comments
 (0)