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 defaultValue;
|
||||
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 Boolean hasVars, emptyVars, hasMoreModels, hasEnums;
|
||||
public ExternalDocs externalDocs;
|
||||
|
@ -1881,6 +1881,10 @@ public class DefaultCodegen {
|
||||
m.vars.add(cp);
|
||||
}
|
||||
}
|
||||
|
||||
m.mandatory = mandatory;
|
||||
m.mandatoryParams = StringUtils.join(mandatory, ", ");
|
||||
|
||||
} else {
|
||||
m.emptyVars = true;
|
||||
m.hasVars = false;
|
||||
|
@ -25,7 +25,13 @@ function {{classname}}() {
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
// 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}});
|
||||
|
||||
var queryParams = {};
|
||||
@ -44,10 +50,10 @@ function {{classname}}() {
|
||||
|
||||
path += createQueryString(queryParams);
|
||||
|
||||
if (console) {
|
||||
console.log('path: ' + path);
|
||||
console.log('queryParams: ' + queryParams);
|
||||
}
|
||||
//if (console) {
|
||||
//console.log('path: ' + path);
|
||||
//console.log('queryParams: ' + queryParams);
|
||||
//}
|
||||
|
||||
{{#isResponseBinary}}
|
||||
byte[] {{localVariablePrefix}}response = null;
|
||||
|
@ -4,16 +4,17 @@
|
||||
{{#description}}/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
function {{classname}}() { {{#parent}}/* extends {{{parent}}}*/{{/parent}}
|
||||
function {{classname}}({{mandatoryParams}}) { {{#parent}}/* extends {{{parent}}}*/{{/parent}}
|
||||
var self = this;
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}
|
||||
* datatype: {{{datatypeWithEnum}}}{{#minimum}}
|
||||
* datatype: {{{datatypeWithEnum}}}{{#required}}
|
||||
* required{{/required}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
self.{{name}} = {{{defaultValue}}};
|
||||
self.{{name}} = {{#required}}{{name}}{{/required}}{{^required}}{{{defaultValue}}}{{/required}};
|
||||
{{/vars}}
|
||||
|
||||
self.constructFromObject = function(data) {
|
||||
@ -42,6 +43,9 @@ function {{classname}}() { {{#parent}}/* extends {{{parent}}}*/{{/parent}}
|
||||
}
|
||||
{{/vars}}
|
||||
|
||||
self.toJson = function () {
|
||||
return JSON.stringify(self);
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user