From f1e35a88742f894234f765f26b68ae1e177d3c08 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Thu, 1 May 2025 15:31:09 +0000 Subject: [PATCH 1/8] [compiler] Move capitalize to compiler --- out.txt | 175 ++++++++++++++++++ packages/compiler/src/utils/index.ts | 9 +- packages/compiler/src/utils/misc.ts | 7 + packages/compiler/test/util.test.ts | 22 ++- .../http-client-python/emitter/src/utils.ts | 4 - packages/openapi3/src/schema-emitter.ts | 8 +- packages/protobuf/src/transform/index.ts | 8 +- 7 files changed, 213 insertions(+), 20 deletions(-) create mode 100644 out.txt diff --git a/out.txt b/out.txt new file mode 100644 index 00000000000..183721d55e8 --- /dev/null +++ b/out.txt @@ -0,0 +1,175 @@ +Scope: 2 of 46 workspace projects +packages/emitter-framework test$ vitest run +packages/emitter-framework test: RUN v3.0.9 /home/maorleger/workspace/typespec/packages/emitter-framework +packages/emitter-framework test: ✓ test/testing/snippet-extractor-java.test.ts (5 tests) 19ms +packages/emitter-framework test: ✓ test/testing/snippet-extractor-csharp.test.ts (5 tests) 24ms +packages/emitter-framework test: ✓ test/testing/snippet-extractor-typescript.test.ts (7 tests) 27ms +packages/emitter-framework test: ✓ test/testing/snippet-extractor-python.test.ts (2 tests) 12ms +packages/emitter-framework test: ↓ test/typescript/components/type-transform.test.tsx (10 tests | 10 skipped) +packages/emitter-framework test: ✓ test/typescript/components/value-expression.test.tsx (14 tests) 783ms +packages/emitter-framework test: ✓ test/typescript/components/function-expression.test.tsx (3 tests) 618ms +packages/emitter-framework test: ✓ test/typescript/components/arrow-function.test.tsx (3 tests) 653ms +packages/emitter-framework test: ✓ arrow functions with a `type` prop > creates a function 351ms +packages/emitter-framework test: ✓ test/typescript/components/function-type.test.tsx (3 tests) 637ms +packages/emitter-framework test: ✓ function types with a `type` prop > creates a function type 351ms +packages/emitter-framework test: ✓ test/typescript/components/member-expression.test.tsx (4 tests) 758ms +packages/emitter-framework test: ✓ test/typescript/components/type-alias-declaration.test.tsx (5 tests) 895ms +packages/emitter-framework test: ✓ Typescript Type Alias Declaration > Type Alias bound to Typespec Scalar > Scalar extends utcDateTime > creates a type alias declaration for a utcDateTime without encoding 415ms +packages/emitter-framework test: ✓ test/typescript/components/enum-declaration.test.tsx (4 tests) 705ms +packages/emitter-framework test: ✓ Typescript Enum Declaration > takes an enum type parameter 378ms +packages/emitter-framework test: ✓ test/typescript/components/function-declaration.test.tsx (7 tests | 1 skipped) 1065ms +packages/emitter-framework test: ✓ Typescript Function Declaration > Function bound to Typespec Types > Bound to Operation > creates a function 432ms +packages/emitter-framework test: ✓ test/typescript/components/union-declaration.test.tsx (6 tests) 1070ms +packages/emitter-framework test: ✓ Typescript Union Declaration > Union not bound to Typespec Types > creates a union declaration 505ms +packages/emitter-framework test: ✓ test/typescript/components/interface-method.test.tsx (8 tests) 1042ms +packages/emitter-framework test: ✓ interface methods with a `type` prop > creates a interface method 379ms +packages/emitter-framework test: ✓ test/typescript/components/interface-declaration.test.tsx (17 tests) 1732ms +packages/emitter-framework test: ✓ Typescript Interface > Interface bound to Typespec Types > Bound to Model > creates an interface that extends a model for Record spread 557ms +packages/emitter-framework test: Test Files 15 passed | 1 skipped (16) +packages/emitter-framework test: Tests 92 passed | 11 skipped (103) +packages/emitter-framework test: Start at 22:25:25 +packages/emitter-framework test: Duration 6.47s (transform 9.23s, setup 0ms, collect 62.40s, tests 10.04s, environment 5ms, prepare 3.66s) +packages/emitter-framework test: Done +packages/http-client-js test$ vitest run +packages/http-client-js test: RUN v3.0.9 /home/maorleger/workspace/typespec/packages/http-client-js +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/encoding/bytes_body.md > Scenario: Should not encode a bytes data when the body is bytes > Test: ts src/api/testClientOperations.ts function foo +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/anonymous_part.md > Scenario: Should handle an http part with anonymous model > Test: ts src/api/testClientOperations.ts function foo +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unsupported content type. Falling back to json +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: Basic file part > Test: ts src/models/models.ts interface RequestBody +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: Basic file part > Test: ts src/api/testClientOperations.ts function doThing +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: With part content type > Test: ts src/models/models.ts interface PngFile +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: With part content type > Test: ts src/models/models.ts interface RequestBody +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: With part content type > Test: ts src/api/testClientOperations.ts function doThing +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: Multiple files > Test: ts src/models/models.ts interface RequestBody +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: Multiple files > Test: ts src/api/testClientOperations.ts function doThing +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file_content_type.md > Scenario: Should handle part files with specific content type > Test: ts src/api/testClientOperations.ts function imageJpegContentType +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file_content_type.md > Scenario: Should handle part files with specific content type > Test: ts src/models/internal/serializers.ts function jsonFileWithHttpPartSpecificContentTypeRequestToApplicationTransform +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file_content_type.md > Scenario: Should handle part files with specific content type > Test: ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToApplicationTransform +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file_content_type.md > Scenario: Should handle part files with specific content type > Test: ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToTransportTransform +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/non-string-float.md > Scenario: Tests content-type: multipart/form-data for non string > Test: ts src/api/testClientOperations.ts function float +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unsupported content type. Falling back to json +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/simple_part.md > Scenario: Simple multipart part > Test: ts src/models/models.ts interface Foo +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unsupported content type. Falling back to json +packages/http-client-js test: Unsupported content type. Falling back to json +packages/http-client-js test: Unsupported content type. Falling back to json +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/simple_part.md > Scenario: Simple multipart part > Test: ts src/api/testClientOperations.ts function doThing +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unsupported content type. Falling back to json +packages/http-client-js test: Unsupported content type. Falling back to json +packages/http-client-js test: Unsupported content type. Falling back to json +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/constant_as_optional.md > Scenario: Should emit an operation that has a content type with a single possible value > Test: ts src/api/testClientOperations.ts function get +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: `Content-Type` header ignored because there is no body. +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/constant_as_optional.md > Scenario: Should emit an operation that has a content type with a single possible value > Test: ts src/api/testClientOperations.ts interface GetOptions +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: `Content-Type` header ignored because there is no body. +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/constant_as_optional.md > Scenario: Should emit an operation that has a content type with a single possible value > Test: ts src/testClient.ts class TestClient +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: `Content-Type` header ignored because there is no body. +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/default_value_as_optional.md > Scenario: Should emit an operation that has a default value > Test: ts src/api/testClientOperations.ts function get +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: `Content-Type` header ignored because there is no body. +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/default_value_as_optional.md > Scenario: Should emit an operation that has a default value > Test: ts src/api/testClientOperations.ts interface GetOptions +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: `Content-Type` header ignored because there is no body. +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/default_value_as_optional.md > Scenario: Should emit an operation that has a default value > Test: ts src/testClient.ts class TestClient +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: `Content-Type` header ignored because there is no body. +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/file.md > Scenario: Should handle File Parts > Test: ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToApplicationTransform +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/file.md > Scenario: Should handle File Parts > Test: ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToTransportTransform +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/file.md > Scenario: Should handle File Parts > Test: ts src/models/internal/serializers.ts function jsonFileToTransportTransform +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/multipart.md > Scenario: Should emit serializer and deserializer correctly for properties with primitive array type > Test: ts src/models/models.ts interface FileSpecificContentType +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/multipart.md > Scenario: Should emit serializer and deserializer correctly for properties with primitive array type > Test: ts src/models/models.ts interface FileWithHttpPartSpecificContentTypeRequest +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/multipart.md > Scenario: Should emit serializer and deserializer correctly for properties with primitive array type > Test: ts src/api/testClientOperations.ts function create +packages/http-client-js test: Warning compiling code: +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: Unknown encoding +packages/http-client-js test: ✓ test/scenarios.test.ts (249 tests | 4 skipped) 46138ms +packages/http-client-js test: ✓ Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/additional-properties/extends.md > Scenario: Should generate a model with an additional properties defined as extending a Record > Test: ts src/models/models.ts interface Widget 1457ms +packages/http-client-js test: ✓ Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/only_optional.md > Scenario: Should emit an operation that has only optional parameters > Test: ts src/testClient.ts class TestClient 616ms +packages/http-client-js test: Test Files 1 passed (1) +packages/http-client-js test: Tests 245 passed | 4 skipped (249) +packages/http-client-js test: Start at 22:25:32 +packages/http-client-js test: Duration 48.54s (transform 1.46s, setup 0ms, collect 1.82s, tests 46.14s, environment 0ms, prepare 104ms) +packages/http-client-js test: Done diff --git a/packages/compiler/src/utils/index.ts b/packages/compiler/src/utils/index.ts index 2af3b409d38..94d7b0bfb78 100644 --- a/packages/compiler/src/utils/index.ts +++ b/packages/compiler/src/utils/index.ts @@ -3,5 +3,12 @@ // Be explicit about what get exported so we don't export utils that are not meant to be public. // --------------------------------------- export { DuplicateTracker } from "./duplicate-tracker.js"; -export { Queue, TwoLevelMap, createRekeyableMap, deepClone, deepEquals } from "./misc.js"; +export { + Queue, + TwoLevelMap, + capitalize, + createRekeyableMap, + deepClone, + deepEquals, +} from "./misc.js"; export { useStateMap, useStateSet } from "./state-accessor.js"; diff --git a/packages/compiler/src/utils/misc.ts b/packages/compiler/src/utils/misc.ts index df6d3aa7e60..f7696ca935d 100644 --- a/packages/compiler/src/utils/misc.ts +++ b/packages/compiler/src/utils/misc.ts @@ -480,3 +480,10 @@ class RekeyableMapImpl implements RekeyableMap { return true; } } + +/** + * Simple utility function to capitalize a string. + */ +export function capitalize(s: S): Capitalize { + return (s.charAt(0).toUpperCase() + s.slice(1)) as Capitalize; +} diff --git a/packages/compiler/test/util.test.ts b/packages/compiler/test/util.test.ts index a51013a58b0..ae538086260 100644 --- a/packages/compiler/test/util.test.ts +++ b/packages/compiler/test/util.test.ts @@ -1,7 +1,7 @@ import { deepStrictEqual } from "assert"; import { beforeEach, describe, it } from "vitest"; import { RekeyableMap } from "../src/index.js"; -import { createRekeyableMap } from "../src/utils/misc.js"; +import { capitalize, createRekeyableMap } from "../src/utils/misc.js"; describe("compiler: util", () => { describe("RekeyableMap", () => { @@ -94,4 +94,24 @@ describe("compiler: util", () => { ); }); }); + + describe("capitalize", () => { + it("should capitalize the first letter of a string", () => { + const str = "hello world"; + const result = capitalize(str); + deepStrictEqual(result, "Hello world"); + }); + + it("should return an empty string when input is empty", () => { + const str = ""; + const result = capitalize(str); + deepStrictEqual(result, ""); + }); + + it("should handle single-character strings", () => { + const str = "a"; + const result = capitalize(str); + deepStrictEqual(result, "A"); + }); + }); }); diff --git a/packages/http-client-python/emitter/src/utils.ts b/packages/http-client-python/emitter/src/utils.ts index 4e346d50a13..01b91c08da9 100644 --- a/packages/http-client-python/emitter/src/utils.ts +++ b/packages/http-client-python/emitter/src/utils.ts @@ -243,10 +243,6 @@ export function isAzureCoreErrorResponse(t: SdkType | undefined): boolean { ); } -export function capitalize(name: string): string { - return name[0].toUpperCase() + name.slice(1); -} - const LIB_NAMESPACE = [ "azure.core", "azure.resourcemanager", diff --git a/packages/openapi3/src/schema-emitter.ts b/packages/openapi3/src/schema-emitter.ts index c51327f9255..fec5a688e6d 100644 --- a/packages/openapi3/src/schema-emitter.ts +++ b/packages/openapi3/src/schema-emitter.ts @@ -54,6 +54,7 @@ import { resolveEncodedName, } from "@typespec/compiler"; import { $ } from "@typespec/compiler/typekit"; +import { capitalize } from "@typespec/compiler/utils"; import { MetadataInfo, Visibility, getVisibilitySuffix } from "@typespec/http"; import { checkDuplicateTypeName, @@ -860,10 +861,3 @@ export const Builders = { return builder; }, } as const; - -/** - * Simple utility function to capitalize a string. - */ -function capitalize(s: S) { - return (s.slice(0, 1).toUpperCase() + s.slice(1)) as Capitalize; -} diff --git a/packages/protobuf/src/transform/index.ts b/packages/protobuf/src/transform/index.ts index fe79b90650a..f7b8d79b06a 100644 --- a/packages/protobuf/src/transform/index.ts +++ b/packages/protobuf/src/transform/index.ts @@ -27,6 +27,7 @@ import { Union, } from "@typespec/compiler"; import { SyntaxKind } from "@typespec/compiler/ast"; +import { capitalize } from "@typespec/compiler/utils"; import { map, matchType, @@ -1005,13 +1006,6 @@ function isArray(t: Type) { return t.kind === "Model" && t.name === "Array" && t.namespace?.name === "TypeSpec"; } -/** - * Simple utility function to capitalize a string. - */ -function capitalize(s: S) { - return (s.slice(0, 1).toUpperCase() + s.slice(1)) as Capitalize; -} - /** * Gets the syntactic return type target for an operation. * From 40c62cc6c31423d5705be1e57bf867d5c2c89a18 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Thu, 1 May 2025 15:35:18 +0000 Subject: [PATCH 2/8] chronus --- .chronus/changes/capitalize-util-2025-4-1-15-35-12.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .chronus/changes/capitalize-util-2025-4-1-15-35-12.md diff --git a/.chronus/changes/capitalize-util-2025-4-1-15-35-12.md b/.chronus/changes/capitalize-util-2025-4-1-15-35-12.md new file mode 100644 index 00000000000..ca995def086 --- /dev/null +++ b/.chronus/changes/capitalize-util-2025-4-1-15-35-12.md @@ -0,0 +1,10 @@ +--- +changeKind: feature +packages: + - "@typespec/http-client-python" + - "@typespec/compiler" + - "@typespec/openapi3" + - "@typespec/protobuf" +--- + +Add "capitalize" string helper to compiler \ No newline at end of file From 64d0c84cb6d4ad78d1dc2f154a4c690f1b268d6f Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Thu, 1 May 2025 16:49:36 +0000 Subject: [PATCH 3/8] revert http-python --- .chronus/changes/capitalize-util-2025-4-1-15-35-12.md | 1 - packages/http-client-python/emitter/src/utils.ts | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.chronus/changes/capitalize-util-2025-4-1-15-35-12.md b/.chronus/changes/capitalize-util-2025-4-1-15-35-12.md index ca995def086..50974492547 100644 --- a/.chronus/changes/capitalize-util-2025-4-1-15-35-12.md +++ b/.chronus/changes/capitalize-util-2025-4-1-15-35-12.md @@ -1,7 +1,6 @@ --- changeKind: feature packages: - - "@typespec/http-client-python" - "@typespec/compiler" - "@typespec/openapi3" - "@typespec/protobuf" diff --git a/packages/http-client-python/emitter/src/utils.ts b/packages/http-client-python/emitter/src/utils.ts index 01b91c08da9..4e346d50a13 100644 --- a/packages/http-client-python/emitter/src/utils.ts +++ b/packages/http-client-python/emitter/src/utils.ts @@ -243,6 +243,10 @@ export function isAzureCoreErrorResponse(t: SdkType | undefined): boolean { ); } +export function capitalize(name: string): string { + return name[0].toUpperCase() + name.slice(1); +} + const LIB_NAMESPACE = [ "azure.core", "azure.resourcemanager", From 1705220b06ef06ceaa5f4088fd996bf435242b2a Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Thu, 1 May 2025 17:18:06 +0000 Subject: [PATCH 4/8] remove extra file --- out.txt | 175 -------------------------------------------------------- 1 file changed, 175 deletions(-) delete mode 100644 out.txt diff --git a/out.txt b/out.txt deleted file mode 100644 index 183721d55e8..00000000000 --- a/out.txt +++ /dev/null @@ -1,175 +0,0 @@ -Scope: 2 of 46 workspace projects -packages/emitter-framework test$ vitest run -packages/emitter-framework test: RUN v3.0.9 /home/maorleger/workspace/typespec/packages/emitter-framework -packages/emitter-framework test: ✓ test/testing/snippet-extractor-java.test.ts (5 tests) 19ms -packages/emitter-framework test: ✓ test/testing/snippet-extractor-csharp.test.ts (5 tests) 24ms -packages/emitter-framework test: ✓ test/testing/snippet-extractor-typescript.test.ts (7 tests) 27ms -packages/emitter-framework test: ✓ test/testing/snippet-extractor-python.test.ts (2 tests) 12ms -packages/emitter-framework test: ↓ test/typescript/components/type-transform.test.tsx (10 tests | 10 skipped) -packages/emitter-framework test: ✓ test/typescript/components/value-expression.test.tsx (14 tests) 783ms -packages/emitter-framework test: ✓ test/typescript/components/function-expression.test.tsx (3 tests) 618ms -packages/emitter-framework test: ✓ test/typescript/components/arrow-function.test.tsx (3 tests) 653ms -packages/emitter-framework test: ✓ arrow functions with a `type` prop > creates a function 351ms -packages/emitter-framework test: ✓ test/typescript/components/function-type.test.tsx (3 tests) 637ms -packages/emitter-framework test: ✓ function types with a `type` prop > creates a function type 351ms -packages/emitter-framework test: ✓ test/typescript/components/member-expression.test.tsx (4 tests) 758ms -packages/emitter-framework test: ✓ test/typescript/components/type-alias-declaration.test.tsx (5 tests) 895ms -packages/emitter-framework test: ✓ Typescript Type Alias Declaration > Type Alias bound to Typespec Scalar > Scalar extends utcDateTime > creates a type alias declaration for a utcDateTime without encoding 415ms -packages/emitter-framework test: ✓ test/typescript/components/enum-declaration.test.tsx (4 tests) 705ms -packages/emitter-framework test: ✓ Typescript Enum Declaration > takes an enum type parameter 378ms -packages/emitter-framework test: ✓ test/typescript/components/function-declaration.test.tsx (7 tests | 1 skipped) 1065ms -packages/emitter-framework test: ✓ Typescript Function Declaration > Function bound to Typespec Types > Bound to Operation > creates a function 432ms -packages/emitter-framework test: ✓ test/typescript/components/union-declaration.test.tsx (6 tests) 1070ms -packages/emitter-framework test: ✓ Typescript Union Declaration > Union not bound to Typespec Types > creates a union declaration 505ms -packages/emitter-framework test: ✓ test/typescript/components/interface-method.test.tsx (8 tests) 1042ms -packages/emitter-framework test: ✓ interface methods with a `type` prop > creates a interface method 379ms -packages/emitter-framework test: ✓ test/typescript/components/interface-declaration.test.tsx (17 tests) 1732ms -packages/emitter-framework test: ✓ Typescript Interface > Interface bound to Typespec Types > Bound to Model > creates an interface that extends a model for Record spread 557ms -packages/emitter-framework test: Test Files 15 passed | 1 skipped (16) -packages/emitter-framework test: Tests 92 passed | 11 skipped (103) -packages/emitter-framework test: Start at 22:25:25 -packages/emitter-framework test: Duration 6.47s (transform 9.23s, setup 0ms, collect 62.40s, tests 10.04s, environment 5ms, prepare 3.66s) -packages/emitter-framework test: Done -packages/http-client-js test$ vitest run -packages/http-client-js test: RUN v3.0.9 /home/maorleger/workspace/typespec/packages/http-client-js -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/encoding/bytes_body.md > Scenario: Should not encode a bytes data when the body is bytes > Test: ts src/api/testClientOperations.ts function foo -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/anonymous_part.md > Scenario: Should handle an http part with anonymous model > Test: ts src/api/testClientOperations.ts function foo -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unsupported content type. Falling back to json -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: Basic file part > Test: ts src/models/models.ts interface RequestBody -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: Basic file part > Test: ts src/api/testClientOperations.ts function doThing -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: With part content type > Test: ts src/models/models.ts interface PngFile -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: With part content type > Test: ts src/models/models.ts interface RequestBody -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: With part content type > Test: ts src/api/testClientOperations.ts function doThing -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: Multiple files > Test: ts src/models/models.ts interface RequestBody -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file.md > Scenario: Multiple files > Test: ts src/api/testClientOperations.ts function doThing -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file_content_type.md > Scenario: Should handle part files with specific content type > Test: ts src/api/testClientOperations.ts function imageJpegContentType -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file_content_type.md > Scenario: Should handle part files with specific content type > Test: ts src/models/internal/serializers.ts function jsonFileWithHttpPartSpecificContentTypeRequestToApplicationTransform -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file_content_type.md > Scenario: Should handle part files with specific content type > Test: ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToApplicationTransform -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/file_content_type.md > Scenario: Should handle part files with specific content type > Test: ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToTransportTransform -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/non-string-float.md > Scenario: Tests content-type: multipart/form-data for non string > Test: ts src/api/testClientOperations.ts function float -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unsupported content type. Falling back to json -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/simple_part.md > Scenario: Simple multipart part > Test: ts src/models/models.ts interface Foo -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unsupported content type. Falling back to json -packages/http-client-js test: Unsupported content type. Falling back to json -packages/http-client-js test: Unsupported content type. Falling back to json -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/multipart/simple_part.md > Scenario: Simple multipart part > Test: ts src/api/testClientOperations.ts function doThing -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unsupported content type. Falling back to json -packages/http-client-js test: Unsupported content type. Falling back to json -packages/http-client-js test: Unsupported content type. Falling back to json -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/constant_as_optional.md > Scenario: Should emit an operation that has a content type with a single possible value > Test: ts src/api/testClientOperations.ts function get -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: `Content-Type` header ignored because there is no body. -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/constant_as_optional.md > Scenario: Should emit an operation that has a content type with a single possible value > Test: ts src/api/testClientOperations.ts interface GetOptions -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: `Content-Type` header ignored because there is no body. -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/constant_as_optional.md > Scenario: Should emit an operation that has a content type with a single possible value > Test: ts src/testClient.ts class TestClient -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: `Content-Type` header ignored because there is no body. -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/default_value_as_optional.md > Scenario: Should emit an operation that has a default value > Test: ts src/api/testClientOperations.ts function get -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: `Content-Type` header ignored because there is no body. -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/default_value_as_optional.md > Scenario: Should emit an operation that has a default value > Test: ts src/api/testClientOperations.ts interface GetOptions -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: `Content-Type` header ignored because there is no body. -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/default_value_as_optional.md > Scenario: Should emit an operation that has a default value > Test: ts src/testClient.ts class TestClient -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: `Content-Type` header ignored because there is no body. -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/file.md > Scenario: Should handle File Parts > Test: ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToApplicationTransform -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/file.md > Scenario: Should handle File Parts > Test: ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToTransportTransform -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/file.md > Scenario: Should handle File Parts > Test: ts src/models/internal/serializers.ts function jsonFileToTransportTransform -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/multipart.md > Scenario: Should emit serializer and deserializer correctly for properties with primitive array type > Test: ts src/models/models.ts interface FileSpecificContentType -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/multipart.md > Scenario: Should emit serializer and deserializer correctly for properties with primitive array type > Test: ts src/models/models.ts interface FileWithHttpPartSpecificContentTypeRequest -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: stderr | test/scenarios.test.ts > Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/serializers/multipart.md > Scenario: Should emit serializer and deserializer correctly for properties with primitive array type > Test: ts src/api/testClientOperations.ts function create -packages/http-client-js test: Warning compiling code: -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: Unknown encoding -packages/http-client-js test: ✓ test/scenarios.test.ts (249 tests | 4 skipped) 46138ms -packages/http-client-js test: ✓ Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/additional-properties/extends.md > Scenario: Should generate a model with an additional properties defined as extending a Record > Test: ts src/models/models.ts interface Widget 1457ms -packages/http-client-js test: ✓ Scenario File: /home/maorleger/workspace/typespec/packages/http-client-js/test/scenarios/operation-parameters/only_optional.md > Scenario: Should emit an operation that has only optional parameters > Test: ts src/testClient.ts class TestClient 616ms -packages/http-client-js test: Test Files 1 passed (1) -packages/http-client-js test: Tests 245 passed | 4 skipped (249) -packages/http-client-js test: Start at 22:25:32 -packages/http-client-js test: Duration 48.54s (transform 1.46s, setup 0ms, collect 1.82s, tests 46.14s, environment 0ms, prepare 104ms) -packages/http-client-js test: Done From d1f70626af9aeb300778a334c86dd0e77eb5fe22 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 2 May 2025 14:34:58 +0000 Subject: [PATCH 5/8] add casing subpath export --- packages/compiler/package.json | 4 ++++ packages/compiler/src/casing/index.ts | 6 ++++++ packages/compiler/src/utils/index.ts | 9 +-------- packages/compiler/src/utils/misc.ts | 7 ------- packages/compiler/test/casing.test.ts | 16 ++++++++++++++++ packages/compiler/test/util.test.ts | 22 +--------------------- packages/openapi3/src/schema-emitter.ts | 2 +- packages/protobuf/src/transform/index.ts | 2 +- 8 files changed, 30 insertions(+), 38 deletions(-) create mode 100644 packages/compiler/src/casing/index.ts create mode 100644 packages/compiler/test/casing.test.ts diff --git a/packages/compiler/package.json b/packages/compiler/package.json index 26cd396491b..cba391f104a 100644 --- a/packages/compiler/package.json +++ b/packages/compiler/package.json @@ -59,6 +59,10 @@ }, "./internals/prettier-formatter": { "import": "./dist/src/internals/prettier-formatter.js" + }, + "./casing": { + "types": "./dist/src/casing/index.d.ts", + "default": "./dist/src/casing/index.js" } }, "browser": { diff --git a/packages/compiler/src/casing/index.ts b/packages/compiler/src/casing/index.ts new file mode 100644 index 00000000000..077c8f9393b --- /dev/null +++ b/packages/compiler/src/casing/index.ts @@ -0,0 +1,6 @@ +/** + * Simple utility function to capitalize a string. + */ +export function capitalize(s: S): Capitalize { + return (s.charAt(0).toUpperCase() + s.slice(1)) as Capitalize; +} diff --git a/packages/compiler/src/utils/index.ts b/packages/compiler/src/utils/index.ts index 94d7b0bfb78..2af3b409d38 100644 --- a/packages/compiler/src/utils/index.ts +++ b/packages/compiler/src/utils/index.ts @@ -3,12 +3,5 @@ // Be explicit about what get exported so we don't export utils that are not meant to be public. // --------------------------------------- export { DuplicateTracker } from "./duplicate-tracker.js"; -export { - Queue, - TwoLevelMap, - capitalize, - createRekeyableMap, - deepClone, - deepEquals, -} from "./misc.js"; +export { Queue, TwoLevelMap, createRekeyableMap, deepClone, deepEquals } from "./misc.js"; export { useStateMap, useStateSet } from "./state-accessor.js"; diff --git a/packages/compiler/src/utils/misc.ts b/packages/compiler/src/utils/misc.ts index f7696ca935d..df6d3aa7e60 100644 --- a/packages/compiler/src/utils/misc.ts +++ b/packages/compiler/src/utils/misc.ts @@ -480,10 +480,3 @@ class RekeyableMapImpl implements RekeyableMap { return true; } } - -/** - * Simple utility function to capitalize a string. - */ -export function capitalize(s: S): Capitalize { - return (s.charAt(0).toUpperCase() + s.slice(1)) as Capitalize; -} diff --git a/packages/compiler/test/casing.test.ts b/packages/compiler/test/casing.test.ts new file mode 100644 index 00000000000..9ded384a3b0 --- /dev/null +++ b/packages/compiler/test/casing.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from "vitest"; +import { capitalize } from "../src/casing/index.js"; + +describe("capitalize", () => { + it("should capitalize the first letter of a string", () => { + expect(capitalize("hello world")).toEqual("Hello world"); + }); + + it("should return an empty string when input is empty", () => { + expect(capitalize("")).toEqual(""); + }); + + it("should handle single-character strings", () => { + expect(capitalize("a")).toEqual("A"); + }); +}); diff --git a/packages/compiler/test/util.test.ts b/packages/compiler/test/util.test.ts index ae538086260..a51013a58b0 100644 --- a/packages/compiler/test/util.test.ts +++ b/packages/compiler/test/util.test.ts @@ -1,7 +1,7 @@ import { deepStrictEqual } from "assert"; import { beforeEach, describe, it } from "vitest"; import { RekeyableMap } from "../src/index.js"; -import { capitalize, createRekeyableMap } from "../src/utils/misc.js"; +import { createRekeyableMap } from "../src/utils/misc.js"; describe("compiler: util", () => { describe("RekeyableMap", () => { @@ -94,24 +94,4 @@ describe("compiler: util", () => { ); }); }); - - describe("capitalize", () => { - it("should capitalize the first letter of a string", () => { - const str = "hello world"; - const result = capitalize(str); - deepStrictEqual(result, "Hello world"); - }); - - it("should return an empty string when input is empty", () => { - const str = ""; - const result = capitalize(str); - deepStrictEqual(result, ""); - }); - - it("should handle single-character strings", () => { - const str = "a"; - const result = capitalize(str); - deepStrictEqual(result, "A"); - }); - }); }); diff --git a/packages/openapi3/src/schema-emitter.ts b/packages/openapi3/src/schema-emitter.ts index fec5a688e6d..6552f5e1b34 100644 --- a/packages/openapi3/src/schema-emitter.ts +++ b/packages/openapi3/src/schema-emitter.ts @@ -54,7 +54,7 @@ import { resolveEncodedName, } from "@typespec/compiler"; import { $ } from "@typespec/compiler/typekit"; -import { capitalize } from "@typespec/compiler/utils"; +import { capitalize } from "@typespec/compiler/casing"; import { MetadataInfo, Visibility, getVisibilitySuffix } from "@typespec/http"; import { checkDuplicateTypeName, diff --git a/packages/protobuf/src/transform/index.ts b/packages/protobuf/src/transform/index.ts index f7b8d79b06a..9c8402f0383 100644 --- a/packages/protobuf/src/transform/index.ts +++ b/packages/protobuf/src/transform/index.ts @@ -27,7 +27,7 @@ import { Union, } from "@typespec/compiler"; import { SyntaxKind } from "@typespec/compiler/ast"; -import { capitalize } from "@typespec/compiler/utils"; +import { capitalize } from "@typespec/compiler/casing"; import { map, matchType, From e7885a93418248f489accb29b8cc6f8dce88b603 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 2 May 2025 14:46:38 +0000 Subject: [PATCH 6/8] use capitalize in tk --- packages/compiler/src/typekit/utils/get-plausible-name.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/compiler/src/typekit/utils/get-plausible-name.ts b/packages/compiler/src/typekit/utils/get-plausible-name.ts index 18e1514085b..9f9096032ae 100644 --- a/packages/compiler/src/typekit/utils/get-plausible-name.ts +++ b/packages/compiler/src/typekit/utils/get-plausible-name.ts @@ -1,3 +1,4 @@ +import { capitalize } from "../../casing/index.js"; import { isTemplateInstance } from "../../core/type-utils.js"; import { Enum, Interface, Model, Scalar, Union } from "../../core/types.js"; @@ -14,9 +15,9 @@ export function getPlausibleName(type: Model | Union | Enum | Scalar | Interface if (a.entityKind === "Type") { switch (a.kind) { case "Scalar": - // Box is not a scalar so capital case naming convention applies const name = getPlausibleName(a); - return name.charAt(0).toUpperCase() + name.slice(1); + // Box is not a scalar so capital case naming convention applies + return capitalize(name); case "Model": case "Interface": case "Enum": From 77ba1eed3bdfb708a7aa97e67ef2fab99883b556 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 2 May 2025 14:50:51 +0000 Subject: [PATCH 7/8] Format --- packages/openapi3/src/schema-emitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/openapi3/src/schema-emitter.ts b/packages/openapi3/src/schema-emitter.ts index 6552f5e1b34..9f597413100 100644 --- a/packages/openapi3/src/schema-emitter.ts +++ b/packages/openapi3/src/schema-emitter.ts @@ -53,8 +53,8 @@ import { isSecret, resolveEncodedName, } from "@typespec/compiler"; -import { $ } from "@typespec/compiler/typekit"; import { capitalize } from "@typespec/compiler/casing"; +import { $ } from "@typespec/compiler/typekit"; import { MetadataInfo, Visibility, getVisibilitySuffix } from "@typespec/http"; import { checkDuplicateTypeName, From 47112c91b4d520fb2348e45c5e5e542282bbf743 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 2 May 2025 10:44:26 -0700 Subject: [PATCH 8/8] Update packages/compiler/package.json Co-authored-by: Timothee Guerin --- packages/compiler/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/compiler/package.json b/packages/compiler/package.json index cba391f104a..87424b59ddc 100644 --- a/packages/compiler/package.json +++ b/packages/compiler/package.json @@ -61,8 +61,7 @@ "import": "./dist/src/internals/prettier-formatter.js" }, "./casing": { - "types": "./dist/src/casing/index.d.ts", - "default": "./dist/src/casing/index.js" + "import": "./dist/src/casing/index.js" } }, "browser": {