diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java index bc7473f9f861..80c2da63d39b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java @@ -103,6 +103,9 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege private static final String X_KEEP_AS_JS_OBJECT = "x-keepAsJSObject"; private static final String X_TYPESCRIPT_FETCH_API_EXAMPLE = "x-typescriptFetchApiExample"; private static final String BLOB_API_EXAMPLE = "new Blob(['example file content'], { type: 'application/octet-stream' })"; + private static final String DATE_TYPE = "date"; + private static final String DATE_TIME_TYPE = "DateTime"; + private static final String TS_DATE_TYPE = "Date"; protected boolean sagasAndRecords = false; @Getter @Setter @@ -317,8 +320,8 @@ public void processOpts() { if (!withoutRuntimeChecks) { this.modelTemplateFiles.put("models.mustache", ".ts"); - typeMapping.put("date", "Date"); - typeMapping.put("DateTime", "Date"); + typeMapping.put(DATE_TYPE, TS_DATE_TYPE); + typeMapping.put(DATE_TIME_TYPE, TS_DATE_TYPE); } if (additionalProperties.containsKey(SAGAS_AND_RECORDS)) { @@ -1484,11 +1487,11 @@ public String getItemsDataType() { } public boolean isDateType() { - return isDate && "Date".equals(dataType); + return isDate && TypeScriptFetchClientCodegen.isDateType(dataType); } public boolean isDateTimeType() { - return isDateTime && "Date".equals(dataType); + return isDateTime && TypeScriptFetchClientCodegen.isDateTimeType(dataType); } public ExtendedCodegenParameter(CodegenParameter cp) { @@ -1635,11 +1638,11 @@ public String getItemsDataType() { } public boolean isDateType() { - return isDate && "Date".equals(dataType); + return isDate && TypeScriptFetchClientCodegen.isDateType(dataType); } public boolean isDateTimeType() { - return isDateTime && "Date".equals(dataType); + return isDateTime && TypeScriptFetchClientCodegen.isDateTimeType(dataType); } public ExtendedCodegenProperty(CodegenProperty cp) { @@ -1923,12 +1926,13 @@ public class ExtendedCodegenModel extends CodegenModel { public boolean hasSelfReferencingDiscriminatorMapping(){ return selfReferencingDiscriminatorMapping != null; } + public boolean isDateType() { - return isDate && "Date".equals(dataType); + return isDate && TypeScriptFetchClientCodegen.isDateType(dataType); } public boolean isDateTimeType() { - return isDateTime && "Date".equals(dataType); + return isDateTime && TypeScriptFetchClientCodegen.isDateTimeType(dataType); } public ExtendedCodegenModel(CodegenModel cm) { @@ -2069,4 +2073,12 @@ public String toString() { protected String getLicenseNameDefaultValue() { return null; } + + private static boolean isDateType(String dataType) { + return TS_DATE_TYPE.equals(dataType); + } + + private static boolean isDateTimeType(String dataType) { + return TS_DATE_TYPE.equals(dataType); + } }