Skip to content

Commit 1c9efe5

Browse files
refactor(typescript-fetch): centralize date type handling in TypeScriptFetchClientCodegen
1 parent 51433f0 commit 1c9efe5

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

‎modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
109109
private static final String X_TYPESCRIPT_FETCH_API_EXAMPLE = "x-typescriptFetchApiExample";
110110
private static final String X_HAS_DATE_VARS = "x-hasDateVars";
111111
private static final String BLOB_API_EXAMPLE = "new Blob(['example file content'], { type: 'application/octet-stream' })";
112+
private static final String DATE_TYPE = "date";
113+
private static final String DATE_TIME_TYPE = "DateTime";
114+
private static final String TS_DATE_TYPE = "Date";
112115

113116
protected boolean sagasAndRecords = false;
114117
@Getter @Setter
@@ -355,11 +358,11 @@ public void processOpts() {
355358
}
356359

357360
if (DATE_LIBRARY_DATE.equals(this.dateLibrary)) {
358-
typeMapping.put("date", "Date");
359-
typeMapping.put("DateTime", "Date");
361+
typeMapping.put(DATE_TYPE, TS_DATE_TYPE);
362+
typeMapping.put(DATE_TIME_TYPE, TS_DATE_TYPE);
360363
} else {
361-
typeMapping.put("date", "string");
362-
typeMapping.put("DateTime", "string");
364+
typeMapping.put(DATE_TYPE, "string");
365+
typeMapping.put(DATE_TIME_TYPE, "string");
363366
}
364367
additionalProperties.put(DATE_LIBRARY, this.dateLibrary);
365368
// Mustache cannot compare strings, so expose the selected library as a flag.
@@ -1534,11 +1537,11 @@ public String getItemsDataType() {
15341537
}
15351538

15361539
public boolean isDateType() {
1537-
return isDate && "Date".equals(dataType);
1540+
return isDate && TypeScriptFetchClientCodegen.isDateType(dataType);
15381541
}
15391542

15401543
public boolean isDateTimeType() {
1541-
return isDateTime && "Date".equals(dataType);
1544+
return isDateTime && TypeScriptFetchClientCodegen.isDateTimeType(dataType);
15421545
}
15431546

15441547
public ExtendedCodegenParameter(CodegenParameter cp) {
@@ -1685,11 +1688,11 @@ public String getItemsDataType() {
16851688
}
16861689

16871690
public boolean isDateType() {
1688-
return isDate && "Date".equals(dataType);
1691+
return isDate && TypeScriptFetchClientCodegen.isDateType(dataType);
16891692
}
16901693

16911694
public boolean isDateTimeType() {
1692-
return isDateTime && "Date".equals(dataType);
1695+
return isDateTime && TypeScriptFetchClientCodegen.isDateTimeType(dataType);
16931696
}
16941697

16951698
public ExtendedCodegenProperty(CodegenProperty cp) {
@@ -1973,12 +1976,13 @@ public class ExtendedCodegenModel extends CodegenModel {
19731976
public boolean hasSelfReferencingDiscriminatorMapping(){
19741977
return selfReferencingDiscriminatorMapping != null;
19751978
}
1979+
19761980
public boolean isDateType() {
1977-
return isDate && "Date".equals(dataType);
1981+
return isDate && TypeScriptFetchClientCodegen.isDateType(dataType);
19781982
}
19791983

19801984
public boolean isDateTimeType() {
1981-
return isDateTime && "Date".equals(dataType);
1985+
return isDateTime && TypeScriptFetchClientCodegen.isDateTimeType(dataType);
19821986
}
19831987

19841988
public ExtendedCodegenModel(CodegenModel cm) {
@@ -2119,4 +2123,12 @@ public String toString() {
21192123
protected String getLicenseNameDefaultValue() {
21202124
return null;
21212125
}
2126+
2127+
private static boolean isDateType(String dataType) {
2128+
return TS_DATE_TYPE.equals(dataType);
2129+
}
2130+
2131+
private static boolean isDateTimeType(String dataType) {
2132+
return TS_DATE_TYPE.equals(dataType);
2133+
}
21222134
}

0 commit comments

Comments
 (0)