Files
openapi-generator/modules/swagger-codegen/src/main/resources/Javascript/model.mustache
delenius 079addb6db More fine-grained fix
Instead of just ignoring default values in the generated
model constructors, we modify the generator code in Java.
The template checks for null before outputting a default value.
2016-02-18 11:12:01 -08:00

91 lines
2.9 KiB
Plaintext

(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([undefined, '../ApiClient'{{#imports}}, './{{import}}'{{/imports}}], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(undefined, require('../ApiClient'){{#imports}}, require('./{{import}}'){{/imports}});
} else {
// Browser globals (root is window)
if (!root.{{moduleName}}) {
root.{{moduleName}} = {};
}
factory(root.{{moduleName}}, root.{{moduleName}}.ApiClient{{#imports}}, root.{{moduleName}}.{{import}}{{/imports}});
}
}(this, function(module, ApiClient{{#imports}}, {{import}}{{/imports}}) {
'use strict';
{{#models}}{{#model}}
{{#description}}/**
* {{description}}
**/{{/description}}
var {{classname}} = function {{classname}}({{#mandatory}}{{this}}{{^-last}}, {{/-last}}{{/mandatory}}) { {{#parent}}/* extends {{{parent}}}*/{{/parent}}
{{#vars}}{{#required}}
/**{{#description}}
* {{{description}}}{{/description}}
* datatype: {{{datatypeWithEnum}}}
* required {{#minimum}}
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
* maximum: {{maximum}}{{/maximum}}
**/
this['{{baseName}}'] = {{name}};{{/required}}{{^required}}{{#defaultValue}}
/**{{#description}}
* {{{description}}}{{/description}}
* datatype: {{{datatypeWithEnum}}}
* required {{#minimum}}
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
* maximum: {{maximum}}{{/maximum}}
**/
this['{{baseName}}'] = {{{defaultValue}}};{{/defaultValue}}{{/required}}{{/vars}}
};
{{classname}}.constructFromObject = function(data) {
if (!data) {
return null;
}
var _this = new {{classname}}();
{{#vars}}
if (data['{{baseName}}']) {
_this['{{baseName}}']{{{defaultValueWithParam}}}
}
{{/vars}}
return _this;
}
{{^omitModelMethods}}
{{#vars}}
/**{{#description}}
* get {{{description}}}{{/description}}{{#minimum}}
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
* maximum: {{maximum}}{{/maximum}}
* @return {{=<% %>=}}{<% datatypeWithEnum %>}<%={{ }}=%>
**/
{{classname}}.prototype.{{getter}} = function() {
return this['{{baseName}}'];
}
/**{{#description}}
* set {{{description}}}{{/description}}
* @param {{=<% %>=}}{<% datatypeWithEnum %>}<%={{ }}=%> {{name}}
**/
{{classname}}.prototype.{{setter}} = function({{name}}) {
this['{{baseName}}'] = {{name}};
}
{{/vars}}
{{/omitModelMethods}}
{{classname}}.prototype.toJson = function() {
return JSON.stringify(this);
}
{{#vars}}{{#isEnum}}{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
{{>enumClass}}{{/items}}*/{{/items.isEnum}}{{/vars}}
if (module) {
module.{{classname}} = {{classname}};
}
return {{classname}};
{{/model}}
{{/models}}
}));