From 89622d6b669213481803e66e767e8ad30bd1a9a0 Mon Sep 17 00:00:00 2001 From: Kanna Kim Date: Sun, 12 Jul 2026 10:43:55 -0500 Subject: [PATCH] [typescript-fetch] Fix Omit generic using baseName for readOnly fields in API requests (#19572) --- .../resources/typescript-fetch/apis.mustache | 2 +- .../TypeScriptFetchClientCodegenTest.java | 14 +++++++ .../3_0/typescript-fetch/issue_19572.yaml | 38 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 modules/openapi-generator/src/test/resources/3_0/typescript-fetch/issue_19572.yaml diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache index c045f6241e25..9abbf2590231 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache @@ -25,7 +25,7 @@ import { {{#allParams.0}} export interface {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request { {{#allParams}} - {{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{#hasReadOnly}}Omit<{{{dataType}}}, {{#readOnlyVars}}'{{baseName}}'{{^-last}}|{{/-last}}{{/readOnlyVars}}>{{/hasReadOnly}}{{^hasReadOnly}}{{{dataType}}}{{/hasReadOnly}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}; + {{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{#hasReadOnly}}Omit<{{{dataType}}}, {{#readOnlyVars}}'{{name}}'{{^-last}}|{{/-last}}{{/readOnlyVars}}>{{/hasReadOnly}}{{^hasReadOnly}}{{{dataType}}}{{/hasReadOnly}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}; {{/allParams}} } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java index a32753a89c20..5b3b81cdf257 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java @@ -680,6 +680,20 @@ public void testIssue23380_OmitUsesCorrectPropertyName() throws Exception { TestUtils.assertFileContains(modelPath, "export function MissionToJSONTyped(value?: Omit | null, ignoreDiscriminator: boolean = false): any {"); } + @Test(description = "Verify Omit uses the camelCase property name instead of the baseName for readOnly fields in API requests") + public void testIssue19572_OmitUsesCorrectPropertyNameInApi() throws Exception { + File output = generate( + Collections.emptyMap(), + "src/test/resources/3_0/typescript-fetch/issue_19572.yaml" + ); + + Path modelPath = Paths.get(output + "/apis/DefaultApi.ts"); + TestUtils.assertFileExists(modelPath); + // Ensure Omit uses camelCase names like 'createdAt' and 'updatedAt' instead of snake_case 'created_at' and 'updated_at' + TestUtils.assertFileContains(modelPath, "export interface FinancingOptionCreateRequest {"); + TestUtils.assertFileContains(modelPath, " financingOption?: Omit;"); + } + private static File generate( Map properties ) throws IOException { diff --git a/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/issue_19572.yaml b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/issue_19572.yaml new file mode 100644 index 000000000000..1e06de2d284f --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/issue_19572.yaml @@ -0,0 +1,38 @@ +openapi: 3.0.0 +info: + title: Test API + version: 1.0.0 +paths: + /financing-options: + post: + operationId: financingOptionCreate + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/FinancingOption' + responses: + '200': + description: OK +components: + schemas: + FinancingOption: + type: object + properties: + id: + type: string + readOnly: true + created_at: + type: string + format: date-time + readOnly: true + updated_at: + type: string + format: date-time + readOnly: true + foo: + type: string + readOnly: true + bar: + type: string + readOnly: true