Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/importer-rest-api-specs: Resource ID parsing now returns map[OperationID]ParsedOperation rather than map[Uri]ParsedOperation #3203

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 0 additions & 73 deletions tools/importer-rest-api-specs/components/differ/apply.go

This file was deleted.

18 changes: 0 additions & 18 deletions tools/importer-rest-api-specs/components/differ/client.go

This file was deleted.

134 changes: 0 additions & 134 deletions tools/importer-rest-api-specs/components/differ/load_existing.go

This file was deleted.

16 changes: 0 additions & 16 deletions tools/importer-rest-api-specs/components/differ/stages.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cleanup

import (
"fmt"
"log"
"strings"

"github.com/gertd/go-pluralize"
Expand Down Expand Up @@ -31,7 +30,6 @@ func GetSingular(input string) string {
}
for _, v := range invariablePlurals() {
if strings.EqualFold(input, v) {
log.Printf("got %q returning %q", input, returnCased(v, casing))
return returnCased(v, casing)
}
}
Expand Down
36 changes: 11 additions & 25 deletions tools/importer-rest-api-specs/components/parser/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
)

type operationsParser struct {
operations []parsedOperation
urisToResourceIds map[string]resourceids.ParsedOperation
swaggerDefinition *SwaggerDefinition
operations []parsedOperation
operationIdsToParsedOperations map[string]resourceids.ParsedOperation
swaggerDefinition *SwaggerDefinition
}

func (d *SwaggerDefinition) parseOperationsWithinTag(tag *string, urisToResourceIds map[string]resourceids.ParsedOperation, resourceProvider *string, found internal.ParseResult) (*map[string]models.OperationDetails, *internal.ParseResult, error) {
func (d *SwaggerDefinition) parseOperationsWithinTag(tag *string, operationIdsToParsedOperations map[string]resourceids.ParsedOperation, resourceProvider *string, found internal.ParseResult) (*map[string]models.OperationDetails, *internal.ParseResult, error) {
logger := d.logger.Named("Operations Parser")
operations := make(map[string]models.OperationDetails, 0)
result := internal.ParseResult{
Expand All @@ -32,8 +32,8 @@ func (d *SwaggerDefinition) parseOperationsWithinTag(tag *string, urisToResource
result.Append(found)

parser := operationsParser{
urisToResourceIds: urisToResourceIds,
swaggerDefinition: d,
operationIdsToParsedOperations: operationIdsToParsedOperations,
swaggerDefinition: d,
}

// first find the operations then pull out everything we can
Expand All @@ -57,7 +57,7 @@ func (d *SwaggerDefinition) parseOperationsWithinTag(tag *string, urisToResource
}

if existing, hasExisting := operations[operation.name]; hasExisting {
return nil, nil, fmt.Errorf("conflicting operations with the Name %q - first %q %q - second %q %q", operation.name, existing.Method, existing.Uri, parsedOperation.Method, parsedOperation.Uri)
return nil, nil, fmt.Errorf("conflicting operations with the Name %q - first %q %q - second %q %q", operation.name, existing.Method, existing.OperationId, parsedOperation.Method, parsedOperation.OperationId)
}

if parsedOperation == nil {
Expand All @@ -76,16 +76,12 @@ func (p operationsParser) parseOperation(operation parsedOperation, resourceProv
Models: map[string]models.ModelDetails{},
}

normalizedUri, err := p.normalizedUriForOperation(operation)
if err != nil {
return nil, nil, fmt.Errorf("determining the normalized uri: %+v", err)
}
contentType := p.determineContentType(operation)
expectedStatusCodes := p.expectedStatusCodesForOperation(operation)
paginationField := p.fieldContainingPaginationDetailsForOperation(operation)
requestObject, nestedResult, err := p.requestObjectForOperation(operation, result)
if err != nil {
return nil, nil, fmt.Errorf("determining request operation for %q (method %q / uri %q): %+v", operation.name, operation.httpMethod, *normalizedUri, err)
return nil, nil, fmt.Errorf("determining request operation for %q (method %q / ID %q): %+v", operation.name, operation.httpMethod, operation.operation.ID, err)
}
if nestedResult != nil {
if err := result.Append(*nestedResult); err != nil {
Expand All @@ -95,7 +91,7 @@ func (p operationsParser) parseOperation(operation parsedOperation, resourceProv
isAListOperation := p.isListOperation(operation)
responseResult, nestedResult, err := p.responseObjectForOperation(operation, result)
if err != nil {
return nil, nil, fmt.Errorf("determining response operation for %q (method %q / uri %q): %+v", operation.name, operation.httpMethod, *normalizedUri, err)
return nil, nil, fmt.Errorf("determining response operation for %q (method %q / ID %q): %+v", operation.name, operation.httpMethod, operation.operation.ID, err)
}
if nestedResult != nil {
if err := result.Append(*nestedResult); err != nil {
Expand All @@ -117,7 +113,7 @@ func (p operationsParser) parseOperation(operation parsedOperation, resourceProv
}
}

resourceId := p.urisToResourceIds[*normalizedUri]
resourceId := p.operationIdsToParsedOperations[operation.operation.ID]
usesADifferentResourceProvider, err := resourceIdUsesAResourceProviderOtherThan(resourceId.ResourceId, resourceProvider)
if err != nil {
return nil, nil, err
Expand All @@ -133,11 +129,11 @@ func (p operationsParser) parseOperation(operation parsedOperation, resourceProv
IsListOperation: isAListOperation,
LongRunning: longRunning,
Method: strings.ToUpper(operation.httpMethod),
OperationId: operation.operation.ID,
Options: *options,
RequestObject: requestObject,
ResourceIdName: resourceId.ResourceIdName,
ResponseObject: responseResult.objectDefinition,
Uri: *normalizedUri,
UriSuffix: resourceId.UriSuffix,
}

Expand Down Expand Up @@ -396,16 +392,6 @@ func (p operationsParser) operationShouldBeIgnored(input models.OperationDetails
return false
}

func (p operationsParser) normalizedUriForOperation(input parsedOperation) (*string, error) {
for key := range p.urisToResourceIds {
if strings.EqualFold(key, input.uri) {
return &key, nil
}
}

return nil, fmt.Errorf("%q was not found in the normalized uri list", input.uri)
}

func (p operationsParser) requestObjectForOperation(input parsedOperation, known internal.ParseResult) (*models.ObjectDefinition, *internal.ParseResult, error) {
// all we should parse out is the top level object - nothing more.

Expand Down
6 changes: 3 additions & 3 deletions tools/importer-rest-api-specs/components/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func (d *SwaggerDefinition) ParseResourceIds(resourceProvider *string) (*resourc

func (d *SwaggerDefinition) filterResourceIdsToResourceProvider(input resourceids.ParseResult, resourceProvider string) (*resourceids.ParseResult, error) {
output := resourceids.ParseResult{
OriginalUrisToResourceIDs: input.OriginalUrisToResourceIDs,
NamesToResourceIDs: map[string]models.ParsedResourceId{},
Constants: input.Constants,
OperationIdsToParsedResourceIds: input.OperationIdsToParsedResourceIds,
NamesToResourceIDs: map[string]models.ParsedResourceId{},
Constants: input.Constants,
}

for name := range input.NamesToResourceIDs {
Expand Down
Loading