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

Use real API Version enums #2285

Merged
merged 10 commits into from
May 19, 2022
Merged

Use real API Version enums #2285

merged 10 commits into from
May 19, 2022

Conversation

Porges
Copy link
Member

@Porges Porges commented May 17, 2022

  1. Add a new pipeline stage to create (singleton) enum types for API versions
  2. Update GetAPIVersion function generation to return this enum value
  3. Correct TypeVisitor so it visits the API Version typename (if any) on resource types
  4. Add a small hack into the Storage type creation to also copy API versions explicitly

This fixes #1554

@codecov-commenter
Copy link

codecov-commenter commented May 17, 2022

Codecov Report

Merging #2285 (8bba438) into main (802178e) will increase coverage by 0.12%.
The diff coverage is 33.45%.

@@            Coverage Diff             @@
##             main    #2285      +/-   ##
==========================================
+ Coverage   53.12%   53.25%   +0.12%     
==========================================
  Files         807      808       +1     
  Lines      238594   245438    +6844     
==========================================
+ Hits       126757   130699    +3942     
- Misses      93968    96242    +2274     
- Partials    17869    18497     +628     
Impacted Files Coverage Δ
...ha1api20200801preview/role_assignment_types_gen.go 26.82% <0.00%> (ø)
...801preview/role_assignments__spec_arm_types_gen.go 0.00% <0.00%> (ø)
...0200801previewstorage/role_assignment_types_gen.go 46.42% <0.00%> (ø)
...v1beta20200801preview/role_assignment_types_gen.go 52.82% <0.00%> (ø)
...tch/v1alpha1api20210101/batch_account_types_gen.go 40.18% <0.00%> (ø)
...1api20210101/batch_accounts__spec_arm_types_gen.go 0.00% <0.00%> (ø)
...lpha1api20210101storage/batch_account_types_gen.go 62.05% <0.00%> (ø)
...pi/batch/v1beta20210101/batch_account_types_gen.go 54.08% <0.00%> (ø)
...e/v1alpha1api20201201/redis__spec_arm_types_gen.go 0.00% <0.00%> (ø)
...alpha1api20201201/redis_firewall_rule_types_gen.go 22.64% <0.00%> (ø)
... and 369 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 802178e...8bba438. Read the comment docs.

Copy link
Member

@theunrepentantgeek theunrepentantgeek left a comment

Choose a reason for hiding this comment

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

A couple of minor suggestions, but otherwise looks good.

Comment on lines +42 to +55
// HACK: include the APIVersion in the storage types package.
// really we don't want storage types to have API Version at all,
// but it's difficult to remove the GetApiVersion() Function at the moment
storageAPIVersions := make(astmodel.TypeNameSet)
for _, tdef := range typesToConvert {
if rt, ok := astmodel.AsResourceType(tdef.Type()); ok && rt.HasAPIVersion() {
storageAPIVersions.Add(rt.APIVersionTypeName())
}
}

for name := range storageAPIVersions {
typesToConvert.Add(state.Definitions()[name])
}

Copy link
Member

Choose a reason for hiding this comment

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

Could this be done by modifying (and renaming) the predicate isResourceOrObject instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not very easily, it would require another pass. I think it's good to call this out as the HACK that it is 😁

Ideally we wouldn't have these at all in the storage types, so this is a reminder that we would like to remove them in future.

@Porges Porges merged commit 0f59cc7 into main May 19, 2022
@Porges Porges deleted the api-version branch May 19, 2022 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Generated packages should define an accessible ARMAPIVersion variable
4 participants