Skip to content

Commit

Permalink
Skip Microsoft.Network 2023-03-01-preview when generating the schema (#…
Browse files Browse the repository at this point in the history
…3102)

[networkManagerRoutingConfiguration.json](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/network/resource-manager/Microsoft.Network/preview/2023-03-01-preview/networkManagerRoutingConfiguration.json)
fails parsing with
`json: cannot unmarshal bool into Go struct field
SwaggerProps.definitions of type []string`

This change also moves the exclusion processing to before we read the
JSON, since that's where this failure is.

I was not able to see, so far, what's actually wrong with the file. It's
valid JSON but not what github.com/go-openapi/spec expects.

Fixes #3100
  • Loading branch information
thomas11 authored Feb 22, 2024
1 parent 6ec28dc commit 5ef3ac9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
7 changes: 4 additions & 3 deletions provider/cmd/pulumi-gen-azure-native/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func main() {
switch languages {
case "schema":
buildSchemaResult, buildSchemaErr := versioning.BuildSchema(buildSchemaArgs)
if buildSchemaErr != nil {
panic(buildSchemaErr)
}

if namespaces == "*" && apiVersions == "" {
written, err := buildSchemaResult.Version.WriteTo("versions")
Expand All @@ -96,9 +99,7 @@ func main() {
} else {
fmt.Println("Note: skipping writing version metadata and reports because DEBUG_CODEGEN_NAMESPACES or DEBUG_CODEGEN_APIVERSIONS is set.")
}
if buildSchemaErr != nil {
panic(buildSchemaErr)
}

if codegenSchemaOutputPath == "" {
codegenSchemaOutputPath = path.Join("bin", "schema-full.json")
}
Expand Down
20 changes: 15 additions & 5 deletions provider/pkg/openapi/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ func ReadAzureProviders(specsDir, namespace, apiVersions string) (AzureProviders
if err != nil {
return nil, diagnostics, errors.Wrapf(err, "failed to get relative path for %q", location)
}

if exclude(relLocation) {
continue
}

swagger, err := NewSpec(location)
if err != nil {
return nil, diagnostics, errors.Wrapf(err, "failed to parse %q", location)
Expand Down Expand Up @@ -452,17 +457,22 @@ var excludeRegexes = []*regexp.Regexp{
// servicefabricmanagedclusters/resource-manager/Microsoft.ServiceFabric/preview/2023-11-01-preview
// This causes a conflict in the version-specific folder, not the default version folder, so we have to completely exclude it.
regexp.MustCompile(".*servicefabric/resource-manager/Microsoft.ServiceFabric/preview/2023-11-01-preview.*"),
// This preview version is invalid OpenAPI JSON, reading it fails with encoding/json.UnmarshalTypeError in field "definitions".
regexp.MustCompile(".*network/resource-manager/Microsoft.Network/preview/2023-03-01-preview.*"),
}

// addAPIPath considers whether an API path contains resources and/or invokes and adds corresponding entries to the
// provider map. `providers` are mutated in-place.
func (providers AzureProviders) addAPIPath(specsDir, fileLocation, path string, swagger *Spec) DiscoveryDiagnostics {
func exclude(filePath string) bool {
for _, re := range excludeRegexes {
if re.MatchString(fileLocation) {
return DiscoveryDiagnostics{}
if re.MatchString(filePath) {
return true
}
}
return false
}

// addAPIPath considers whether an API path contains resources and/or invokes and adds corresponding entries to the
// provider map. `providers` are mutated in-place.
func (providers AzureProviders) addAPIPath(specsDir, fileLocation, path string, swagger *Spec) DiscoveryDiagnostics {
prov := resources.ResourceProvider(filepath.Join(specsDir, fileLocation), path)
if prov == "" {
return DiscoveryDiagnostics{}
Expand Down

0 comments on commit 5ef3ac9

Please sign in to comment.