forked from loafle/openapi-generator-original
[typescript] Don't hardcode the date type if user has mapped it (#5266)
* [typescript] Don't hardcode the date type if user has mapped it If the user has set --type-mappings Date=foo, respect this setting instead of hardcoding the date type. * Use default type mappings for date/date-time * Use typeMapping mechanism correctly * Add default mapping for angular and node to preserve behavior * One more change to keep current behavior * Add default type mappings to the other TS generators
This commit is contained in:
committed by
GitHub
parent
b04c53674d
commit
e157b05206
@@ -158,7 +158,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
typeMapping.put("Map", "any");
|
||||
typeMapping.put("map", "any");
|
||||
typeMapping.put("date", "string");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
typeMapping.put("DateTime", "string");
|
||||
typeMapping.put("binary", "any");
|
||||
typeMapping.put("File", "any");
|
||||
typeMapping.put("file", "any");
|
||||
|
||||
@@ -86,6 +86,8 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
apiPackage = "api";
|
||||
modelPackage = "model";
|
||||
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY,
|
||||
"Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(CliOption.newBoolean(WITH_INTERFACES,
|
||||
|
||||
@@ -34,6 +34,8 @@ public class TypeScriptAngularJsClientCodegen extends AbstractTypeScriptClientCo
|
||||
apiPackage = "api";
|
||||
modelPackage = "model";
|
||||
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
removeOption(NPM_NAME);
|
||||
removeOption(NPM_VERSION);
|
||||
removeOption(SNAPSHOT);
|
||||
|
||||
@@ -37,6 +37,7 @@ public class TypeScriptAureliaClientCodegen extends AbstractTypeScriptClientCode
|
||||
outputFolder = "generated-code/typescript-aurelia";
|
||||
embeddedTemplateDir = templateDir = "typescript-aurelia";
|
||||
|
||||
typeMapping.put("DateTime", "Date");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,6 +55,8 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
|
||||
outputFolder = "generated-code/typescript-axios";
|
||||
embeddedTemplateDir = templateDir = "typescript-axios";
|
||||
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url of your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
this.cliOptions.add(new CliOption(SEPARATE_MODELS_AND_API, "Put the model and api in separate folders and in separate classes", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
|
||||
@@ -63,6 +63,9 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
this.modelTemplateFiles.put("models.mustache", ".ts");
|
||||
this.addExtraReservedWords();
|
||||
|
||||
typeMapping.put("date", "Date");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.TRUE.toString()));
|
||||
@@ -138,10 +141,6 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
return "Blob";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return "Blob";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "Date";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "Date";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo
|
||||
apiPackage = "api";
|
||||
modelPackage = "model";
|
||||
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
this.reservedWords.add("map");
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY,
|
||||
|
||||
@@ -53,6 +53,8 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg
|
||||
outputFolder = "generated-code/typescript-jquery";
|
||||
embeddedTemplateDir = templateDir = "typescript-jquery";
|
||||
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(JQUERY_ALREADY_IMPORTED,
|
||||
"When using this in legacy app using mix of typescript and javascript, this will only declare jquery and not import it",
|
||||
|
||||
@@ -55,6 +55,8 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
// at the moment
|
||||
importMapping.clear();
|
||||
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
outputFolder = "generated-code/typescript-node";
|
||||
embeddedTemplateDir = templateDir = "typescript-node";
|
||||
modelTemplateFiles.put("model.mustache", ".ts");
|
||||
|
||||
@@ -58,6 +58,9 @@ public class TypeScriptReduxQueryClientCodegen extends AbstractTypeScriptClientC
|
||||
this.modelTemplateFiles.put("models.mustache", ".ts");
|
||||
this.addExtraReservedWords();
|
||||
|
||||
typeMapping.put("date", "Date");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.TRUE.toString()));
|
||||
@@ -107,10 +110,6 @@ public class TypeScriptReduxQueryClientCodegen extends AbstractTypeScriptClientC
|
||||
return "Blob";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return "Blob";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "Date";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "Date";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
|
||||
languageSpecificPrimitives.add("Blob");
|
||||
typeMapping.put("file", "Blob");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
@@ -109,14 +110,8 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Schema p) {
|
||||
if (ModelUtils.isFileSchema(p)) {
|
||||
if (ModelUtils.isBinarySchema(p)) {
|
||||
return "Blob";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return "Blob";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "Date";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "Date";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user