mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-23 01:00:52 +00:00
Merge pull request #2143 from delenius/empty-objects
Do not create empty objects in model constructors
This commit is contained in:
commit
531d6e5249
@ -17,9 +17,17 @@ import io.swagger.models.Model;
|
|||||||
import io.swagger.models.Operation;
|
import io.swagger.models.Operation;
|
||||||
import io.swagger.models.Swagger;
|
import io.swagger.models.Swagger;
|
||||||
import io.swagger.models.properties.ArrayProperty;
|
import io.swagger.models.properties.ArrayProperty;
|
||||||
|
import io.swagger.models.properties.BooleanProperty;
|
||||||
|
import io.swagger.models.properties.DateProperty;
|
||||||
|
import io.swagger.models.properties.DateTimeProperty;
|
||||||
|
import io.swagger.models.properties.DoubleProperty;
|
||||||
|
import io.swagger.models.properties.FloatProperty;
|
||||||
|
import io.swagger.models.properties.IntegerProperty;
|
||||||
|
import io.swagger.models.properties.LongProperty;
|
||||||
import io.swagger.models.properties.MapProperty;
|
import io.swagger.models.properties.MapProperty;
|
||||||
import io.swagger.models.properties.Property;
|
import io.swagger.models.properties.Property;
|
||||||
import io.swagger.models.properties.RefProperty;
|
import io.swagger.models.properties.RefProperty;
|
||||||
|
import io.swagger.models.properties.StringProperty;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -326,15 +334,43 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValue(Property p) {
|
public String toDefaultValue(Property p) {
|
||||||
if (p instanceof ArrayProperty) {
|
if (p instanceof StringProperty) {
|
||||||
return "[]";
|
StringProperty dp = (StringProperty) p;
|
||||||
} else if (p instanceof MapProperty) {
|
if (dp.getDefault() != null) {
|
||||||
return "{}";
|
return dp.getDefault();
|
||||||
} else if (p instanceof RefProperty) {
|
}
|
||||||
return "new " + getTypeDeclaration(p) + "()";
|
} else if (p instanceof BooleanProperty) {
|
||||||
|
BooleanProperty dp = (BooleanProperty) p;
|
||||||
|
if (dp.getDefault() != null) {
|
||||||
|
return dp.getDefault().toString();
|
||||||
|
}
|
||||||
|
} else if (p instanceof DateProperty) {
|
||||||
|
// TODO
|
||||||
|
} else if (p instanceof DateTimeProperty) {
|
||||||
|
// TODO
|
||||||
|
} else if (p instanceof DoubleProperty) {
|
||||||
|
DoubleProperty dp = (DoubleProperty) p;
|
||||||
|
if (dp.getDefault() != null) {
|
||||||
|
return dp.getDefault().toString();
|
||||||
|
}
|
||||||
|
} else if (p instanceof FloatProperty) {
|
||||||
|
FloatProperty dp = (FloatProperty) p;
|
||||||
|
if (dp.getDefault() != null) {
|
||||||
|
return dp.getDefault().toString();
|
||||||
|
}
|
||||||
|
} else if (p instanceof IntegerProperty) {
|
||||||
|
IntegerProperty dp = (IntegerProperty) p;
|
||||||
|
if (dp.getDefault() != null) {
|
||||||
|
return dp.getDefault().toString();
|
||||||
|
}
|
||||||
|
} else if (p instanceof LongProperty) {
|
||||||
|
LongProperty dp = (LongProperty) p;
|
||||||
|
if (dp.getDefault() != null) {
|
||||||
|
return dp.getDefault().toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.toDefaultValue(p);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,16 +19,23 @@
|
|||||||
* {{description}}
|
* {{description}}
|
||||||
**/{{/description}}
|
**/{{/description}}
|
||||||
var {{classname}} = function {{classname}}({{#mandatory}}{{this}}{{^-last}}, {{/-last}}{{/mandatory}}) { {{#parent}}/* extends {{{parent}}}*/{{/parent}}
|
var {{classname}} = function {{classname}}({{#mandatory}}{{this}}{{^-last}}, {{/-last}}{{/mandatory}}) { {{#parent}}/* extends {{{parent}}}*/{{/parent}}
|
||||||
{{#vars}}
|
{{#vars}}{{#required}}
|
||||||
/**{{#description}}
|
/**{{#description}}
|
||||||
* {{{description}}}{{/description}}
|
* {{{description}}}{{/description}}
|
||||||
* datatype: {{{datatypeWithEnum}}}{{#required}}
|
* datatype: {{{datatypeWithEnum}}}
|
||||||
* required{{/required}}{{#minimum}}
|
* required {{#minimum}}
|
||||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||||
* maximum: {{maximum}}{{/maximum}}
|
* maximum: {{maximum}}{{/maximum}}
|
||||||
**/
|
**/
|
||||||
this['{{baseName}}'] = {{#required}}{{name}}{{/required}}{{^required}}{{{defaultValue}}}{{/required}};
|
this['{{baseName}}'] = {{name}};{{/required}}{{^required}}{{#defaultValue}}
|
||||||
{{/vars}}
|
/**{{#description}}
|
||||||
|
* {{{description}}}{{/description}}
|
||||||
|
* datatype: {{{datatypeWithEnum}}}
|
||||||
|
* required {{#minimum}}
|
||||||
|
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||||
|
* maximum: {{maximum}}{{/maximum}}
|
||||||
|
**/
|
||||||
|
this['{{baseName}}'] = {{{defaultValue}}};{{/defaultValue}}{{/required}}{{/vars}}
|
||||||
};
|
};
|
||||||
|
|
||||||
{{classname}}.constructFromObject = function(data) {
|
{{classname}}.constructFromObject = function(data) {
|
||||||
|
@ -102,7 +102,7 @@
|
|||||||
var pathParams = {
|
var pathParams = {
|
||||||
};
|
};
|
||||||
var queryParams = {
|
var queryParams = {
|
||||||
'status': this.buildCollectionParam(status, 'multi')
|
'status': this.apiClient.buildCollectionParam(status, 'multi')
|
||||||
};
|
};
|
||||||
var headerParams = {
|
var headerParams = {
|
||||||
};
|
};
|
||||||
@ -137,7 +137,7 @@
|
|||||||
var pathParams = {
|
var pathParams = {
|
||||||
};
|
};
|
||||||
var queryParams = {
|
var queryParams = {
|
||||||
'tags': this.buildCollectionParam(tags, 'multi')
|
'tags': this.apiClient.buildCollectionParam(tags, 'multi')
|
||||||
};
|
};
|
||||||
var headerParams = {
|
var headerParams = {
|
||||||
};
|
};
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
(function(factory) {
|
(function(factory) {
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
// AMD. Register as an anonymous module.
|
// AMD. Register as an anonymous module.
|
||||||
define(['./ApiClient', './model/User', './model/Category', './model/Pet', './model/Tag', './model/Order', './api/UserApi', './api/StoreApi', './api/PetApi'], factory);
|
define(['./ApiClient', './model/Order', './model/User', './model/Category', './model/Tag', './model/Pet', './api/UserApi', './api/StoreApi', './api/PetApi'], factory);
|
||||||
} else if (typeof module === 'object' && module.exports) {
|
} else if (typeof module === 'object' && module.exports) {
|
||||||
// CommonJS-like environments that support module.exports, like Node.
|
// CommonJS-like environments that support module.exports, like Node.
|
||||||
module.exports = factory(require('./ApiClient'), require('./model/User'), require('./model/Category'), require('./model/Pet'), require('./model/Tag'), require('./model/Order'), require('./api/UserApi'), require('./api/StoreApi'), require('./api/PetApi'));
|
module.exports = factory(require('./ApiClient'), require('./model/Order'), require('./model/User'), require('./model/Category'), require('./model/Tag'), require('./model/Pet'), require('./api/UserApi'), require('./api/StoreApi'), require('./api/PetApi'));
|
||||||
}
|
}
|
||||||
}(function(ApiClient, User, Category, Pet, Tag, Order, UserApi, StoreApi, PetApi) {
|
}(function(ApiClient, Order, User, Category, Tag, Pet, UserApi, StoreApi, PetApi) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ApiClient: ApiClient,
|
ApiClient: ApiClient,
|
||||||
|
Order: Order,
|
||||||
User: User,
|
User: User,
|
||||||
Category: Category,
|
Category: Category,
|
||||||
Pet: Pet,
|
|
||||||
Tag: Tag,
|
Tag: Tag,
|
||||||
Order: Order,
|
Pet: Pet,
|
||||||
UserApi: UserApi,
|
UserApi: UserApi,
|
||||||
StoreApi: StoreApi,
|
StoreApi: StoreApi,
|
||||||
PetApi: PetApi
|
PetApi: PetApi
|
||||||
|
@ -18,16 +18,6 @@
|
|||||||
|
|
||||||
var Category = function Category() {
|
var Category = function Category() {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['name'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Category.constructFromObject = function(data) {
|
Category.constructFromObject = function(data) {
|
||||||
|
@ -18,37 +18,6 @@
|
|||||||
|
|
||||||
var Order = function Order() {
|
var Order = function Order() {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['petId'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['quantity'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Date
|
|
||||||
**/
|
|
||||||
this['shipDate'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Order Status
|
|
||||||
* datatype: StatusEnum
|
|
||||||
**/
|
|
||||||
this['status'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Boolean
|
|
||||||
**/
|
|
||||||
this['complete'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Order.constructFromObject = function(data) {
|
Order.constructFromObject = function(data) {
|
||||||
|
@ -18,39 +18,16 @@
|
|||||||
|
|
||||||
var Pet = function Pet(photoUrls, name) {
|
var Pet = function Pet(photoUrls, name) {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Category
|
|
||||||
**/
|
|
||||||
this['category'] = new Category();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* datatype: String
|
* datatype: String
|
||||||
* required
|
* required
|
||||||
**/
|
**/
|
||||||
this['name'] = name;
|
this['name'] = name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* datatype: [String]
|
* datatype: [String]
|
||||||
* required
|
* required
|
||||||
**/
|
**/
|
||||||
this['photoUrls'] = photoUrls;
|
this['photoUrls'] = photoUrls;
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: [Tag]
|
|
||||||
**/
|
|
||||||
this['tags'] = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* pet status in the store
|
|
||||||
* datatype: StatusEnum
|
|
||||||
**/
|
|
||||||
this['status'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Pet.constructFromObject = function(data) {
|
Pet.constructFromObject = function(data) {
|
||||||
|
@ -18,16 +18,6 @@
|
|||||||
|
|
||||||
var Tag = function Tag() {
|
var Tag = function Tag() {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['name'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Tag.constructFromObject = function(data) {
|
Tag.constructFromObject = function(data) {
|
||||||
|
@ -18,47 +18,6 @@
|
|||||||
|
|
||||||
var User = function User() {
|
var User = function User() {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['username'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['firstName'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['lastName'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['email'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['password'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['phone'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User Status
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['userStatus'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
User.constructFromObject = function(data) {
|
User.constructFromObject = function(data) {
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
(function(factory) {
|
(function(factory) {
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
// AMD. Register as an anonymous module.
|
// AMD. Register as an anonymous module.
|
||||||
define(['./ApiClient', './model/User', './model/Category', './model/Pet', './model/Tag', './model/Order', './api/UserApi', './api/StoreApi', './api/PetApi'], factory);
|
define(['./ApiClient', './model/Order', './model/User', './model/Category', './model/Tag', './model/Pet', './api/UserApi', './api/StoreApi', './api/PetApi'], factory);
|
||||||
} else if (typeof module === 'object' && module.exports) {
|
} else if (typeof module === 'object' && module.exports) {
|
||||||
// CommonJS-like environments that support module.exports, like Node.
|
// CommonJS-like environments that support module.exports, like Node.
|
||||||
module.exports = factory(require('./ApiClient'), require('./model/User'), require('./model/Category'), require('./model/Pet'), require('./model/Tag'), require('./model/Order'), require('./api/UserApi'), require('./api/StoreApi'), require('./api/PetApi'));
|
module.exports = factory(require('./ApiClient'), require('./model/Order'), require('./model/User'), require('./model/Category'), require('./model/Tag'), require('./model/Pet'), require('./api/UserApi'), require('./api/StoreApi'), require('./api/PetApi'));
|
||||||
}
|
}
|
||||||
}(function(ApiClient, User, Category, Pet, Tag, Order, UserApi, StoreApi, PetApi) {
|
}(function(ApiClient, Order, User, Category, Tag, Pet, UserApi, StoreApi, PetApi) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ApiClient: ApiClient,
|
ApiClient: ApiClient,
|
||||||
|
Order: Order,
|
||||||
User: User,
|
User: User,
|
||||||
Category: Category,
|
Category: Category,
|
||||||
Pet: Pet,
|
|
||||||
Tag: Tag,
|
Tag: Tag,
|
||||||
Order: Order,
|
Pet: Pet,
|
||||||
UserApi: UserApi,
|
UserApi: UserApi,
|
||||||
StoreApi: StoreApi,
|
StoreApi: StoreApi,
|
||||||
PetApi: PetApi
|
PetApi: PetApi
|
||||||
|
@ -18,16 +18,6 @@
|
|||||||
|
|
||||||
var Category = function Category() {
|
var Category = function Category() {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['name'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Category.constructFromObject = function(data) {
|
Category.constructFromObject = function(data) {
|
||||||
|
@ -18,37 +18,6 @@
|
|||||||
|
|
||||||
var Order = function Order() {
|
var Order = function Order() {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['petId'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['quantity'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Date
|
|
||||||
**/
|
|
||||||
this['shipDate'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Order Status
|
|
||||||
* datatype: StatusEnum
|
|
||||||
**/
|
|
||||||
this['status'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Boolean
|
|
||||||
**/
|
|
||||||
this['complete'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Order.constructFromObject = function(data) {
|
Order.constructFromObject = function(data) {
|
||||||
|
@ -18,39 +18,16 @@
|
|||||||
|
|
||||||
var Pet = function Pet(photoUrls, name) {
|
var Pet = function Pet(photoUrls, name) {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Category
|
|
||||||
**/
|
|
||||||
this['category'] = new Category();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* datatype: String
|
* datatype: String
|
||||||
* required
|
* required
|
||||||
**/
|
**/
|
||||||
this['name'] = name;
|
this['name'] = name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* datatype: [String]
|
* datatype: [String]
|
||||||
* required
|
* required
|
||||||
**/
|
**/
|
||||||
this['photoUrls'] = photoUrls;
|
this['photoUrls'] = photoUrls;
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: [Tag]
|
|
||||||
**/
|
|
||||||
this['tags'] = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* pet status in the store
|
|
||||||
* datatype: StatusEnum
|
|
||||||
**/
|
|
||||||
this['status'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Pet.constructFromObject = function(data) {
|
Pet.constructFromObject = function(data) {
|
||||||
|
@ -18,16 +18,6 @@
|
|||||||
|
|
||||||
var Tag = function Tag() {
|
var Tag = function Tag() {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['name'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Tag.constructFromObject = function(data) {
|
Tag.constructFromObject = function(data) {
|
||||||
|
@ -18,47 +18,6 @@
|
|||||||
|
|
||||||
var User = function User() {
|
var User = function User() {
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['id'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['username'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['firstName'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['lastName'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['email'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['password'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* datatype: String
|
|
||||||
**/
|
|
||||||
this['phone'] = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User Status
|
|
||||||
* datatype: Integer
|
|
||||||
**/
|
|
||||||
this['userStatus'] = null;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
User.constructFromObject = function(data) {
|
User.constructFromObject = function(data) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user