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

Rule for x-ms-enum crashes when "name" property is missing. #654

Closed
tjprescott opened this issue Feb 1, 2024 · 6 comments
Closed

Rule for x-ms-enum crashes when "name" property is missing. #654

tjprescott opened this issue Feb 1, 2024 · 6 comments

Comments

@tjprescott
Copy link
Member

The following Swagger causes LintDiff to crash with a fatal error:
image

The error is:
openapiValidatorPluginFunc: Failed validating:TypeError: Cannot read property 'toLowerCase' of undefined Location

Here's the failing CI run:
https://github.com/Azure/azure-rest-api-specs/pull/27356/checks?check_run_id=20396982945

Per the specification for x-ms-enum, name is an optional field, so any rule that is operating on x-ms-enum needs to have appropriate logic. In this case, the rule seems to be assuming name exists and calling toLowerCase on it, resulting in the fatal crash.

@mikeharder
Copy link
Member

mikeharder commented Feb 1, 2024

Root cause documented at Azure/azure-sdk-tools#7602

@mikeharder
Copy link
Member

I this this code just needs to no-op if name is undefinted:

if (section.value["x-ms-enum"] && isValidEnum(section.value)) {
const enumName = section.value["x-ms-enum"].name.toLowerCase()

@konrad-jamrozik
Copy link
Contributor

Yeah so probably, in pseudocode:

if (section.value["x-ms-enum"] && isValidEnum(section.value)) {

-->

if (section.value["x-ms-enum"] && isValidEnum(section.value) && section.value["x-ms-enum"] is defined) {

@mikeharder
Copy link
Member

if (section.value["x-ms-enum"] && isValidEnum(section.value) && section.value["x-ms-enum"].name is defined) {

Need to check if name is defined

@konrad-jamrozik
Copy link
Contributor

Should be fixed now.

@mikeharder
Copy link
Member

Swagger LintDiff is now passing for Azure/azure-rest-api-specs#27356.

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

No branches or pull requests

3 participants