From b56581ce1981c3dc78cd36c1cd89265d6c551d70 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:30:49 +0000 Subject: [PATCH 1/7] Bump core from `edf272d` to `72d544c` Bumps [core](https://github.com/microsoft/typespec) from `edf272d` to `72d544c`. - [Release notes](https://github.com/microsoft/typespec/releases) - [Commits](https://github.com/microsoft/typespec/compare/edf272da71ab47e953201ceab10b78466484b06f...72d544c1eae2339401b3e9bfdd8aedd1b843326d) --- updated-dependencies: - dependency-name: core dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index edf272da71..72d544c1ea 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit edf272da71ab47e953201ceab10b78466484b06f +Subproject commit 72d544c1eae2339401b3e9bfdd8aedd1b843326d From 381802a63cd8342421d7811e1e31090b48de5295 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 31 Jul 2024 08:53:48 -0700 Subject: [PATCH 2/7] Add encode support --- packages/typespec-autorest/src/openapi.ts | 8 +++---- .../test/primitive-types.test.ts | 23 +++++++++++++++++-- .../src/rules/known-encoding.ts | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index c66b4ef4c9..12fe3a8dce 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -2180,12 +2180,12 @@ export async function getOpenAPIForService( } function mergeFormatAndEncoding( format: string | undefined, - encoding: string, + encoding: string | undefined, encodeAsFormat: string | undefined - ): string { + ): string | undefined { switch (format) { case undefined: - return encodeAsFormat ?? encoding; + return encodeAsFormat ?? encoding ?? format; case "date-time": switch (encoding) { case "rfc3339": @@ -2205,7 +2205,7 @@ export async function getOpenAPIForService( return encodeAsFormat ?? encoding; } default: - return encodeAsFormat ?? encoding; + return encodeAsFormat ?? encoding ?? format; } } diff --git a/packages/typespec-autorest/test/primitive-types.test.ts b/packages/typespec-autorest/test/primitive-types.test.ts index a8b1be7330..4a9bdf89c6 100644 --- a/packages/typespec-autorest/test/primitive-types.test.ts +++ b/packages/typespec-autorest/test/primitive-types.test.ts @@ -221,11 +221,16 @@ describe("typespec-autorest: primitives", () => { async function testEncode( scalar: string, expectedOpenApi: OpenAPI2Schema, - encoding?: string, + encoding?: string | null, encodeAs?: string ) { const encodeAsParam = encodeAs ? `, ${encodeAs}` : ""; - const encodeDecorator = encoding ? `@encode("${encoding}"${encodeAsParam})` : ""; + const encodeDecorator = + encoding === null + ? `@encode(${encodeAs})` + : encoding !== undefined + ? `@encode("${encoding}"${encodeAsParam})` + : ""; const res1 = await oapiForModel("s", `${encodeDecorator} scalar s extends ${scalar};`); deepStrictEqual(res1.defs.s, expectedOpenApi); const res2 = await oapiForModel("Test", `model Test {${encodeDecorator} prop: ${scalar}};`); @@ -287,5 +292,19 @@ describe("typespec-autorest: primitives", () => { it("set format to base64url when encoding bytes as base64url", () => testEncode("bytes", { type: "string", format: "base64url" }, "base64url")); }); + + describe("int64", () => { + it("set type: integer and format to 'int64' by default", () => + testEncode("int64", { type: "integer", format: "int64" })); + it("set type: string and format to int64 when @encode(string)", () => + testEncode("int64", { type: "string", format: "int64" }, null, "string")); + }); + + describe("decimal128", () => { + it("set type: integer and format to 'int64' by default", () => + testEncode("decimal128", { type: "number", format: "decimal" })); + it("set type: string and format to int64 when @encode(string)", () => + testEncode("decimal128", { type: "string", format: "decimal" }, null, "string")); + }); }); }); diff --git a/packages/typespec-azure-core/src/rules/known-encoding.ts b/packages/typespec-azure-core/src/rules/known-encoding.ts index 2aa4e9e68a..4bd3978987 100644 --- a/packages/typespec-azure-core/src/rules/known-encoding.ts +++ b/packages/typespec-azure-core/src/rules/known-encoding.ts @@ -22,7 +22,7 @@ export const knownEncodingRule = createRule({ create(context) { function checkEncoding(type: ModelProperty | Scalar) { const encode = getEncode(context.program, type); - if (encode) { + if (encode && encode.encoding) { if (!knownEncodings.has(encode.encoding)) { context.reportDiagnostic({ format: { From 5c419d810d8ae5fcc464d3fca1a3e4918719efd5 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 31 Jul 2024 08:54:24 -0700 Subject: [PATCH 3/7] Changelog --- ...dependabot-submodules-core-72d544c-2024-6-31-8-54-14.md | 7 +++++++ ...dependabot-submodules-core-72d544c-2024-6-31-8-54-18.md | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 .chronus/changes/dependabot-submodules-core-72d544c-2024-6-31-8-54-14.md create mode 100644 .chronus/changes/dependabot-submodules-core-72d544c-2024-6-31-8-54-18.md diff --git a/.chronus/changes/dependabot-submodules-core-72d544c-2024-6-31-8-54-14.md b/.chronus/changes/dependabot-submodules-core-72d544c-2024-6-31-8-54-14.md new file mode 100644 index 0000000000..41e66e9020 --- /dev/null +++ b/.chronus/changes/dependabot-submodules-core-72d544c-2024-6-31-8-54-14.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@azure-tools/typespec-autorest" +--- + +Add support for encoding numeric types as string \ No newline at end of file diff --git a/.chronus/changes/dependabot-submodules-core-72d544c-2024-6-31-8-54-18.md b/.chronus/changes/dependabot-submodules-core-72d544c-2024-6-31-8-54-18.md new file mode 100644 index 0000000000..e33df47351 --- /dev/null +++ b/.chronus/changes/dependabot-submodules-core-72d544c-2024-6-31-8-54-18.md @@ -0,0 +1,6 @@ +--- +changeKind: internal +packages: + - "@azure-tools/typespec-azure-core" +--- + From b3ad867403e779980d58698e2706779da56b90fc Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 31 Jul 2024 09:35:53 -0700 Subject: [PATCH 4/7] fix --- .../test/types/general-decorators-list.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a11d50683f..ba5cdb1132 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 @@ -75,7 +75,7 @@ describe("typespec-client-generator-core: general decorators list", () => { strictEqual(models.length, 1); strictEqual(models[0].properties[0].decorators[0].name, "TypeSpec.@encode"); const encodeInfo = models[0].properties[0].decorators[0].arguments[ - "encoding" + "encodingOrEncodeAs" ] as SdkEnumValueType; strictEqual(encodeInfo.value, "base64url"); expectDiagnostics(runner.context.diagnostics, []); From e7077ad2d9db6730ddb40fcb8a89a59888732e8f Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 31 Jul 2024 12:55:59 -0700 Subject: [PATCH 5/7] fix test --- .../test/types/general-decorators-list.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ba5cdb1132..57ad1517e4 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 @@ -77,7 +77,7 @@ describe("typespec-client-generator-core: general decorators list", () => { const encodeInfo = models[0].properties[0].decorators[0].arguments[ "encodingOrEncodeAs" ] as SdkEnumValueType; - strictEqual(encodeInfo.value, "base64url"); + strictEqual((encodeInfo.value as any).value, "base64url"); expectDiagnostics(runner.context.diagnostics, []); }); From 63e2948b4135733fe0e995b036be8c45d0f7e648 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 31 Jul 2024 15:32:59 -0700 Subject: [PATCH 6/7] Bump main --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index 72d544c1ea..fa70428314 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 72d544c1eae2339401b3e9bfdd8aedd1b843326d +Subproject commit fa704283140eb278d4c66a6e350969bd418d0575 From 5c096fb32a25dc6df0d71f1dfc611935dbb61d5a Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 1 Aug 2024 09:05:43 -0700 Subject: [PATCH 7/7] Lock --- pnpm-lock.yaml | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 47320e7fc1..62402179ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -570,6 +570,55 @@ importers: specifier: ^2.0.4 version: 2.0.4(@types/node@18.11.19)(@vitest/ui@2.0.4(vitest@2.0.4))(happy-dom@14.12.3)(jsdom@24.1.1)(terser@5.31.3) + core/packages/http-server-csharp: + dependencies: + '@typespec/versioning': + specifier: workspace:~ + version: link:../versioning + change-case: + specifier: ~5.4.4 + version: 5.4.4 + devDependencies: + '@types/node': + specifier: ~18.11.19 + version: 18.11.19 + '@typespec/compiler': + specifier: workspace:~ + version: link:../compiler + '@typespec/http': + specifier: workspace:~ + version: link:../http + '@typespec/library-linter': + specifier: workspace:~ + version: link:../library-linter + '@typespec/openapi': + specifier: workspace:~ + version: link:../openapi + '@typespec/rest': + specifier: workspace:~ + version: link:../rest + '@typespec/tspd': + specifier: workspace:~ + version: link:../tspd + '@vitest/coverage-v8': + specifier: ^2.0.4 + version: 2.0.4(vitest@2.0.4(@types/node@18.11.19)(@vitest/ui@2.0.4)(happy-dom@14.12.3)(jsdom@24.1.1)(terser@5.31.3)) + '@vitest/ui': + specifier: ^2.0.4 + version: 2.0.4(vitest@2.0.4) + c8: + specifier: ^10.1.2 + version: 10.1.2 + rimraf: + specifier: ~6.0.1 + version: 6.0.1 + typescript: + specifier: ~5.5.4 + version: 5.5.4 + vitest: + specifier: ^2.0.4 + version: 2.0.4(@types/node@18.11.19)(@vitest/ui@2.0.4(vitest@2.0.4))(happy-dom@14.12.3)(jsdom@24.1.1)(terser@5.31.3) + core/packages/http-server-javascript: dependencies: prettier: