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: support for pulling the Display Name for an Integer Constant if defined #3611

Merged

Conversation

tombuildsstuff
Copy link
Contributor

@tombuildsstuff tombuildsstuff commented Jan 11, 2024

This commit fixes #3010 by checking for a Display Name within the x-ms-enum block and pulling from that if a (Display) Name is defined for an Integer constant.

Whilst I considered doing this for Float and String constants too, I've intentionally omitted those since Float constants are rare (so we can apply this same fix if needed down the line) - and for String constants there's little benefit to changing at this point, since we normalize a key from the value for the constant.

Ultimately this should ensure that when we import the constant EmailChannelAuthMethod for BotService that we output this as:

Password: 0
Graph: 1

Which is far more descriptive than:

Zero: 0
One: 1


There's a couple of changes to the existing data, but it's nothing major:

diff --git a/api-definitions/resource-manager/CosmosDB/2022-11-15/Mongorbacs/Constant-MongoRoleDefinitionType.json b/api-definitions/resource-manager/CosmosDB/2022-11-15/Mongorbacs/Constant-MongoRoleDefinitionType.json
index 6283a51ce7..0c3a0f9cf9 100644
--- a/api-definitions/resource-manager/CosmosDB/2022-11-15/Mongorbacs/Constant-MongoRoleDefinitionType.json
+++ b/api-definitions/resource-manager/CosmosDB/2022-11-15/Mongorbacs/Constant-MongoRoleDefinitionType.json
@@ -3,12 +3,12 @@
        "type": "Integer",
        "values": [
                {
-                       "key": "One",
-                       "value": "1"
+                       "key": "BuiltInRole",
+                       "value": "0"
                },
                {
-                       "key": "Zero",
-                       "value": "0"
+                       "key": "CustomRole",
+                       "value": "1"
                }
        ]
 }
\ No newline at end of file
diff --git a/api-definitions/resource-manager/MixedReality/2021-01-01/Key/Constant-Serial.json b/api-definitions/resource-manager/MixedReality/2021-01-01/Key/Constant-Serial.json
index f21186275a..1e385dd515 100644
--- a/api-definitions/resource-manager/MixedReality/2021-01-01/Key/Constant-Serial.json
+++ b/api-definitions/resource-manager/MixedReality/2021-01-01/Key/Constant-Serial.json
@@ -3,11 +3,11 @@
        "type": "Integer",
        "values": [
                {
-                       "key": "One",
+                       "key": "Primary",
                        "value": "1"
                },
                {
-                       "key": "Two",
+                       "key": "Secondary",
                        "value": "2"
                }
        ]

… for an Integer Constant if defined

This commit fixes #3010 by checking for a Display Name within the
`x-ms-enum` block and pulling from that if a (Display) Name is defined for an Integer constant.

Whilst I considered doing this for Float and String constants too, I've intentionally omitted those since
Float constants are rare (so we can apply this same fix if needed down the line) - and for String constants
there's little benefit to changing at this point, since we normalize a key from the value for the constant.

Ultimately this should ensure that when we import the constant `EmailChannelAuthMethod` for `BotService` that
we output this as:

> `Password`: `0`
> `Graph`: `1`

Which is far more descriptive than:

> `0`: `0`
> `1`: `1`
Copy link

Breaking Changes

No Breaking Changes were found 👍

Copy link

Summary of Changes

No Breaking or Non-Breaking Changes were found 👍

Copy link

New Resource ID Segments containing Static Identifiers

No new Resource ID Segments containing Static Identifiers were identified in the set of changes 🤙.

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

LGTM with a minor comment

items := v.([]interface{})
displayNameOverrides := make(map[interface{}]string)
for _, itemRaw := range items {
item := itemRaw.(map[string]interface{})
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to check that this isn't nil or is it fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The extension is defined in this manner, and everything we're importing matches it - so I think this is fine as-is for now. If this is an issue we can fix it at that point, but that's likely going to be bad data - so would want resolving upstream anyway - as such this is fine 👍

@tombuildsstuff tombuildsstuff merged commit 0ce64cb into main Jan 17, 2024
3 checks passed
@tombuildsstuff tombuildsstuff deleted the f/support-for-using-display-names-for-constants branch January 17, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/data-canonicalisation Issues around Data Normalisation/Canonicalisation tool/importer-rest-api-specs Swagger Data Importer issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Constants: pulling the display name from x-ms-enum
2 participants