[JaxRS-Java] issue with implFolder on windows, and required fields generation for containers (#88)

* Fix implFolder issue with jaxrs-cxf-cdi generator

This fix is for the issue:
https://github.com/swagger-api/swagger-codegen/issues/8113

When using jaxrs-cxf-cdi and other JaxRS generators, the implFolder
config is not honored by hte generator on windows.

* jaxrs-cxf-cdi: containers with no default init

Change similar to
https://github.com/swagger-api/swagger-codegen/pull/5363/files for
jax-rs-cdi generator.
When a property that is a contained is not declared as required, it is
initialized to `null`, and not to the empty container.
This makes apio mich more easy to use, since one can differentiate when
an input list in json has been set to the empty array or simply not set.
This commit is contained in:
Antoine Reilles 2018-05-17 19:28:05 +02:00 committed by Jérémie Bresson
parent 4889103621
commit d890d733f8
8 changed files with 102 additions and 4 deletions

View File

@ -33,6 +33,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.net.URL; import java.net.URL;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -240,11 +241,11 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
String result = super.apiFilename(templateName, tag); String result = super.apiFilename(templateName, tag);
if (templateName.endsWith("Impl.mustache")) { if (templateName.endsWith("Impl.mustache")) {
int ix = result.lastIndexOf('/'); int ix = result.lastIndexOf(File.separator);
result = result.substring(0, ix) + "/impl" + result.substring(ix, result.length() - 5) + "ServiceImpl.java"; result = result.substring(0, ix) + "/impl" + result.substring(ix, result.length() - 5) + "ServiceImpl.java";
result = result.replace(apiFileFolder(), implFileFolder(implFolder)); result = result.replace(apiFileFolder(), implFileFolder(implFolder));
} else if (templateName.endsWith("Factory.mustache")) { } else if (templateName.endsWith("Factory.mustache")) {
int ix = result.lastIndexOf('/'); int ix = result.lastIndexOf(File.separator);
result = result.substring(0, ix) + "/factories" + result.substring(ix, result.length() - 5) + "ServiceFactory.java"; result = result.substring(0, ix) + "/factories" + result.substring(ix, result.length() - 5) + "ServiceFactory.java";
result = result.replace(apiFileFolder(), implFileFolder(implFolder)); result = result.replace(apiFileFolder(), implFileFolder(implFolder));
} else if (templateName.endsWith("Service.mustache")) { } else if (templateName.endsWith("Service.mustache")) {

View File

@ -11,7 +11,12 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}} {{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
{{>enumClass}}{{/items}}{{/items.isEnum}} {{>enumClass}}{{/items}}{{/items.isEnum}}
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} {{#isContainer}}
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
{{/isContainer}}
{{^isContainer}}
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
{{/isContainer}}{{/vars}}
{{#vars}} {{#vars}}
/** /**
@ -39,6 +44,31 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}}; this.{{name}} = {{name}};
} }
{{#isListContainer}}
public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
{{^required}}
if (this.{{name}} == null) {
this.{{name}} = {{{defaultValue}}};
}
{{/required}}
this.{{name}}.add({{name}}Item);
return this;
}
{{/isListContainer}}
{{#isMapContainer}}
public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
{{^required}}
if (this.{{name}} == null) {
this.{{name}} = {{{defaultValue}}};
}
{{/required}}
this.{{name}}.put(key, {{name}}Item);
return this;
}
{{/isMapContainer}}
{{/vars}} {{/vars}}

View File

@ -19,8 +19,10 @@ import javax.xml.bind.annotation.*;
public class Category { public class Category {
private Long id = null; private Long id = null;
private String name = null; private String name = null;
/** /**
**/ **/
public Category id(Long id) { public Category id(Long id) {
@ -38,6 +40,7 @@ public class Category {
this.id = id; this.id = id;
} }
/** /**
**/ **/
public Category name(String name) { public Category name(String name) {
@ -56,6 +59,7 @@ public class Category {
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {

View File

@ -19,9 +19,12 @@ import javax.xml.bind.annotation.*;
public class ModelApiResponse { public class ModelApiResponse {
private Integer code = null; private Integer code = null;
private String type = null; private String type = null;
private String message = null; private String message = null;
/** /**
**/ **/
public ModelApiResponse code(Integer code) { public ModelApiResponse code(Integer code) {
@ -39,6 +42,7 @@ public class ModelApiResponse {
this.code = code; this.code = code;
} }
/** /**
**/ **/
public ModelApiResponse type(String type) { public ModelApiResponse type(String type) {
@ -56,6 +60,7 @@ public class ModelApiResponse {
this.type = type; this.type = type;
} }
/** /**
**/ **/
public ModelApiResponse message(String message) { public ModelApiResponse message(String message) {
@ -74,6 +79,7 @@ public class ModelApiResponse {
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {

View File

@ -19,10 +19,14 @@ import javax.xml.bind.annotation.*;
public class Order { public class Order {
private Long id = null; private Long id = null;
private Long petId = null; private Long petId = null;
private Integer quantity = null; private Integer quantity = null;
private java.util.Date shipDate = null; private java.util.Date shipDate = null;
@XmlType(name="StatusEnum") @XmlType(name="StatusEnum")
@XmlEnum(String.class) @XmlEnum(String.class)
public enum StatusEnum { public enum StatusEnum {
@ -56,8 +60,10 @@ public enum StatusEnum {
} }
private StatusEnum status = null; private StatusEnum status = null;
private Boolean complete = false; private Boolean complete = false;
/** /**
**/ **/
public Order id(Long id) { public Order id(Long id) {
@ -75,6 +81,7 @@ public enum StatusEnum {
this.id = id; this.id = id;
} }
/** /**
**/ **/
public Order petId(Long petId) { public Order petId(Long petId) {
@ -92,6 +99,7 @@ public enum StatusEnum {
this.petId = petId; this.petId = petId;
} }
/** /**
**/ **/
public Order quantity(Integer quantity) { public Order quantity(Integer quantity) {
@ -109,6 +117,7 @@ public enum StatusEnum {
this.quantity = quantity; this.quantity = quantity;
} }
/** /**
**/ **/
public Order shipDate(java.util.Date shipDate) { public Order shipDate(java.util.Date shipDate) {
@ -126,6 +135,7 @@ public enum StatusEnum {
this.shipDate = shipDate; this.shipDate = shipDate;
} }
/** /**
* Order Status * Order Status
**/ **/
@ -144,6 +154,7 @@ public enum StatusEnum {
this.status = status; this.status = status;
} }
/** /**
**/ **/
public Order complete(Boolean complete) { public Order complete(Boolean complete) {
@ -162,6 +173,7 @@ public enum StatusEnum {
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {

View File

@ -23,10 +23,15 @@ import javax.xml.bind.annotation.*;
public class Pet { public class Pet {
private Long id = null; private Long id = null;
private Category category = null; private Category category = null;
private String name = null; private String name = null;
private List<String> photoUrls = new ArrayList<String>(); private List<String> photoUrls = new ArrayList<String>();
private List<Tag> tags = new ArrayList<Tag>();
private List<Tag> tags = null;
@XmlType(name="StatusEnum") @XmlType(name="StatusEnum")
@XmlEnum(String.class) @XmlEnum(String.class)
@ -62,6 +67,7 @@ public enum StatusEnum {
private StatusEnum status = null; private StatusEnum status = null;
/** /**
**/ **/
public Pet id(Long id) { public Pet id(Long id) {
@ -79,6 +85,7 @@ public enum StatusEnum {
this.id = id; this.id = id;
} }
/** /**
**/ **/
public Pet category(Category category) { public Pet category(Category category) {
@ -96,6 +103,7 @@ public enum StatusEnum {
this.category = category; this.category = category;
} }
/** /**
**/ **/
public Pet name(String name) { public Pet name(String name) {
@ -114,6 +122,7 @@ public enum StatusEnum {
this.name = name; this.name = name;
} }
/** /**
**/ **/
public Pet photoUrls(List<String> photoUrls) { public Pet photoUrls(List<String> photoUrls) {
@ -132,6 +141,12 @@ public enum StatusEnum {
this.photoUrls = photoUrls; this.photoUrls = photoUrls;
} }
public Pet addPhotoUrlsItem(String photoUrlsItem) {
this.photoUrls.add(photoUrlsItem);
return this;
}
/** /**
**/ **/
public Pet tags(List<Tag> tags) { public Pet tags(List<Tag> tags) {
@ -149,6 +164,15 @@ public enum StatusEnum {
this.tags = tags; this.tags = tags;
} }
public Pet addTagsItem(Tag tagsItem) {
if (this.tags == null) {
this.tags = new ArrayList<Tag>();
}
this.tags.add(tagsItem);
return this;
}
/** /**
* pet status in the store * pet status in the store
**/ **/
@ -168,6 +192,7 @@ public enum StatusEnum {
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {

View File

@ -19,8 +19,10 @@ import javax.xml.bind.annotation.*;
public class Tag { public class Tag {
private Long id = null; private Long id = null;
private String name = null; private String name = null;
/** /**
**/ **/
public Tag id(Long id) { public Tag id(Long id) {
@ -38,6 +40,7 @@ public class Tag {
this.id = id; this.id = id;
} }
/** /**
**/ **/
public Tag name(String name) { public Tag name(String name) {
@ -56,6 +59,7 @@ public class Tag {
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {

View File

@ -19,14 +19,22 @@ import javax.xml.bind.annotation.*;
public class User { public class User {
private Long id = null; private Long id = null;
private String username = null; private String username = null;
private String firstName = null; private String firstName = null;
private String lastName = null; private String lastName = null;
private String email = null; private String email = null;
private String password = null; private String password = null;
private String phone = null; private String phone = null;
private Integer userStatus = null; private Integer userStatus = null;
/** /**
**/ **/
public User id(Long id) { public User id(Long id) {
@ -44,6 +52,7 @@ public class User {
this.id = id; this.id = id;
} }
/** /**
**/ **/
public User username(String username) { public User username(String username) {
@ -61,6 +70,7 @@ public class User {
this.username = username; this.username = username;
} }
/** /**
**/ **/
public User firstName(String firstName) { public User firstName(String firstName) {
@ -78,6 +88,7 @@ public class User {
this.firstName = firstName; this.firstName = firstName;
} }
/** /**
**/ **/
public User lastName(String lastName) { public User lastName(String lastName) {
@ -95,6 +106,7 @@ public class User {
this.lastName = lastName; this.lastName = lastName;
} }
/** /**
**/ **/
public User email(String email) { public User email(String email) {
@ -112,6 +124,7 @@ public class User {
this.email = email; this.email = email;
} }
/** /**
**/ **/
public User password(String password) { public User password(String password) {
@ -129,6 +142,7 @@ public class User {
this.password = password; this.password = password;
} }
/** /**
**/ **/
public User phone(String phone) { public User phone(String phone) {
@ -146,6 +160,7 @@ public class User {
this.phone = phone; this.phone = phone;
} }
/** /**
* User Status * User Status
**/ **/
@ -165,6 +180,7 @@ public class User {
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {