-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix non-deterministic behavior in generating schema (#104)
**CONTAINS BREAKING CHANGES** * Fix bug that caused non-deterministic behavior in generating functions for GET requests * BREAKING CHANGE! Get rid of using Title for resource names. Require operationId. * Add a test for discriminated type resources * Fix bug with simple property refs and add test for it * Reorganize the code for readability * Fix bug that caused non-determinism for allOf definitions under certain conditions * Don't skip non-object type allOf definitions that have yet another allOf definition * Add CSharp namespaces for all modules and not just for certain request methods * Generate language-specific overrides for non-camel-cased property names * Add tests for naming funcs * Upgrade deps and fix upgrade errors * Normalize prop names (#117) * Ensure property names in Pulumi schema are always camelCase * Update ToSdkName to use toCamelInitCase * Add name override for C# if the property name is the same as the enclosing type * Exclude id property from resource input/output when handling allOf definitions
- Loading branch information
1 parent
551fb45
commit ae0c6a2
Showing
17 changed files
with
1,973 additions
and
3,493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package pkg | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBug103(t *testing.T) { | ||
mustReadTestOpenAPIDoc(t, filepath.Join("testdata", "bug_103_openapi.yml")) | ||
|
||
openAPICtx := &OpenAPIContext{ | ||
Doc: *testOpenAPIDoc, | ||
Pkg: &testPulumiPkg, | ||
} | ||
|
||
csharpNamespaces := map[string]string{ | ||
"": "Provider", | ||
} | ||
|
||
providerMetadata, _, err := openAPICtx.GatherResourcesFromAPI(csharpNamespaces) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, providerMetadata) | ||
|
||
// apps_get_logs_active_deployment_aggregate | ||
_, ok := testPulumiPkg.Functions[packageName+":apps/v2:getAppsLogsActiveDeploymentAggregate"] | ||
assert.True(t, ok, "Expected to find function getAppsLogsActiveDeploymentAggregate in the Pulumi package spec") | ||
|
||
// apps_get_logs_aggregate | ||
_, ok = testPulumiPkg.Functions[packageName+":apps/v2:getAppsLogsAggregate"] | ||
assert.True(t, ok, "Expected to find function getAppsLogsAggregate in the Pulumi package spec") | ||
|
||
// projects_list_resources | ||
_, ok = testPulumiPkg.Functions[packageName+":projects/v2:listProjectsResources"] | ||
assert.True(t, ok, "Expected to find function listProjectsResources in the Pulumi package spec") | ||
|
||
// projects_list_resources_default | ||
_, ok = testPulumiPkg.Functions[packageName+":projects/v2:listProjectsResourcesDefault"] | ||
assert.True(t, ok, "Expected to find function listProjectsResourcesDefault in the Pulumi package spec") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package pkg | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Test to ensure resources with discriminated request body types | ||
// are generated with unique resource names if there is a collision. | ||
func TestBug104(t *testing.T) { | ||
mustReadTestOpenAPIDoc(t, filepath.Join("testdata", "bug_105_openapi.yml")) | ||
|
||
openAPICtx := &OpenAPIContext{ | ||
Doc: *testOpenAPIDoc, | ||
Pkg: &testPulumiPkg, | ||
} | ||
|
||
csharpNamespaces := map[string]string{ | ||
"": "Provider", | ||
} | ||
|
||
providerMetadata, _, err := openAPICtx.GatherResourcesFromAPI(csharpNamespaces) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, providerMetadata) | ||
|
||
_, ok := testPulumiPkg.Resources["fake-package:droplets/v2:DropletAction"] | ||
assert.False(t, ok, "Resource DropletAction should not exist") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package pkg | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestMultiplePathsUsingSameRef tests that a type used in an allOf | ||
// definition as well as a regular reference don't cause collisions. | ||
// In other words, the random order in which request paths in an API | ||
// spec are sometimes processed should not add/remove such a type | ||
// based on which request is processed first. | ||
func TestMultiplePathsUsingSameRef(t *testing.T) { | ||
mustReadTestOpenAPIDoc(t, filepath.Join("testdata", "multiple_paths_using_same_refs.yml")) | ||
|
||
openAPICtx := &OpenAPIContext{ | ||
Doc: *testOpenAPIDoc, | ||
Pkg: &testPulumiPkg, | ||
} | ||
|
||
csharpNamespaces := map[string]string{ | ||
"": "Provider", | ||
} | ||
|
||
count := 0 | ||
|
||
// Due to the non-deterministic nature of iterating the request | ||
// paths in the OpenAPI spec, we should execute this test a | ||
// few times to guarantee we are safe from the issue we are | ||
// testing for. | ||
for { | ||
if count >= 10 { | ||
break | ||
} | ||
_, _, err := openAPICtx.GatherResourcesFromAPI(csharpNamespaces) | ||
assert.Nil(t, err) | ||
|
||
assert.Contains(t, testPulumiPkg.Types, "fake-package:resources:Meta") | ||
|
||
count++ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package pkg | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestToSdkName(t *testing.T) { | ||
assert.Equal(t, "stringProp", ToSdkName("string_prop")) | ||
assert.Equal(t, "stringProp", ToSdkName("string.prop")) | ||
assert.Equal(t, "stringPropProp", ToSdkName("string.prop.prop")) | ||
} | ||
|
||
func TestStartsWithNumber(t *testing.T) { | ||
assert.True(t, startsWithNumber("1_var")) | ||
assert.True(t, startsWithNumber("1var")) | ||
assert.False(t, startsWithNumber("var")) | ||
} |
Oops, something went wrong.