Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript] Don't hardcode the date type if user has mapped it #5266

Merged
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 @@ -158,7 +158,7 @@ public AbstractTypeScriptClientCodegen() {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public TypeScriptAngularClientCodegen() {
apiPackage = "api";
modelPackage = "model";

typeMapping.put("DateTime", "Date");
asmundg marked this conversation as resolved.
Show resolved Hide resolved

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public TypeScriptAngularJsClientCodegen() {
apiPackage = "api";
modelPackage = "model";

typeMapping.put("DateTime", "Date");

removeOption(NPM_NAME);
removeOption(NPM_VERSION);
removeOption(SNAPSHOT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public TypeScriptAureliaClientCodegen() {
outputFolder = "generated-code/typescript-aurelia";
embeddedTemplateDir = templateDir = "typescript-aurelia";

typeMapping.put("DateTime", "Date");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public TypeScriptAxiosClientCodegen() {
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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public TypeScriptFetchClientCodegen() {
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()));
Expand Down Expand Up @@ -138,10 +141,6 @@ public String getTypeDeclaration(Schema p) {
return "Blob";
} else if (ModelUtils.isBinarySchema(p)) {
return "Blob";
} else if (ModelUtils.isDateSchema(p)) {
return "Date";
} else if (ModelUtils.isDateTimeSchema(p)) {
return "Date";
}
asmundg marked this conversation as resolved.
Show resolved Hide resolved
return super.getTypeDeclaration(p);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public TypeScriptInversifyClientCodegen() {
apiPackage = "api";
modelPackage = "model";

typeMapping.put("DateTime", "Date");

this.reservedWords.add("map");

this.cliOptions.add(new CliOption(NPM_REPOSITORY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public TypeScriptJqueryClientCodegen() {
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public TypeScriptNodeClientCodegen() {
// at the moment
importMapping.clear();

typeMapping.put("DateTime", "Date");

outputFolder = "generated-code/typescript-node";
embeddedTemplateDir = templateDir = "typescript-node";
modelTemplateFiles.put("model.mustache", ".ts");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public TypeScriptReduxQueryClientCodegen() {
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()));
Expand Down Expand Up @@ -107,10 +110,6 @@ public String getTypeDeclaration(Schema 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public TypeScriptRxjsClientCodegen() {

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()));
Expand Down Expand Up @@ -109,14 +110,8 @@ public boolean isDataTypeFile(final String dataType) {

@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);
}
Expand Down