Skip to content

Commit bc4ca5d

Browse files
refactor(typescript-fetch): centralize date type handling in TypeScriptFetchClientCodegen
1 parent 9a0e7ae commit bc4ca5d

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
103103
private static final String X_KEEP_AS_JS_OBJECT = "x-keepAsJSObject";
104104
private static final String X_TYPESCRIPT_FETCH_API_EXAMPLE = "x-typescriptFetchApiExample";
105105
private static final String BLOB_API_EXAMPLE = "new Blob(['example file content'], { type: 'application/octet-stream' })";
106+
private static final String DATE_TYPE = "date";
107+
private static final String DATE_TIME_TYPE = "DateTime";
108+
private static final String TS_DATE_TYPE = "Date";
106109

107110
protected boolean sagasAndRecords = false;
108111
@Getter @Setter
@@ -317,8 +320,8 @@ public void processOpts() {
317320

318321
if (!withoutRuntimeChecks) {
319322
this.modelTemplateFiles.put("models.mustache", ".ts");
320-
typeMapping.put("date", "Date");
321-
typeMapping.put("DateTime", "Date");
323+
typeMapping.put(DATE_TYPE, TS_DATE_TYPE);
324+
typeMapping.put(DATE_TIME_TYPE, TS_DATE_TYPE);
322325
}
323326

324327
if (additionalProperties.containsKey(SAGAS_AND_RECORDS)) {
@@ -1484,11 +1487,11 @@ public String getItemsDataType() {
14841487
}
14851488

14861489
public boolean isDateType() {
1487-
return isDate && "Date".equals(dataType);
1490+
return isDate && TypeScriptFetchClientCodegen.isDateType(dataType);
14881491
}
14891492

14901493
public boolean isDateTimeType() {
1491-
return isDateTime && "Date".equals(dataType);
1494+
return isDateTime && TypeScriptFetchClientCodegen.isDateTimeType(dataType);
14921495
}
14931496

14941497
public ExtendedCodegenParameter(CodegenParameter cp) {
@@ -1635,11 +1638,11 @@ public String getItemsDataType() {
16351638
}
16361639

16371640
public boolean isDateType() {
1638-
return isDate && "Date".equals(dataType);
1641+
return isDate && TypeScriptFetchClientCodegen.isDateType(dataType);
16391642
}
16401643

16411644
public boolean isDateTimeType() {
1642-
return isDateTime && "Date".equals(dataType);
1645+
return isDateTime && TypeScriptFetchClientCodegen.isDateTimeType(dataType);
16431646
}
16441647

16451648
public ExtendedCodegenProperty(CodegenProperty cp) {
@@ -1923,12 +1926,13 @@ public class ExtendedCodegenModel extends CodegenModel {
19231926
public boolean hasSelfReferencingDiscriminatorMapping(){
19241927
return selfReferencingDiscriminatorMapping != null;
19251928
}
1929+
19261930
public boolean isDateType() {
1927-
return isDate && "Date".equals(dataType);
1931+
return isDate && TypeScriptFetchClientCodegen.isDateType(dataType);
19281932
}
19291933

19301934
public boolean isDateTimeType() {
1931-
return isDateTime && "Date".equals(dataType);
1935+
return isDateTime && TypeScriptFetchClientCodegen.isDateTimeType(dataType);
19321936
}
19331937

19341938
public ExtendedCodegenModel(CodegenModel cm) {
@@ -2069,4 +2073,12 @@ public String toString() {
20692073
protected String getLicenseNameDefaultValue() {
20702074
return null;
20712075
}
2076+
2077+
private static boolean isDateType(String dataType) {
2078+
return TS_DATE_TYPE.equals(dataType);
2079+
}
2080+
2081+
private static boolean isDateTimeType(String dataType) {
2082+
return TS_DATE_TYPE.equals(dataType);
2083+
}
20722084
}

0 commit comments

Comments
 (0)