Skip to content

[RequiredPropertiesMissingInResourceModel] Crash with "TypeError: Cannot read properties of undefined (reading 'readOnly')" #781

@mikeharder

Description

@mikeharder
$ gh repo clone azure/azure-rest-api-specs
$ git checkout b8fbdcc1e60dc013870988ef563014a07e9c7f47
$ npm i
npm exec -- autorest \
  --level=fatal \
  --v3 \
  --spectral --azure-validator --semantic-validator=false --model-validator=false \
  --use=$(pwd)/node_modules/@microsoft.azure/openapi-validator \
  --openapi-type=arm --openapi-subtype=arm \
  --tag=package-2024-04 \
    specification/monitor/resource-manager/readme.md

fatal | openapiValidatorPluginFunc: Failed validating: TypeError: azure-openapi-validator/core/src/runner.ts/LintRunner.runRules/processRule error. ruleName: RequiredPropertiesMissingInResourceModel, specFilePath: file:///home/mharder/specs-mh/specification/monitor/resource-manager/Microsoft.Insights/stable/2024-02-01/metrics_API.json, jsonPath: , errorName: TypeError, errorMessage: Cannot read properties of undefined (reading 'readOnly')

This is a regression between [email protected] and [email protected]. Using [email protected], this spec doesn't crash.

Details

I was able to log the error:

propName: 'name'
prop: {
  file: 'file:///home/mharder/specs/specification/monitor/resource-manager/Microsoft.Insights/stable/2024-02-01/metrics_API.json',
  value: [Object: null prototype] {
    '$ref': '#/definitions/LocalizableString',
    description: 'The name and the display name of the metric, i.e. it is localizable string.'
  }
}

I think the bug is related to this code. It might be as simple, as these properties need to be marked readOnly. Or, it might be the case that name must be a regular string, not a LocalizableString.

    "Metric": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "The metric Id."
        },
        "type": {
          "type": "string",
          "description": "The resource type of the metric resource."
        },
        "name": {
          "$ref": "#/definitions/LocalizableString",
          "description": "The name and the display name of the metric, i.e. it is localizable string."
        },

https://github.com/Azure/azure-rest-api-specs/blob/41a1a5bcff6f3fcef298389a2d4897b47681c4f2/specification/monitor/common-types/v2/commonMonitoringTypes.json#L185-L196

This file hasn't been touched in 2 years. So either it's always been broken, or the rule recently changed.

https://github.com/Azure/azure-openapi-validator/blame/21c0234f420468a5edc580953edd941d487bf564/packages/rulesets/src/native/functions/arm-resource-validation.ts#L177-L198

This may be a recent regression in the rule.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions