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: skip build model if input schema is only for property #3041

Merged
merged 5 commits into from
Sep 22, 2023

Conversation

wuxu92
Copy link
Collaborator

@wuxu92 wuxu92 commented Sep 14, 2023

should fix the importer issue of #2675. also cherry-picked @tombuildsstuff 's commit of adding Unit Test for it: d2ea0bb

--- PASS: TestParseModelBug2675DuplicateModel (0.02s)
PASS

I have regenerated all services and it caused no different from main branch's data, (except the DevCenter service):

image

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @wuxu92

Thanks for this PR - I've taken a look and left some comments inline, but this is looking pretty good - if we can fix those up then this should otherwise be good to go 👍

Thanks!

modelName, propertyName string,
input *spec.Schema,
known internal.ParseResult,
isInputForModel bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is being used to determine if we're passing a model, or pulling inlined information from a field - this is probably better named as:

Suggested change
isInputForModel bool,
parsingModel bool,

@@ -509,7 +515,7 @@ func (d SwaggerDefinition) parseObjectDefinition(modelName, propertyName string,
}

// then call ourselves to work out what to do with it
objectDefinition, nestedResult, err := d.parseObjectDefinition(*objectName, propertyName, topLevelObject, knownIncludingPlaceholder)
objectDefinition, nestedResult, err := d.parseObjectDefinition(*objectName, propertyName, topLevelObject, knownIncludingPlaceholder, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably this should be passing parsingModel in when looping around? else we'll potentially be passing true when the false thing:

Suggested change
objectDefinition, nestedResult, err := d.parseObjectDefinition(*objectName, propertyName, topLevelObject, knownIncludingPlaceholder, true)
objectDefinition, nestedResult, err := d.parseObjectDefinition(*objectName, propertyName, topLevelObject, knownIncludingPlaceholder, parsingModel)

Copy link
Collaborator Author

@wuxu92 wuxu92 Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should always pass a true here, because the Schame represented by topLevelObject is what the *objectName want. that means we can use topLevelObject to parse model of *objectName. also as other two calls below, the inner/inheritedModel is corresponding to the modelName, and they should always pass a true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing the full set of Services there's no difference with this logic, but threading this through causes:

2023-09-21T13:09:57.569+0200 [INFO]  Importer for Service "Advisor".Importer for API Version "2022-10-01": :x: Service "Advisor" - Api Version "2022-10-01"
2023-09-21T13:09:57.569+0200 [ERROR] Importer for Service "Advisor".Importer for API Version "2022-10-01":      :boom: Error: parsing Swagger files: parsing files in "../../submodules/rest-api-specs/specification/advisor/resource-manager/Microsoft.Advisor/stable/2022-10-01": parsing definition: finding resources for tag "AdvisorScore": finding nested items yet to be parsed: finding top level object named "TimeSeriesEntityTimeSeriesInlined": the top level object "TimeSeriesEntityTimeSeriesInlined" was not found
2023/09/21 13:09:57 Error: parsing data for Service "Advisor": parsing data for Service "Advisor" / Version "2022-10-01": parsing Swagger files: parsing files in "../../submodules/rest-api-specs/specification/advisor/resource-manager/Microsoft.Advisor/stable/2022-10-01": parsing definition: finding resources for tag "AdvisorScore": finding nested items yet to be parsed: finding top level object named "TimeSeriesEntityTimeSeriesInlined": the top level object "TimeSeriesEntityTimeSeriesInlined" was not found

So this looks fine 👍

Comment on lines 539 to 540
// only parse model when modelName equals PropertyName, otherwise the `input` Schema may not for the modelName
// if parsing a top-level or an inlined model, should pass the propertyName just the same as the modelName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this'd be clearer as:

Suggested change
// only parse model when modelName equals PropertyName, otherwise the `input` Schema may not for the modelName
// if parsing a top-level or an inlined model, should pass the propertyName just the same as the modelName
// however we should only do this when we're parsing a model (`parsingModel`) directly rather than when parsing a model from a field - and only if we haven't already parsed this model

@tombuildsstuff tombuildsstuff added tool/importer-rest-api-specs Swagger Data Importer issues data/swagger-issue An issue related to the Swagger/OpenAPI Definitions labels Sep 18, 2023
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @wuxu92

If we can fix up the remaining comment (about the comment) then this should otherwise be good to go 👍

Thanks!

@@ -509,7 +515,7 @@ func (d SwaggerDefinition) parseObjectDefinition(modelName, propertyName string,
}

// then call ourselves to work out what to do with it
objectDefinition, nestedResult, err := d.parseObjectDefinition(*objectName, propertyName, topLevelObject, knownIncludingPlaceholder)
objectDefinition, nestedResult, err := d.parseObjectDefinition(*objectName, propertyName, topLevelObject, knownIncludingPlaceholder, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing the full set of Services there's no difference with this logic, but threading this through causes:

2023-09-21T13:09:57.569+0200 [INFO]  Importer for Service "Advisor".Importer for API Version "2022-10-01": :x: Service "Advisor" - Api Version "2022-10-01"
2023-09-21T13:09:57.569+0200 [ERROR] Importer for Service "Advisor".Importer for API Version "2022-10-01":      :boom: Error: parsing Swagger files: parsing files in "../../submodules/rest-api-specs/specification/advisor/resource-manager/Microsoft.Advisor/stable/2022-10-01": parsing definition: finding resources for tag "AdvisorScore": finding nested items yet to be parsed: finding top level object named "TimeSeriesEntityTimeSeriesInlined": the top level object "TimeSeriesEntityTimeSeriesInlined" was not found
2023/09/21 13:09:57 Error: parsing data for Service "Advisor": parsing data for Service "Advisor" / Version "2022-10-01": parsing Swagger files: parsing files in "../../submodules/rest-api-specs/specification/advisor/resource-manager/Microsoft.Advisor/stable/2022-10-01": parsing definition: finding resources for tag "AdvisorScore": finding nested items yet to be parsed: finding top level object named "TimeSeriesEntityTimeSeriesInlined": the top level object "TimeSeriesEntityTimeSeriesInlined" was not found

So this looks fine 👍

@wuxu92
Copy link
Collaborator Author

wuxu92 commented Sep 22, 2023

@tombuildsstuff Thanks a lot for reminding me of missing one comment ❤️ . updated now.

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data/swagger-issue An issue related to the Swagger/OpenAPI Definitions tool/importer-rest-api-specs Swagger Data Importer issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants