Skip to content

Commit

Permalink
importer-rest-api-specs: normalize API resources after parsing all …
Browse files Browse the repository at this point in the history
…of them
  • Loading branch information
manicminer committed Jul 18, 2024
1 parent a55bf59 commit 8458a26
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func parseAPIResourcesFromFile(filePath, serviceName string, resourceProvider *s
}
}

// 3. Discriminator implementations that are defined in separate files with no link to a swagger tag
// 4. Discriminator implementations that are defined in separate files with no link to a swagger tag
// are not parsed. So far there are two known instances of this (Data Factory, Chaos Studio) where
// the files are defined in a nested directory e.g. d.Name = /Types/Capabilities
if len(parsedAPIResources) == 0 {
Expand All @@ -95,7 +95,6 @@ func parseAPIResourcesFromFile(filePath, serviceName string, resourceProvider *s
Constants: result.Constants,
Models: result.Models,
}
resource = cleanup.NormalizeAPIResource(resource)

discoveredResources := map[string]sdkModels.APIResource{
inferredTag: resource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ func parseAPIVersion(serviceName string, input discoveryModels.AvailableDataSetF
logging.Tracef("Processing API Definitions from file %q - Completed.", filePath)
}

// Normalize names of all operations, resource IDs, constants, models, and field names, ensuring they are
// appropriately Pascal cased. We are doing this after building out all the resources, since some references
// can get updated out-of-band and would subsequently be missed if we normalized immediately after parsing
// each resource.
for resourceName, resource := range apiResources {
apiResources[resourceName] = cleanup.NormalizeAPIResource(resource)
}

// Now that we have a canonical list of resources - can we simplify the Operation names at all?
for resourceName, resource := range apiResources {
logging.Tracef("Simplifying operation names for resource %q", resourceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

sdkModels "github.com/hashicorp/pandora/tools/data-api-sdk/v1/models"
"github.com/hashicorp/pandora/tools/importer-rest-api-specs/internal/components/apidefinitions/parser/cleanup"
"github.com/hashicorp/pandora/tools/importer-rest-api-specs/internal/components/apidefinitions/parser/commonschema"
parserModels "github.com/hashicorp/pandora/tools/importer-rest-api-specs/internal/components/apidefinitions/parser/models"
"github.com/hashicorp/pandora/tools/importer-rest-api-specs/internal/components/apidefinitions/parser/operation"
Expand Down Expand Up @@ -61,8 +60,5 @@ func (p *apiDefinitionsParser) ParseAPIResourceWithinSwaggerTag(tag, resourcePro
// then switch out any Common Schema Types (e.g. Identity)
resource = commonschema.ReplaceSDKObjectDefinitionsAsNeeded(resource)

// Normalize the names, ensuring they are appropriately Pascal cased
resource = cleanup.NormalizeAPIResource(resource)

return &resource, nil
}
2 changes: 1 addition & 1 deletion tools/importer-rest-api-specs/internal/pipeline/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func RunImporter(opts Options) error {
}
logging.Debugf("Completed - Clearing any existing API Definitions.")

logging.Infof("Processing the %d Services..", len(p.servicesFromConfigurationFiles))
logging.Infof("Processing %d Services..", len(p.servicesFromConfigurationFiles))
for _, service := range p.servicesFromConfigurationFiles {
if len(opts.ServiceNamesToLimitTo) > 0 {
processThisService := false
Expand Down

0 comments on commit 8458a26

Please sign in to comment.