Skip to content

Fix x-ms-identifier present on every array model #2607

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-autorest"
---

Fix `x-ms-identifiers` being automatically populated, which caused default values to be overwritten unexpectedly. Now, it is only set when explicitly defined.
3 changes: 1 addition & 2 deletions packages/samples/common-types/openapi/v3/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@
"items": {
"$ref": "#/definitions/ErrorAdditionalInfo"
},
"readOnly": true,
"x-ms-identifiers": []
"readOnly": true
}
}
},
Expand Down
3 changes: 1 addition & 2 deletions packages/samples/common-types/openapi/v4/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@
"items": {
"$ref": "#/definitions/ErrorAdditionalInfo"
},
"readOnly": true,
"x-ms-identifiers": []
"readOnly": true
}
}
},
Expand Down
3 changes: 1 addition & 2 deletions packages/samples/common-types/openapi/v5/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@
"items": {
"$ref": "#/definitions/ErrorAdditionalInfo"
},
"readOnly": true,
"x-ms-identifiers": []
"readOnly": true
}
}
},
Expand Down
3 changes: 1 addition & 2 deletions packages/samples/common-types/openapi/v6/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@
"items": {
"$ref": "#/definitions/ErrorAdditionalInfo"
},
"readOnly": true,
"x-ms-identifiers": []
"readOnly": true
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,7 @@
"description": "An array of details about specific errors that led to this reported error.",
"items": {
"$ref": "#/definitions/Azure.Core.Foundations.Error"
},
"x-ms-identifiers": []
}
},
"innererror": {
"$ref": "#/definitions/Azure.Core.Foundations.InnerError",
Expand Down Expand Up @@ -1209,8 +1208,7 @@
"description": "The Widget items on this page",
"items": {
"$ref": "#/definitions/Widget"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,7 @@
"description": "An array of details about specific errors that led to this reported error.",
"items": {
"$ref": "#/definitions/Azure.Core.Foundations.Error"
},
"x-ms-identifiers": []
}
},
"innererror": {
"$ref": "#/definitions/Azure.Core.Foundations.InnerError",
Expand Down Expand Up @@ -630,8 +629,7 @@
"description": "The Widget items on this page",
"items": {
"$ref": "#/definitions/Widget"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,7 @@
"description": "An array of details about specific errors that led to this reported error.",
"items": {
"$ref": "#/definitions/Azure.Core.Foundations.Error"
},
"x-ms-identifiers": []
}
},
"innererror": {
"$ref": "#/definitions/Azure.Core.Foundations.InnerError",
Expand Down Expand Up @@ -1113,8 +1112,7 @@
"description": "The Widget items on this page",
"items": {
"$ref": "#/definitions/Widget"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,7 @@
"description": "An array of details about specific errors that led to this reported error.",
"items": {
"$ref": "#/definitions/Azure.Core.Foundations.Error"
},
"x-ms-identifiers": []
}
},
"innererror": {
"$ref": "#/definitions/Azure.Core.Foundations.InnerError",
Expand Down Expand Up @@ -1209,8 +1208,7 @@
"description": "The Widget items on this page",
"items": {
"$ref": "#/definitions/Widget"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1961,8 +1961,7 @@
"description": "An array of details about specific errors that led to this reported error.",
"items": {
"$ref": "#/definitions/Azure.Core.Foundations.Error"
},
"x-ms-identifiers": []
}
},
"innererror": {
"$ref": "#/definitions/Azure.Core.Foundations.InnerError",
Expand Down Expand Up @@ -2107,8 +2106,7 @@
"description": "The Widget items on this page",
"items": {
"$ref": "#/definitions/Widget"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand All @@ -2129,8 +2127,7 @@
"description": "The WidgetPart items on this page",
"items": {
"$ref": "#/definitions/WidgetPart"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,7 @@
"description": "The Key items on this page",
"items": {
"$ref": "#/definitions/Key"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand All @@ -1083,8 +1082,7 @@
"description": "The KeyValue items on this page",
"items": {
"$ref": "#/definitions/KeyValue"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand All @@ -1104,8 +1102,7 @@
"description": "The Label items on this page",
"items": {
"$ref": "#/definitions/Label"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,7 @@
"description": "The LogAnalyticsOperationResult items on this page",
"items": {
"$ref": "#/definitions/LogAnalyticsOperationResult"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand Down Expand Up @@ -614,8 +613,7 @@
"description": "The VmSize items on this page",
"items": {
"$ref": "#/definitions/VmSize"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@
"type": "array",
"items": {
"$ref": "#/definitions/ProtobufAny"
},
"x-ms-identifiers": []
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@
"description": "The list of books.",
"items": {
"$ref": "#/definitions/Book"
},
"x-ms-identifiers": []
}
},
"next_page_token": {
"type": "string",
Expand Down Expand Up @@ -350,8 +349,7 @@
"description": "The list of shelves.",
"items": {
"$ref": "#/definitions/Shelf"
},
"x-ms-identifiers": []
}
},
"next_page_token": {
"type": "string",
Expand Down Expand Up @@ -406,8 +404,7 @@
"type": "array",
"items": {
"$ref": "#/definitions/ProtobufAny"
},
"x-ms-identifiers": []
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
},
"x-ms-identifiers": []
}
},
"nextLink": {
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@
"type": "array",
"items": {
"$ref": "#/definitions/Resp"
},
"x-ms-identifiers": []
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@
"type": "array",
"items": {
"$ref": "#/definitions/Library.PetToy"
},
"x-ms-identifiers": []
}
}
},
"discriminator": "type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@
"type": "array",
"items": {
"$ref": "#/definitions/Library.PetToy"
},
"x-ms-identifiers": []
}
}
},
"discriminator": "type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@
"items": {
"$ref": "#/definitions/PersonRelative"
},
"x-ms-identifiers": [],
"x-ms-mutability": [
"read",
"update",
Expand Down Expand Up @@ -223,7 +222,6 @@
"items": {
"$ref": "#/definitions/PersonRelative"
},
"x-ms-identifiers": [],
"x-ms-mutability": [
"read",
"update",
Expand Down Expand Up @@ -254,8 +252,7 @@
"type": "array",
"items": {
"$ref": "#/definitions/PersonRelativeMergePatchUpdateReplaceOnly"
},
"x-ms-identifiers": []
}
}
}
},
Expand All @@ -275,8 +272,7 @@
"type": "array",
"items": {
"$ref": "#/definitions/PersonRelativeMergePatchUpdateReplaceOnly"
},
"x-ms-identifiers": []
}
}
},
"required": [
Expand Down Expand Up @@ -345,7 +341,6 @@
"items": {
"$ref": "#/definitions/PersonRelative"
},
"x-ms-identifiers": [],
"x-ms-mutability": [
"read",
"update",
Expand Down Expand Up @@ -385,7 +380,6 @@
"items": {
"$ref": "#/definitions/PersonRelative"
},
"x-ms-identifiers": [],
"x-ms-mutability": [
"read",
"update",
Expand Down Expand Up @@ -424,7 +418,6 @@
"items": {
"$ref": "#/definitions/PersonRelative"
},
"x-ms-identifiers": [],
"x-ms-mutability": [
"read",
"update",
Expand Down
13 changes: 0 additions & 13 deletions packages/typespec-autorest/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
shouldFlattenProperty,
} from "@azure-tools/typespec-client-generator-core";
import {
ArrayModelType,
BooleanLiteral,
CompilerHost,
Diagnostic,
Expand Down Expand Up @@ -1844,16 +1843,6 @@ export async function getOpenAPIForService(
}
}

function ifArrayItemContainsIdentifier(program: Program, array: ArrayModelType) {
if (array.indexer.value?.kind !== "Model") {
return true;
}
return (
getExtensions(program, array).has("x-ms-identifiers") ||
getProperty(array.indexer.value, "id")
);
}

function ifArmIdentifiersDefault(armIdentifiers: string[]) {
return armIdentifiers.every((identifier) => identifier === "id" || identifier === "name");
}
Expand Down Expand Up @@ -2415,8 +2404,6 @@ export async function getOpenAPIForService(
hasValidArmIdentifiers(armKeyIdentifiers)
) {
array["x-ms-identifiers"] = armKeyIdentifiers;
} else if (!ifArrayItemContainsIdentifier(program, typespecType as any)) {
array["x-ms-identifiers"] = [];
}

return applyIntrinsicDecorators(typespecType, array);
Expand Down
Loading
Loading