Skip to content

Commit

Permalink
[JaxRS-Java] issue with implFolder on windows, and required fields ge…
Browse files Browse the repository at this point in the history
…neration for containers (#88)

* Fix implFolder issue with jaxrs-cxf-cdi generator

This fix is for the issue:
swagger-api/swagger-codegen#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.
  • Loading branch information
selliera authored and jmini committed May 17, 2018
1 parent 4889103 commit d890d73
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.slf4j.LoggerFactory;

import java.net.URL;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -240,11 +241,11 @@ public String apiFilename(String templateName, String tag) {
String result = super.apiFilename(templateName, tag);

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.replace(apiFileFolder(), implFileFolder(implFolder));
} 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.replace(apiFileFolder(), implFileFolder(implFolder));
} else if (templateName.endsWith("Service.mustache")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}

{{>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}}
/**
Expand Down Expand Up @@ -39,6 +44,31 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
public void {{setter}}({{{datatypeWithEnum}}} {{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}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
public class Category {

private Long id = null;

private String name = null;


/**
**/
public Category id(Long id) {
Expand All @@ -38,6 +40,7 @@ public void setId(Long id) {
this.id = id;
}


/**
**/
public Category name(String name) {
Expand All @@ -56,6 +59,7 @@ public void setName(String name) {
}



@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
public class ModelApiResponse {

private Integer code = null;

private String type = null;

private String message = null;


/**
**/
public ModelApiResponse code(Integer code) {
Expand All @@ -39,6 +42,7 @@ public void setCode(Integer code) {
this.code = code;
}


/**
**/
public ModelApiResponse type(String type) {
Expand All @@ -56,6 +60,7 @@ public void setType(String type) {
this.type = type;
}


/**
**/
public ModelApiResponse message(String message) {
Expand All @@ -74,6 +79,7 @@ public void setMessage(String message) {
}



@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
public class Order {

private Long id = null;

private Long petId = null;

private Integer quantity = null;

private java.util.Date shipDate = null;


@XmlType(name="StatusEnum")
@XmlEnum(String.class)
public enum StatusEnum {
Expand Down Expand Up @@ -56,8 +60,10 @@ public static StatusEnum fromValue(String v) {
}

private StatusEnum status = null;

private Boolean complete = false;


/**
**/
public Order id(Long id) {
Expand All @@ -75,6 +81,7 @@ public void setId(Long id) {
this.id = id;
}


/**
**/
public Order petId(Long petId) {
Expand All @@ -92,6 +99,7 @@ public void setPetId(Long petId) {
this.petId = petId;
}


/**
**/
public Order quantity(Integer quantity) {
Expand All @@ -109,6 +117,7 @@ public void setQuantity(Integer quantity) {
this.quantity = quantity;
}


/**
**/
public Order shipDate(java.util.Date shipDate) {
Expand All @@ -126,6 +135,7 @@ public void setShipDate(java.util.Date shipDate) {
this.shipDate = shipDate;
}


/**
* Order Status
**/
Expand All @@ -144,6 +154,7 @@ public void setStatus(StatusEnum status) {
this.status = status;
}


/**
**/
public Order complete(Boolean complete) {
Expand All @@ -162,6 +173,7 @@ public void setComplete(Boolean complete) {
}



@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
public class Pet {

private Long id = null;

private Category category = null;

private String name = null;

private List<String> photoUrls = new ArrayList<String>();
private List<Tag> tags = new ArrayList<Tag>();

private List<Tag> tags = null;


@XmlType(name="StatusEnum")
@XmlEnum(String.class)
Expand Down Expand Up @@ -62,6 +67,7 @@ public static StatusEnum fromValue(String v) {

private StatusEnum status = null;


/**
**/
public Pet id(Long id) {
Expand All @@ -79,6 +85,7 @@ public void setId(Long id) {
this.id = id;
}


/**
**/
public Pet category(Category category) {
Expand All @@ -96,6 +103,7 @@ public void setCategory(Category category) {
this.category = category;
}


/**
**/
public Pet name(String name) {
Expand All @@ -114,6 +122,7 @@ public void setName(String name) {
this.name = name;
}


/**
**/
public Pet photoUrls(List<String> photoUrls) {
Expand All @@ -132,6 +141,12 @@ public void setPhotoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
}

public Pet addPhotoUrlsItem(String photoUrlsItem) {
this.photoUrls.add(photoUrlsItem);
return this;
}


/**
**/
public Pet tags(List<Tag> tags) {
Expand All @@ -149,6 +164,15 @@ public void setTags(List<Tag> 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
**/
Expand All @@ -168,6 +192,7 @@ public void setStatus(StatusEnum status) {
}



@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
public class Tag {

private Long id = null;

private String name = null;


/**
**/
public Tag id(Long id) {
Expand All @@ -38,6 +40,7 @@ public void setId(Long id) {
this.id = id;
}


/**
**/
public Tag name(String name) {
Expand All @@ -56,6 +59,7 @@ public void setName(String name) {
}



@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
Expand Down
Loading

0 comments on commit d890d73

Please sign in to comment.