Azure / azure-openapi-validator

Azure Open API Validator
MIT License
47 stars 46 forks source link

LintDiff: FATAL: TypeError: Cannot read properties of null (reading 'additionalProperties') #680

Closed konrad-jamrozik closed 7 months ago

konrad-jamrozik commented 7 months ago

Context on Teams.

Raw log:

2024-04-24T18:13:49.4556642Z {"pluginName":"spectral","extensionName":"@microsoft.azure/openapi-validator","level":"information","message":"spectralPluginFunc: Validating OpenAPI spec. TypeSpec-generated: false. Path: 'file:///mnt/vss/_work/1/lint-c93b354fd9c14905bb574a8834c4d69b/specification/network/resource-manager/Microsoft.Network/stable/2023-11-01/applicationGateway.json'"}

2024-04-24T18:13:49.4557616Z {"pluginName":"spectral","extensionName":"@microsoft.azure/openapi-validator","level":"fatal","message":"spectralPluginFunc: Failed validating: 'file:///mnt/vss/_work/1/lint-c93b354fd9c14905bb574a8834c4d69b/specification/network/resource-manager/Microsoft.Network/stable/2023-11-01/applicationGateway.json'. Errors encountered:\nTypeError: Cannot read properties of null (reading 'additionalProperties')"}

mikeharder commented 7 months ago

Root Cause

I believe the root cause is the additionalProperties at the end of this line:

https://github.com/Azure/azure-openapi-validator/blob/ebf190a813ec46d2482c250ee6132456a4d0f455/packages/rulesets/src/spectral/az-arm.ts#L305

Potential fix (ensure @ is not null before dereferencing pointer):

&& @ && @.additionalProperties

Issues describing this behavior in spectral:

https://github.com/stoplightio/spectral/issues/1920 https://github.com/stoplightio/spectral/issues/2139

Repro Steps

$ gh repo clone azure/azure-rest-api-specs-pr

$ gh pr checkout 18022
OR
$ git checkout 642e50f5d5110d2f345ca3cd9364de7ac35bbfe5

$ npx autorest --v3 --spectral --azure-validator --semantic-validator=false --model-validator=false
--message-format=json --openapi-type=arm --openapi-subtype=arm
--use=@microsoft.azure/openapi-validator@2.2.1 --tag=package-2023-11-preview
specification/network/resource-manager/readme.md