Skip to content

Commit

Permalink
Prepare v3 version files (#3847)
Browse files Browse the repository at this point in the history
Extracted from the work on the `v3` branch:
#3846

This has no impact until the major version is changed in the makefile.
  • Loading branch information
thomas11 authored Jan 13, 2025
2 parents 896f531 + aa1b3c1 commit f4a80f0
Show file tree
Hide file tree
Showing 12 changed files with 1,486 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ dist/pulumi-azure-native_$(PROVIDER_VERSION)_checksums.txt: dist/$(PROVIDER)-v$(
@touch $@

.make/prebuild: .pulumi/bin/pulumi
cp -v versions/v${MAJOR_VERSION}-lock.json provider/pkg/versionLookup/
cp -v versions/v${MAJOR_VERSION}-lock.json provider/pkg/versionLookup/version-lock.json
@touch $@

define FAKE_MODULE
Expand Down
4 changes: 1 addition & 3 deletions provider/pkg/gen/exclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import (
// excludeResourcePatterns lists resources being skipped due to known codegen issues.
var excludeResourcePatterns = []string{
"azure-native:chaos:Experiment",
"azure-native:costmanagement:Budget",
"azure-native:costmanagement:Report",
"azure-native:datafactory:Pipeline", // go codegen goes full CPU and doesn't return

"azure-native:hybridcompute:GuestConfigurationHCRPAssignment", // python name mismatch
"azure-native:hybridcompute:GuestConfigurationHCRPAssignment", // python name mismatch
}
var excludeRegexes []*regexp.Regexp

Expand Down
17 changes: 12 additions & 5 deletions provider/pkg/gen/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ type genPropertiesVariant struct {
isType bool
// isResponse indicates that the properties are being generated for a response type.
isResponse bool
// isTopLevel indicates that the properties are being generated for a top-level resource rather than a referenced type.
isTopLevel bool
}

// noResponse returns a new copy of the variant with isResponse set to false.
func (v *genPropertiesVariant) noResponse() genPropertiesVariant {
// nestedWithoutResponse returns a new copy of the variant with isResponse set to false.
func (v *genPropertiesVariant) nestedWithoutResponse() genPropertiesVariant {
return genPropertiesVariant{
isTopLevel: false,
isOutput: v.isOutput,
isType: v.isType,
isResponse: false,
Expand Down Expand Up @@ -109,6 +112,10 @@ func (m *moduleGenerator) genProperties(resolvedSchema *openapi.Schema, variants
if clientName, ok := resolvedProperty.Extensions.GetString(extensionClientName); ok {
sdkName = firstToLower(clientName)
}
// Urn is a reserved word in our SDKs so we should avoid it on the resource itself.
if sdkName == "urn" && variants.isTopLevel {
sdkName = "urnValue"
}
// Change the name to lowerCamelCase.
sdkName = ToLowerCamel(sdkName)

Expand Down Expand Up @@ -137,7 +144,7 @@ func (m *moduleGenerator) genProperties(resolvedSchema *openapi.Schema, variants
}

if (ok && flatten && !isDict) || workaroundDelegatedNetworkBreakingChange {
bag, err := m.genProperties(resolvedProperty, variants.noResponse())
bag, err := m.genProperties(resolvedProperty, variants.nestedWithoutResponse())
if err != nil {
return nil, err
}
Expand All @@ -154,7 +161,7 @@ func (m *moduleGenerator) genProperties(resolvedSchema *openapi.Schema, variants
}
} else { // v3+: don't flatten when there are conflicts
if (ok && flatten && !isDict) || workaroundDelegatedNetworkBreakingChange {
bag, err := m.genProperties(resolvedProperty, variants.noResponse())
bag, err := m.genProperties(resolvedProperty, variants.nestedWithoutResponse())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -210,7 +217,7 @@ func (m *moduleGenerator) genProperties(resolvedSchema *openapi.Schema, variants
return nil, fmt.Errorf("failed to resolve allOf schema %d: %w", i, err)
}

allOfProperties, err := m.genProperties(allOfSchema, variants.noResponse())
allOfProperties, err := m.genProperties(allOfSchema, variants.nestedWithoutResponse())
if err != nil {
return nil, fmt.Errorf("failed to generate allOf properties %d: %w", i, err)
}
Expand Down
2 changes: 2 additions & 0 deletions provider/pkg/gen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@ func (m *moduleGenerator) genMethodParameters(parameters []spec.Parameter, ctx *

// The body parameter is flattened, so that all its properties become the properties of the type.
props, err := m.genProperties(bodySchema, genPropertiesVariant{
isTopLevel: true,
isOutput: false,
isType: false,
isResponse: false,
Expand Down Expand Up @@ -1514,6 +1515,7 @@ func (m *moduleGenerator) genResponse(statusCodeResponses map[int]spec.Response,
}

result, err := m.genProperties(responseSchema, genPropertiesVariant{
isTopLevel: true,
isOutput: true,
isType: false,
isResponse: true,
Expand Down
3 changes: 3 additions & 0 deletions provider/pkg/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ var moduleNameOverridesWithAliases = map[string]map[string]string{
"privatedns": "PrivateDns",
"trafficmanager": "TrafficManager",
},
"DocumentDB": {
"mongocluster": "MongoCluster",
},
}

// getNameOverride returns a name override for a given folder name, and non-prefixed namespace.
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/versionLookup/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
)

//go:embed v2-lock.json
//go:embed version-lock.json
var rawVersionLock []byte

// versionLock is a map from Azure provider name to resource name to API version.
Expand Down
Loading

0 comments on commit f4a80f0

Please sign in to comment.