diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache index 961aa9c2761c..5f4c379724b1 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache @@ -145,7 +145,7 @@ export function {{classname}}ToJSON(json: any): {{classname}} { return {{classname}}ToJSONTyped(json, false); } -export function {{classname}}ToJSONTyped(value?: {{#hasReadOnly}}Omit<{{classname}}, {{#readOnlyVars}}'{{baseName}}'{{^-last}}|{{/-last}}{{/readOnlyVars}}>{{/hasReadOnly}}{{^hasReadOnly}}{{classname}}{{/hasReadOnly}} | null, ignoreDiscriminator: boolean = false): any { +export function {{classname}}ToJSONTyped(value?: {{#hasReadOnly}}Omit<{{classname}}, {{#readOnlyVars}}'{{name}}'{{^-last}}|{{/-last}}{{/readOnlyVars}}>{{/hasReadOnly}}{{^hasReadOnly}}{{classname}}{{/hasReadOnly}} | null, ignoreDiscriminator: boolean = false): any { {{#hasVars}} if (value == null) { return value; 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 8cdc317434da..a32753a89c20 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 @@ -667,6 +667,19 @@ public void testOptionalNullableFieldDeserializesToNull() throws Exception { TestUtils.assertFileNotContains(modelPath, "json['required_property'] === undefined ? undefined : json['required_property'] === null ? null :"); } + @Test(description = "Verify Omit uses the camelCase property name instead of the baseName for readOnly fields") + public void testIssue23380_OmitUsesCorrectPropertyName() throws Exception { + File output = generate( + Collections.emptyMap(), + "src/test/resources/3_0/typescript-fetch/issue_23380.yaml" + ); + + Path modelPath = Paths.get(output + "/models/Mission.ts"); + TestUtils.assertFileExists(modelPath); + // Ensure Omit uses camelCase names like 'singleCar' and 'taskName' instead of snake_case 'single_car' and 'TaskName' + TestUtils.assertFileContains(modelPath, "export function MissionToJSONTyped(value?: Omit | null, ignoreDiscriminator: boolean = false): any {"); + } + private static File generate( Map properties ) throws IOException { diff --git a/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/issue_23380.yaml b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/issue_23380.yaml new file mode 100644 index 000000000000..e15cb0ff847e --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/issue_23380.yaml @@ -0,0 +1,37 @@ +openapi: 3.0.0 +info: + title: Test API + version: 1.0.0 +paths: + /missions: + post: + operationId: createMission + requestBody: + content: + application/json: + schema: + type: object + properties: + mission: + $ref: '#/components/schemas/Mission' + required: + - mission + responses: + '200': + description: OK +components: + schemas: + Mission: + type: object + properties: + id: + type: string + readOnly: true + name: + type: string + TaskName: + type: string + readOnly: true + single_car: + type: object + readOnly: true diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts index b999bdccb1d0..98a66b7c6a7b 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts @@ -74,7 +74,7 @@ export function NameToJSON(json: any): Name { return NameToJSONTyped(json, false); } -export function NameToJSONTyped(value?: Omit | null, ignoreDiscriminator: boolean = false): any { +export function NameToJSONTyped(value?: Omit | null, ignoreDiscriminator: boolean = false): any { if (value == null) { return value; } diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts index b999bdccb1d0..98a66b7c6a7b 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts @@ -74,7 +74,7 @@ export function NameToJSON(json: any): Name { return NameToJSONTyped(json, false); } -export function NameToJSONTyped(value?: Omit | null, ignoreDiscriminator: boolean = false): any { +export function NameToJSONTyped(value?: Omit | null, ignoreDiscriminator: boolean = false): any { if (value == null) { return value; } diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts index b999bdccb1d0..98a66b7c6a7b 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts @@ -74,7 +74,7 @@ export function NameToJSON(json: any): Name { return NameToJSONTyped(json, false); } -export function NameToJSONTyped(value?: Omit | null, ignoreDiscriminator: boolean = false): any { +export function NameToJSONTyped(value?: Omit | null, ignoreDiscriminator: boolean = false): any { if (value == null) { return value; }