autorest icon indicating copy to clipboard operation
autorest copied to clipboard

empty source in message when message occurs in the external referenced file

Open jianyexi opened this issue 3 years ago • 2 comments

Before filling a bug

  • [x] have you checked the faq for known issues.
  • [x] have you checked existing issues

Describe the bug

Suppose there are below two swaggers , b.json -> a.json, run below command

autorest --v3 --azure-validator --spectral --openapi-type=arm [email protected]/[email protected] --input-file=b.json

a.json

{
  "swagger": "2.0",
  "info": {
    "version": "2022-07-01",
    "title": "KeyVaultManagementClient",
  },
  "paths": {},
  "definitions": {
    "TypeB": {
      "readOnly": true,
      "properties": {
        "propA": {
          "type": "boolean",
          "description": "The identity that created the key vault resource."
        },
      },
      "type": "object"
    },
 
  },

}

b.json

{
  "swagger": "2.0",
  "info": {
    "version": "2022-07-01",
    "title": "",
  },
  "paths": {},
  "definitions": {
    "ModelA":{
      "type":"object",
      "properties": {
        "a" :{
          "$ref": "a.json#/definitions/TypeB"
        }
      }
    }
  },
}

the output message will contain a linter error message with empty source, though the jsonpath passed to the autorest/core is correct

{"pluginName":"spectral","extensionName":"@microsoft.azure/openapi-validator","level":"warning","message":"Booleans properties are not descriptive in all cases and can make them to use, evaluate whether is makes sense to keep the property as boolean or turn it into an enum.","code":"EnumInsteadOfBoolean","details":{"jsonpath":["definitions","TypeB","properties","propA"],"providerNamespace":false,"resourceType":false, "source":[]}

Expected behavior the message will contain the correct source

jianyexi avatar Nov 07 '22 09:11 jianyexi

can you pass the source then? autorest won't be able to resolve it from the message you are sending.

timotheeguerin avatar Nov 09 '22 16:11 timotheeguerin

@timotheeguerin I've debugged locally, the message the extension sent to autorest/core is below, the source contains the correct document and json path

{
    "Channel": "warning",
    "Text": "Booleans properties are not descriptive in all cases and can make them to use, evaluate whether is makes sense to keep the property as boolean or turn it into an enum.",
    "Key": [
        "EnumInsteadOfBoolean"
    ],
    "Source": [
        {
            "document": "file:///home/justinxi/openapi-env-test/a.json",
            "Position": {
                "path": [
                    "definitions",
                    "TypeB",
                    "properties",
                    "propA"
                ]
            }
        }
    ],
    "Details": {
        "jsonpath": [
            "definitions",
            "TypeB",
            "properties",
            "propA"
        ],
        "providerNamespace": false,
        "resourceType": false,
    }
}```

jianyexi avatar Nov 10 '22 06:11 jianyexi