autorest icon indicating copy to clipboard operation
autorest copied to clipboard

[tsp-client convert] `x-ms-identifiers` dropped in some cases

Open darkoa-msft opened this issue 6 months ago • 0 comments

I am converting an existing OpenAPI swagger to TypeSpec. In some cases, arrays are not annotated with x-ms-identifiers although they exist in the swagger.

Expected behavior All instances of x-ms-identifiers from the swagger should appear as @OpenAPI.extension("x-ms-identifiers", []) in tsp.

Additional context

Here is the model from the swagger. Note that this model is used as a payload to an ARM action. One of the arrays (files) gets properly annotated, the other (ImportUpdateInput) does not. The one that does not is being inlined by the converter.

    "ImportUpdateInput": {
      "type": "array",
      "description": "Import update input metadata.",
      "minItems": 1,
      "maxItems": 11,
      "items": {
        "$ref": "#/definitions/ImportUpdateInputItem"
      },
      "x-ms-identifiers": []
    },
    "ImportUpdateInputItem": {
      "type": "object",
      "description": "Import update input item metadata.",
      "properties": {
        "importManifest": {
          "$ref": "#/definitions/ImportManifestMetadata",
          "description": "Import manifest metadata like source URL, file size/hashes, etc."
        },
        "friendlyName": {
          "type": "string",
          "description": "Friendly update name.",
          "minLength": 1,
          "maxLength": 512
        },
        "files": {
          "type": "array",
          "description": "One or more update file properties like filename and source URL.",
          "minItems": 0,
          "maxItems": 10,
          "items": {
            "$ref": "#/definitions/FileImportMetadata"
          },
          "x-ms-identifiers": []
        }
      },
      "required": [
        "importManifest"
      ]
    },
    "ImportUpdateRequest": {
      "type": "object",
      "description": "Import Update API request body.",
      "properties": {
        "importUpdateInput": {
          "$ref": "#/definitions/ImportUpdateInput"
        },
        "enableScan": {
          "type": "boolean",
          "description": "Whether enable anti-malware scan",
          "default": false
        }
      },
      "required": [
        "importUpdateInput"
      ]
    },

And here is the result in tsp

/**
* Import Update API request body.
*/
model ImportUpdateRequest {
 /**
  * Import update input metadata.
  */
 importUpdateInput: ImportUpdateInputItem[];

 /**
  * Whether enable anti-malware scan
  */
 enableScan?: boolean;
}

/**
* Import update input item metadata.
*/
model ImportUpdateInputItem {
 /**
  * Import manifest metadata like source URL, file size/hashes, etc.
  */
 importManifest: ImportManifestMetadata;

 /**
  * Friendly update name.
  */
 @maxLength(512)
 @minLength(1)
 friendlyName?: string;

 /**
  * One or more update file properties like filename and source URL.
  */
 @OpenAPI.extension("x-ms-identifiers", [])
 files?: FileImportMetadata[];
}

darkoa-msft avatar Aug 12 '24 19:08 darkoa-msft