diff --git a/.chronus/changes/allow-reserved-2024-8-11-16-40-29.md b/.chronus/changes/allow-reserved-2024-8-11-16-40-29.md new file mode 100644 index 0000000000..5062d7dc94 --- /dev/null +++ b/.chronus/changes/allow-reserved-2024-8-11-16-40-29.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@azure-tools/typespec-azure-resource-manager" +--- + +`x-ms-skip-url-encoding` should be replaced with `allowReserved` \ No newline at end of file diff --git a/.chronus/changes/fix-tcgc-multipart-model-name-2024-8-6-14-12-14.md b/.chronus/changes/fix-tcgc-multipart-model-name-2024-8-6-14-12-14.md new file mode 100644 index 0000000000..3927c0b4e0 --- /dev/null +++ b/.chronus/changes/fix-tcgc-multipart-model-name-2024-8-6-14-12-14.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +Fix naming logic for anonymous model wrapped by `HttpPart` \ No newline at end of file diff --git a/core b/core index 0be9e8f22b..a5fc2ce620 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 0be9e8f22bb587db69bf1fc5e73effef1e2364a5 +Subproject commit a5fc2ce6201098d1d7095bb4e7a6109c1dd2fe9a diff --git a/packages/e2e-tests/cadl-ranch-specs/package.json b/packages/e2e-tests/cadl-ranch-specs/package.json index 8f367a6c91..77ff83c22a 100644 --- a/packages/e2e-tests/cadl-ranch-specs/package.json +++ b/packages/e2e-tests/cadl-ranch-specs/package.json @@ -1,7 +1,7 @@ { "name": "@azure-tools/typespec-e2e-cadl-ranch-specs", "dependencies": { - "@azure-tools/cadl-ranch-specs": "0.37.1" + "@azure-tools/cadl-ranch-specs": "0.37.2" }, "type": "module", "private": true diff --git a/packages/typespec-azure-resource-manager/lib/common-types/types.tsp b/packages/typespec-azure-resource-manager/lib/common-types/types.tsp index d8c386b134..a83e3b1d81 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/types.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/types.tsp @@ -537,10 +537,9 @@ model ManagementGroupNameParameter { @added(Versions.v4) model ScopeParameter { /** The scope at which the operation is performed. */ - @path + @path(#{ allowReserved: true }) @segment("scope") @minLength(1) - @extension("x-ms-skip-url-encoding", true) scope: string; } diff --git a/packages/typespec-azure-resource-manager/lib/parameters.tsp b/packages/typespec-azure-resource-manager/lib/parameters.tsp index 43a17c652e..498cdadc19 100644 --- a/packages/typespec-azure-resource-manager/lib/parameters.tsp +++ b/packages/typespec-azure-resource-manager/lib/parameters.tsp @@ -83,9 +83,8 @@ model ArmLocationResource to get "MyRealType" + const typeWrappedByHttpPart = getHttpPart(context.program, currentType); + if (typeWrappedByHttpPart) { + return dfsModelProperties(expectedType, typeWrappedByHttpPart.type, displayName); + } + + if ( + currentType.indexer && + currentType.properties.size === 0 && + ((currentType.indexer.key.name === "string" && currentType.name === "Record") || + currentType.indexer.key.name === "integer") + ) { + // handle array or dict + const dictOrArrayItemType: Type = currentType.indexer.value; + return dfsModelProperties( + expectedType, + dictOrArrayItemType, + pluralize.singular(displayName) + ); + } + // handle model result.push({ name: displayName, type: currentType }); for (const property of currentType.properties.values()) { diff --git a/packages/typespec-client-generator-core/test/types/array-types.test.ts b/packages/typespec-client-generator-core/test/types/array-types.test.ts index 97bd609de4..1f5307433f 100644 --- a/packages/typespec-client-generator-core/test/types/array-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/array-types.test.ts @@ -1,6 +1,6 @@ import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; describe("typespec-client-generator-core: array types", () => { @@ -9,7 +9,16 @@ describe("typespec-client-generator-core: array types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("use model is to represent array", async () => { await runner.compile(` @service({}) @@ -40,13 +49,13 @@ describe("typespec-client-generator-core: array types", () => { }); it("EmbeddingVector from azure-core", async () => { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], "filter-out-core-models": false, emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService(` + await runner.compileWithBuiltInAzureCoreService(` @service({}) namespace TestClient { model ModelWithEmbeddingVector { @@ -56,7 +65,7 @@ describe("typespec-client-generator-core: array types", () => { op get(): ModelWithEmbeddingVector; } `); - const models = runnerWithCore.context.sdkPackage.models; + const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); const model = models[0]; const property = model.properties[0]; @@ -67,13 +76,13 @@ describe("typespec-client-generator-core: array types", () => { }); it("alias of EmbeddingVector", async () => { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], "filter-out-core-models": false, emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService(` + await runner.compileWithBuiltInAzureCoreService(` @service({}) namespace TestClient { alias MyEmbeddingVector = EmbeddingVector; @@ -85,7 +94,7 @@ describe("typespec-client-generator-core: array types", () => { op get(): ModelWithEmbeddingVector; } `); - const models = runnerWithCore.context.sdkPackage.models; + const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); const model = models[0]; const property = model.properties[0]; diff --git a/packages/typespec-client-generator-core/test/types/body-model-property-types.test.ts b/packages/typespec-client-generator-core/test/types/body-model-property-types.test.ts index a3cd77f83b..fc4a4e9ffa 100644 --- a/packages/typespec-client-generator-core/test/types/body-model-property-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/body-model-property-types.test.ts @@ -1,5 +1,5 @@ import { deepStrictEqual, ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { isReadOnly } from "../../src/types.js"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; import { getSdkBodyModelPropertyTypeHelper } from "./utils.js"; @@ -10,7 +10,16 @@ describe("typespec-client-generator-core: body model property types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("required", async function () { await runner.compileWithBuiltInService(` @usage(Usage.input | Usage.output) @@ -134,12 +143,12 @@ describe("typespec-client-generator-core: body model property types", () => { strictEqual(values[1].kind, "int32"); }); it("versioning", async function () { - const runnerWithVersion = await createSdkTestRunner({ + runner = await createSdkTestRunner({ "api-version": "all", emitterName: "@azure-tools/typespec-python", }); - await runnerWithVersion.compile(` + await runner.compile(` @versioned(Versions) @service({title: "Widget Service"}) namespace DemoService; @@ -164,7 +173,7 @@ describe("typespec-client-generator-core: body model property types", () => { removedProp: string; } `); - const sdkModel = runnerWithVersion.context.sdkPackage.models.find((x) => x.kind === "model"); + const sdkModel = runner.context.sdkPackage.models.find((x) => x.kind === "model"); ok(sdkModel); strictEqual(sdkModel.kind, "model"); diff --git a/packages/typespec-client-generator-core/test/types/built-in-types.test.ts b/packages/typespec-client-generator-core/test/types/built-in-types.test.ts index 7f97883ffb..029f85cdde 100644 --- a/packages/typespec-client-generator-core/test/types/built-in-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/built-in-types.test.ts @@ -1,7 +1,7 @@ import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { expectDiagnostics } from "@typespec/compiler/testing"; import { ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkBuiltInType } from "../../src/interfaces.js"; import { getAllModels } from "../../src/types.js"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; @@ -13,7 +13,16 @@ describe("typespec-client-generator-core: built-in types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("string", async function () { await runner.compileWithBuiltInService( ` @@ -204,12 +213,12 @@ describe("typespec-client-generator-core: built-in types", () => { }); it("armId from Core", async function () { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService( + await runner.compileWithBuiltInAzureCoreService( ` @usage(Usage.input | Usage.output) model Test { @@ -221,7 +230,7 @@ describe("typespec-client-generator-core: built-in types", () => { } ` ); - const models = runnerWithCore.context.sdkPackage.models; + const models = runner.context.sdkPackage.models; const type = models[0].properties[0].type; strictEqual(type.kind, "string"); strictEqual(type.name, "armResourceIdentifier"); @@ -230,12 +239,12 @@ describe("typespec-client-generator-core: built-in types", () => { }); it("format", async function () { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService( + await runner.compileWithBuiltInAzureCoreService( ` @usage(Usage.input | Usage.output) model Test { @@ -246,7 +255,7 @@ describe("typespec-client-generator-core: built-in types", () => { } ` ); - const models = runnerWithCore.context.sdkPackage.models; + const models = runner.context.sdkPackage.models; for (const property of models[0].properties) { strictEqual(property.kind, "property"); strictEqual( @@ -257,13 +266,13 @@ describe("typespec-client-generator-core: built-in types", () => { }); it("etag from core", async () => { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], "filter-out-core-models": false, emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService(` + await runner.compileWithBuiltInAzureCoreService(` @resource("users") @doc("Details about a user.") model User { @@ -278,7 +287,7 @@ describe("typespec-client-generator-core: built-in types", () => { @doc("Gets status.") op getStatus is GetResourceOperationStatus; `); - const userModel = runnerWithCore.context.sdkPackage.models.find( + const userModel = runner.context.sdkPackage.models.find( (x) => x.kind === "model" && x.name === "User" ); ok(userModel); diff --git a/packages/typespec-client-generator-core/test/types/bytes-types.test.ts b/packages/typespec-client-generator-core/test/types/bytes-types.test.ts index 4251598eb7..4bb7b6544d 100644 --- a/packages/typespec-client-generator-core/test/types/bytes-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/bytes-types.test.ts @@ -1,5 +1,5 @@ import { ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkBasicServiceMethod, SdkBuiltInType, SdkHttpOperation } from "../../src/interfaces.js"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; @@ -9,7 +9,16 @@ describe("typespec-client-generator-core: bytes types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); describe("bytes SdkMethodParameter", () => { it("should use service operation parameter encoding", async () => { await runner.compile(` diff --git a/packages/typespec-client-generator-core/test/types/constant-types.test.ts b/packages/typespec-client-generator-core/test/types/constant-types.test.ts index 2ec2976bcf..84ec528776 100644 --- a/packages/typespec-client-generator-core/test/types/constant-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/constant-types.test.ts @@ -1,5 +1,5 @@ -import { strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { ok, strictEqual } from "assert"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; import { getSdkTypeHelper } from "./utils.js"; @@ -9,7 +9,16 @@ describe("typespec-client-generator-core: constant types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("string", async function () { await runner.compileWithBuiltInService(` @usage(Usage.input | Usage.output) diff --git a/packages/typespec-client-generator-core/test/types/date-time-types.test.ts b/packages/typespec-client-generator-core/test/types/date-time-types.test.ts index 926f40b27b..cf0c308e44 100644 --- a/packages/typespec-client-generator-core/test/types/date-time-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/date-time-types.test.ts @@ -1,5 +1,5 @@ -import { strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { ok, strictEqual } from "assert"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; import { getSdkTypeHelper } from "./utils.js"; @@ -9,7 +9,16 @@ describe("typespec-client-generator-core: date-time types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("default", async function () { await runner.compileWithBuiltInService( ` diff --git a/packages/typespec-client-generator-core/test/types/doc-summary.test.ts b/packages/typespec-client-generator-core/test/types/doc-summary.test.ts index aefa151ff4..ec04a3649d 100644 --- a/packages/typespec-client-generator-core/test/types/doc-summary.test.ts +++ b/packages/typespec-client-generator-core/test/types/doc-summary.test.ts @@ -1,5 +1,5 @@ -import { strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { ok, strictEqual } from "assert"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { createSdkTestRunner, SdkTestRunner } from "../test-host.js"; describe("typespec-client-generator-core: doc and summary", () => { @@ -8,7 +8,16 @@ describe("typespec-client-generator-core: doc and summary", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("unicode", async () => { await runner.compileWithBuiltInService(` @usage(Usage.input | Usage.output) diff --git a/packages/typespec-client-generator-core/test/types/duration-type.test.ts b/packages/typespec-client-generator-core/test/types/duration-type.test.ts index a095b66c13..07a8cd95c7 100644 --- a/packages/typespec-client-generator-core/test/types/duration-type.test.ts +++ b/packages/typespec-client-generator-core/test/types/duration-type.test.ts @@ -1,5 +1,5 @@ -import { strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { ok, strictEqual } from "assert"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; import { getSdkTypeHelper } from "./utils.js"; @@ -9,7 +9,16 @@ describe("typespec-client-generator-core: duration types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("default", async function () { await runner.compileWithBuiltInService( ` diff --git a/packages/typespec-client-generator-core/test/types/enum-types.test.ts b/packages/typespec-client-generator-core/test/types/enum-types.test.ts index c2ffcc4b42..5ce9c439c9 100644 --- a/packages/typespec-client-generator-core/test/types/enum-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/enum-types.test.ts @@ -1,7 +1,7 @@ import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { Enum, Model, Union } from "@typespec/compiler"; import { deepEqual, deepStrictEqual, ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkEnumType, SdkModelType, SdkUnionType, UsageFlags } from "../../src/interfaces.js"; import { getClientType, getSdkEnum } from "../../src/types.js"; import { @@ -16,7 +16,16 @@ describe("typespec-client-generator-core: enum types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("string extensible", async function () { await runner.compileWithBuiltInService(` @usage(Usage.input | Usage.output) @@ -200,12 +209,12 @@ describe("typespec-client-generator-core: enum types", () => { }); it("string fixed", async function () { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService(` + await runner.compileWithBuiltInAzureCoreService(` #suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "For testing" @doc(".") @fixed @@ -227,9 +236,9 @@ describe("typespec-client-generator-core: enum types", () => { prop: DaysOfWeekFixedEnum } `); - strictEqual(runnerWithCore.context.sdkPackage.models.length, 1); - strictEqual(runnerWithCore.context.sdkPackage.enums.length, 1); - const sdkType = runnerWithCore.context.sdkPackage.enums[0]; + strictEqual(runner.context.sdkPackage.models.length, 1); + strictEqual(runner.context.sdkPackage.enums.length, 1); + const sdkType = runner.context.sdkPackage.enums[0]; strictEqual(sdkType.isFixed, true); strictEqual(sdkType.name, "DaysOfWeekFixedEnum"); strictEqual(sdkType.crossLanguageDefinitionId, "My.Service.DaysOfWeekFixedEnum"); @@ -648,12 +657,12 @@ describe("typespec-client-generator-core: enum types", () => { }); it("versioned enums with all", async () => { - const runnerWithVersion = await createSdkTestRunner({ + runner = await createSdkTestRunner({ "api-version": "all", emitterName: "@azure-tools/typespec-python", }); - await runnerWithVersion.compile( + await runner.compile( ` @versioned(Versions) @service() @@ -665,7 +674,7 @@ describe("typespec-client-generator-core: enum types", () => { } ` ); - const enums = runnerWithVersion.context.sdkPackage.enums; + const enums = runner.context.sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); strictEqual(enums[0].crossLanguageDefinitionId, "DemoService.Versions"); @@ -677,12 +686,12 @@ describe("typespec-client-generator-core: enum types", () => { }); it("versioned enums with latest", async () => { - const runnerWithVersion = await createSdkTestRunner({ + runner = await createSdkTestRunner({ "api-version": "latest", emitterName: "@azure-tools/typespec-python", }); - await runnerWithVersion.compile( + await runner.compile( ` @versioned(Versions) @service() @@ -694,7 +703,7 @@ describe("typespec-client-generator-core: enum types", () => { } ` ); - const enums = runnerWithVersion.context.sdkPackage.enums; + const enums = runner.context.sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); strictEqual(enums[0].crossLanguageDefinitionId, "DemoService.Versions"); @@ -706,12 +715,12 @@ describe("typespec-client-generator-core: enum types", () => { }); it("versioned enums with specific version", async () => { - const runnerWithVersion = await createSdkTestRunner({ + runner = await createSdkTestRunner({ "api-version": "v1", emitterName: "@azure-tools/typespec-python", }); - await runnerWithVersion.compile( + await runner.compile( ` @versioned(Versions) @service() @@ -723,7 +732,7 @@ describe("typespec-client-generator-core: enum types", () => { } ` ); - const enums = runnerWithVersion.context.sdkPackage.enums; + const enums = runner.context.sdkPackage.enums; strictEqual(enums.length, 1); strictEqual(enums[0].name, "Versions"); strictEqual(enums[0].crossLanguageDefinitionId, "DemoService.Versions"); diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index 8608236957..b31dd176fe 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -1,8 +1,8 @@ import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { expectDiagnostics } from "@typespec/compiler/testing"; import { XmlTestLibrary } from "@typespec/xml/testing"; -import { deepStrictEqual, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { deepStrictEqual, ok, strictEqual } from "assert"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkEnumValueType } from "../../src/interfaces.js"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; @@ -12,7 +12,16 @@ describe("typespec-client-generator-core: general decorators list", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("no arg", async function () { runner = await createSdkTestRunner({}, { additionalDecorators: ["TypeSpec\\.@error"] }); diff --git a/packages/typespec-client-generator-core/test/types/model-types.test.ts b/packages/typespec-client-generator-core/test/types/model-types.test.ts index 71e30c7796..5f283a9375 100644 --- a/packages/typespec-client-generator-core/test/types/model-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/model-types.test.ts @@ -1,7 +1,7 @@ import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { isErrorModel } from "@typespec/compiler"; import { deepStrictEqual, ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkBodyModelPropertyType, UsageFlags } from "../../src/interfaces.js"; import { isAzureCoreModel } from "../../src/internal-utils.js"; import { getAllModels } from "../../src/types.js"; @@ -13,7 +13,16 @@ describe("typespec-client-generator-core: model types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("basic", async () => { await runner.compile(` @service({}) @@ -690,12 +699,12 @@ describe("typespec-client-generator-core: model types", () => { }); it("filterOutCoreModels true", async () => { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService(` + await runner.compileWithBuiltInAzureCoreService(` @resource("users") @doc("Details about a user.") model User { @@ -711,12 +720,12 @@ describe("typespec-client-generator-core: model types", () => { @doc("Creates or updates a User") op createOrUpdate is StandardResourceOperations.ResourceCreateOrUpdate; `); - const models = runnerWithCore.context.sdkPackage.models; + const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); strictEqual(models[0].name, "User"); strictEqual(models[0].crossLanguageDefinitionId, "My.Service.User"); - for (const [type, sdkType] of runnerWithCore.context.modelsMap?.entries() ?? []) { + for (const [type, sdkType] of runner.context.modelsMap?.entries() ?? []) { if (isAzureCoreModel(type)) { ok(sdkType.usage !== UsageFlags.None); } @@ -724,13 +733,13 @@ describe("typespec-client-generator-core: model types", () => { }); it("filterOutCoreModels false", async () => { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], "filter-out-core-models": false, emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService(` + await runner.compileWithBuiltInAzureCoreService(` @resource("users") @doc("Details about a user.") model User { @@ -746,9 +755,7 @@ describe("typespec-client-generator-core: model types", () => { @doc("Creates or updates a User") op createOrUpdate is StandardResourceOperations.ResourceCreateOrUpdate; `); - const models = runnerWithCore.context.sdkPackage.models.sort((a, b) => - a.name.localeCompare(b.name) - ); + const models = runner.context.sdkPackage.models.sort((a, b) => a.name.localeCompare(b.name)); strictEqual(models.length, 4); strictEqual(models[0].name, "Error"); strictEqual(models[0].crossLanguageDefinitionId, "Azure.Core.Foundations.Error"); @@ -761,12 +768,12 @@ describe("typespec-client-generator-core: model types", () => { }); it("lro core filterOutCoreModels true", async () => { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService(` + await runner.compileWithBuiltInAzureCoreService(` @resource("users") @doc("Details about a user.") model User { @@ -783,20 +790,20 @@ describe("typespec-client-generator-core: model types", () => { @pollingOperation(My.Service.getStatus) op createOrUpdateUser is StandardResourceOperations.LongRunningResourceCreateOrUpdate; `); - const models = runnerWithCore.context.sdkPackage.models; + const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); strictEqual(models[0].name, "User"); strictEqual(models[0].crossLanguageDefinitionId, "My.Service.User"); }); it("lro core filterOutCoreModels false", async () => { - const runnerWithCore = await createSdkTestRunner({ + runner = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], autoUsings: ["Azure.Core"], "filter-out-core-models": false, emitterName: "@azure-tools/typespec-java", }); - await runnerWithCore.compileWithBuiltInAzureCoreService(` + await runner.compileWithBuiltInAzureCoreService(` @resource("users") @doc("Details about a user.") model User { @@ -813,9 +820,7 @@ describe("typespec-client-generator-core: model types", () => { @pollingOperation(My.Service.getStatus) op createOrUpdateUser is StandardResourceOperations.LongRunningResourceCreateOrUpdate; `); - const models = runnerWithCore.context.sdkPackage.models.sort((a, b) => - a.name.localeCompare(b.name) - ); + const models = runner.context.sdkPackage.models.sort((a, b) => a.name.localeCompare(b.name)); strictEqual(models.length, 5); strictEqual(models[0].name, "Error"); strictEqual(models[0].crossLanguageDefinitionId, "Azure.Core.Foundations.Error"); @@ -827,8 +832,8 @@ describe("typespec-client-generator-core: model types", () => { strictEqual(models[3].crossLanguageDefinitionId, "Azure.Core.ResourceOperationStatus"); strictEqual(models[4].name, "User"); strictEqual(models[4].crossLanguageDefinitionId, "My.Service.User"); - strictEqual(runnerWithCore.context.sdkPackage.enums.length, 1); - strictEqual(runnerWithCore.context.sdkPackage.enums[0].name, "OperationState"); + strictEqual(runner.context.sdkPackage.enums.length, 1); + strictEqual(runner.context.sdkPackage.enums[0].name, "OperationState"); }); it("no models filter core", async () => { await runner.compile(` diff --git a/packages/typespec-client-generator-core/test/types/multipart-types.test.ts b/packages/typespec-client-generator-core/test/types/multipart-types.test.ts index e85ab84033..8b0a04cb98 100644 --- a/packages/typespec-client-generator-core/test/types/multipart-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/multipart-types.test.ts @@ -1,6 +1,6 @@ import { expectDiagnostics } from "@typespec/compiler/testing"; import { deepEqual, ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkBodyModelPropertyType, SdkClientType, @@ -16,6 +16,17 @@ describe("typespec-client-generator-core: multipart types", () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); + it("multipart form basic", async function () { await runner.compileWithBuiltInService(` model MultiPartRequest { @@ -543,6 +554,7 @@ describe("typespec-client-generator-core: multipart types", () => { ) as SdkBodyModelPropertyType; ok(stringWithContentType); strictEqual(stringWithContentType.type.kind, "model"); + strictEqual(stringWithContentType.type.name, "MultiPartRequestStringWithContentType"); ok(stringWithContentType.multipartOptions); ok(stringWithContentType.multipartOptions.contentType); deepEqual(stringWithContentType.multipartOptions.defaultContentTypes, ["text/html"]); @@ -563,6 +575,7 @@ describe("typespec-client-generator-core: multipart types", () => { ) as SdkBodyModelPropertyType; ok(bytesWithContentType); strictEqual(bytesWithContentType.type.kind, "model"); + strictEqual(bytesWithContentType.type.name, "MultiPartRequestBytesWithContentType"); ok(bytesWithContentType.multipartOptions); ok(bytesWithContentType.multipartOptions.contentType); deepEqual(bytesWithContentType.multipartOptions.defaultContentTypes, ["image/png"]); diff --git a/packages/typespec-client-generator-core/test/types/response.test.ts b/packages/typespec-client-generator-core/test/types/response.test.ts index b77016cd49..6b37b063e8 100644 --- a/packages/typespec-client-generator-core/test/types/response.test.ts +++ b/packages/typespec-client-generator-core/test/types/response.test.ts @@ -1,5 +1,5 @@ import { ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; describe("typespec-client-generator-core: responses", () => { @@ -8,7 +8,16 @@ describe("typespec-client-generator-core: responses", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("content type shall be included in response headers", async () => { await runner.compile(` @service({}) diff --git a/packages/typespec-client-generator-core/test/types/tuple-types.test.ts b/packages/typespec-client-generator-core/test/types/tuple-types.test.ts index 81e0e03379..8b93717940 100644 --- a/packages/typespec-client-generator-core/test/types/tuple-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/tuple-types.test.ts @@ -1,5 +1,5 @@ import { ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; describe("typespec-client-generator-core: tuple types", () => { @@ -8,7 +8,16 @@ describe("typespec-client-generator-core: tuple types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("model with tupled properties", async function () { await runner.compileAndDiagnose(` @service({}) diff --git a/packages/typespec-client-generator-core/test/types/union-types.test.ts b/packages/typespec-client-generator-core/test/types/union-types.test.ts index b86da40b41..2d63dec0a0 100644 --- a/packages/typespec-client-generator-core/test/types/union-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/union-types.test.ts @@ -1,5 +1,5 @@ import { ok, strictEqual } from "assert"; -import { beforeEach, describe, it } from "vitest"; +import { afterEach, beforeEach, describe, it } from "vitest"; import { SdkArrayType, UsageFlags } from "../../src/interfaces.js"; import { SdkTestRunner, createSdkTestRunner } from "../test-host.js"; import { getSdkTypeHelper } from "./utils.js"; @@ -10,7 +10,16 @@ describe("typespec-client-generator-core: union types", () => { beforeEach(async () => { runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); }); - + afterEach(async () => { + for (const modelsOrEnums of [ + runner.context.sdkPackage.models, + runner.context.sdkPackage.enums, + ]) { + for (const item of modelsOrEnums) { + ok(item.name !== ""); + } + } + }); it("primitive union", async function () { await runner.compileWithBuiltInService( `