Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mission, 'id'|'taskName'|'singleCar'> | null, ignoreDiscriminator: boolean = false): any {");
}

private static File generate(
Map<String, Object> properties
) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function NameToJSON(json: any): Name {
return NameToJSONTyped(json, false);
}

export function NameToJSONTyped(value?: Omit<Name, 'snake_case'|'123Number'> | null, ignoreDiscriminator: boolean = false): any {
export function NameToJSONTyped(value?: Omit<Name, 'snakeCase'|'_123number'> | null, ignoreDiscriminator: boolean = false): any {
if (value == null) {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function NameToJSON(json: any): Name {
return NameToJSONTyped(json, false);
}

export function NameToJSONTyped(value?: Omit<Name, 'snake_case'|'123Number'> | null, ignoreDiscriminator: boolean = false): any {
export function NameToJSONTyped(value?: Omit<Name, 'snakeCase'|'_123number'> | null, ignoreDiscriminator: boolean = false): any {
if (value == null) {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function NameToJSON(json: any): Name {
return NameToJSONTyped(json, false);
}

export function NameToJSONTyped(value?: Omit<Name, 'snake_case'|'123Number'> | null, ignoreDiscriminator: boolean = false): any {
export function NameToJSONTyped(value?: Omit<Name, 'snakeCase'|'_123number'> | null, ignoreDiscriminator: boolean = false): any {
if (value == null) {
return value;
}
Expand Down
Loading