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

importer-rest-api-specs - parse orphaned discriminated models in nested files #3727

Merged
merged 3 commits into from
Jan 31, 2024

Conversation

stephybun
Copy link
Member

@stephybun stephybun commented Jan 30, 2024

This PR closes #3693 and is related to #2551 but doesn't close it since we skip over this new functionality for DataFactory due to #3725.

Although we iterate over files in a nested directory structure, if the files have no paths defined then we don't parse any of the models defined in them.

This change adds the following functionality:

  • Will find all discriminated models in files without any paths
  • Find any models that the discriminated models reference
  • Combine them into the resource they belong to (this depends on the file name, ChaosStudio and DataFactory use the resource name as the file name)
  • Links the discriminated models to the parent, updating the data on the model that describes it as a discriminator

Note: DataMigration and SecurityInsights are also affected by this change. DataMigration results in the addition of a lot of new "resources" due to the naming of the files, we may want to consider skipping this functionality for DataMigration as well.

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 @stephybun

Thanks for this PR - I've taken a look through and left a few minor comments inline, but on the whole this is looking pretty good, if we can fix those up then this should otherwise be good to merge 👍

Thanks!

tools/importer-rest-api-specs/components/parser/models.go Outdated Show resolved Hide resolved
Comment on lines +87 to +91
resource := models.AzureApiResource{
Constants: result.Constants,
Models: result.Models,
}
resource = normalizeAzureApiResource(resource)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the structure of Azure/azure-rest-api-specs has changed multiple times in the past - I suspect we probably shouldn't assume that only Constants and Models are present within the nested directories (even if that's the case today).

Whilst we're merging the result of this function in combineResourcesWith - rather than assuming the Swagger Tag is unique within this function (as we're doing here by writing to resourcesOut without checking for an existing value) - I suspect it'd be worth supporting merging into resourcesOut, as we do above (similar to lines 52-57 above) so that we don't unintentionally overwrite any Operations/Resource IDs which may be defined for an existing Tag, should Operations be added into a nested directory?

Alternatively we could look to surface an error here if the Swagger Tag already exists within resourcesOut - but since we'd end up needing to implement the merge to fix that error, I suspect it'd be worth supporting merge from the start for consistency with the rest of the function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Although I'm not in agreement that it's necessary I've added the logic to merge the resource information for a tag if it already exists since there isn't any harm in adding it.

Because this function is called on a per file basis, if any tags or operations were defined in the file it would be pulled out either here

resource, err := d.parseResourcesWithinSwaggerTag(&tag, resourceProvider, resourceIds)

or here
// however some things don't, so we then need to iterate over any without them
if _, shouldIgnore := tagsToIgnore[strings.ToLower(serviceName)]; !shouldIgnore {
resource, err := d.parseResourcesWithinSwaggerTag(nil, resourceProvider, resourceIds)

resulting in a populated resources variable which means we would never enter this part of the function and no prior tags could exist if we ended up here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChaosStudio @ 2023-11-01 discriminator models aren't parsed in Experiments
2 participants