forked from loafle/openapi-generator-original
Add all required parameters as default constructor parameters #1294
This commit is contained in:
parent
1a8a03ee52
commit
8fd6b604d3
@ -13,6 +13,13 @@ public class CodegenModel {
|
|||||||
public String unescapedDescription;
|
public String unescapedDescription;
|
||||||
public String defaultValue;
|
public String defaultValue;
|
||||||
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>();
|
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>();
|
||||||
|
|
||||||
|
// list of all required parameters
|
||||||
|
public Set<String> mandatory = new HashSet<String>();
|
||||||
|
|
||||||
|
// TODO: temporary solution to get a delimited list of default constructor parameters, should be replaced if there is a better way of injecting the mandatory parameters into the mustache templates
|
||||||
|
public String mandatoryParams;
|
||||||
|
|
||||||
public Set<String> imports = new HashSet<String>();
|
public Set<String> imports = new HashSet<String>();
|
||||||
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums;
|
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums;
|
||||||
public ExternalDocs externalDocs;
|
public ExternalDocs externalDocs;
|
||||||
|
@ -1881,6 +1881,10 @@ public class DefaultCodegen {
|
|||||||
m.vars.add(cp);
|
m.vars.add(cp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.mandatory = mandatory;
|
||||||
|
m.mandatoryParams = StringUtils.join(mandatory, ", ");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
m.emptyVars = true;
|
m.emptyVars = true;
|
||||||
m.hasVars = false;
|
m.hasVars = false;
|
||||||
|
@ -25,7 +25,13 @@ function {{classname}}() {
|
|||||||
}
|
}
|
||||||
{{/required}}{{/allParams}}
|
{{/required}}{{/allParams}}
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
var {{localVariablePrefix}}path = '{{basePath}}' + replaceAll(replaceAll("{{{path}}}", "\\{format\\}","json"){{#pathParams}}
|
var basePath = '{{basePath}}';
|
||||||
|
// if basePath ends with a /, remove it as path starts with a leading /
|
||||||
|
if (basePath.substring(basePath.length-1, basePath.length)=='/') {
|
||||||
|
basePath = basePath.substring(0, basePath.length-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var {{localVariablePrefix}}path = basePath + replaceAll(replaceAll("{{{path}}}", "\\{format\\}","json"){{#pathParams}}
|
||||||
, "\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString()){{/pathParams}});
|
, "\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString()){{/pathParams}});
|
||||||
|
|
||||||
var queryParams = {};
|
var queryParams = {};
|
||||||
@ -44,10 +50,10 @@ function {{classname}}() {
|
|||||||
|
|
||||||
path += createQueryString(queryParams);
|
path += createQueryString(queryParams);
|
||||||
|
|
||||||
if (console) {
|
//if (console) {
|
||||||
console.log('path: ' + path);
|
//console.log('path: ' + path);
|
||||||
console.log('queryParams: ' + queryParams);
|
//console.log('queryParams: ' + queryParams);
|
||||||
}
|
//}
|
||||||
|
|
||||||
{{#isResponseBinary}}
|
{{#isResponseBinary}}
|
||||||
byte[] {{localVariablePrefix}}response = null;
|
byte[] {{localVariablePrefix}}response = null;
|
||||||
|
@ -4,16 +4,17 @@
|
|||||||
{{#description}}/**
|
{{#description}}/**
|
||||||
* {{description}}
|
* {{description}}
|
||||||
**/{{/description}}
|
**/{{/description}}
|
||||||
function {{classname}}() { {{#parent}}/* extends {{{parent}}}*/{{/parent}}
|
function {{classname}}({{mandatoryParams}}) { {{#parent}}/* extends {{{parent}}}*/{{/parent}}
|
||||||
var self = this;
|
var self = this;
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
/**{{#description}}
|
/**{{#description}}
|
||||||
* {{{description}}}{{/description}}
|
* {{{description}}}{{/description}}
|
||||||
* datatype: {{{datatypeWithEnum}}}{{#minimum}}
|
* datatype: {{{datatypeWithEnum}}}{{#required}}
|
||||||
|
* required{{/required}}{{#minimum}}
|
||||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||||
* maximum: {{maximum}}{{/maximum}}
|
* maximum: {{maximum}}{{/maximum}}
|
||||||
**/
|
**/
|
||||||
self.{{name}} = {{{defaultValue}}};
|
self.{{name}} = {{#required}}{{name}}{{/required}}{{^required}}{{{defaultValue}}}{{/required}};
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
|
||||||
self.constructFromObject = function(data) {
|
self.constructFromObject = function(data) {
|
||||||
@ -42,6 +43,9 @@ function {{classname}}() { {{#parent}}/* extends {{{parent}}}*/{{/parent}}
|
|||||||
}
|
}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
|
||||||
|
self.toJson = function () {
|
||||||
|
return JSON.stringify(self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{{/model}}
|
{{/model}}
|
||||||
{{/models}}
|
{{/models}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user