[M][REQ][JAVA]: Add option to generate arrays with "uniqueItems" true as Sets rather than Lists (#5466)

* [REQ][JAVA]: Add option to generate arrays with "uniqueItems" true as Sets rather than Lists
 - Update Java code generation to use sets instead of lists when uniqueItems is set to true
 - Add import resolution for sets
 - Add tests and fix broke tests

resolve #5254

* Update Javascript, Perl, Python and Ruby to preserve current functionality.

* Switch set implementation to LinkedHashSet

* Fix missing import for uniqueItems used on param.

* Fix missing import and return type for responses with uniqueItems

* Fix default values for array of enum

* Update generated samples

* fix merge issue

* Update generated samples

Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
Januson
2020-05-21 07:27:57 +02:00
committed by GitHub
parent dec1365619
commit c49d8fda8e
348 changed files with 1264 additions and 604 deletions

View File

@@ -6,6 +6,7 @@ import org.openapitools.client.EncodingUtils;
import java.io.File;
import org.openapitools.client.model.ModelApiResponse;
import org.openapitools.client.model.Pet;
import java.util.Set;
import java.util.ArrayList;
import java.util.HashMap;
@@ -90,13 +91,13 @@ public interface PetApi extends ApiClient.Api {
* Finds Pets by tags
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @param tags Tags to filter by (required)
* @return List&lt;Pet&gt;
* @return Set&lt;Pet&gt;
*/
@RequestLine("GET /pet/findByTags?tags={tags}")
@Headers({
"Accept: application/json",
})
List<Pet> findPetsByTags(@Param("tags") List<String> tags);
Set<Pet> findPetsByTags(@Param("tags") Set<String> tags);
/**
* Finds Pets by tags
@@ -111,20 +112,20 @@ public interface PetApi extends ApiClient.Api {
* <ul>
* <li>tags - Tags to filter by (required)</li>
* </ul>
* @return List&lt;Pet&gt;
* @return Set&lt;Pet&gt;
*/
@RequestLine("GET /pet/findByTags?tags={tags}")
@Headers({
"Accept: application/json",
})
List<Pet> findPetsByTags(@QueryMap(encoded=true) Map<String, Object> queryParams);
Set<Pet> findPetsByTags(@QueryMap(encoded=true) Map<String, Object> queryParams);
/**
* A convenience class for generating query parameters for the
* <code>findPetsByTags</code> method in a fluent style.
*/
public static class FindPetsByTagsQueryParams extends HashMap<String, Object> {
public FindPetsByTagsQueryParams tags(final List<String> value) {
public FindPetsByTagsQueryParams tags(final Set<String> value) {
put("tags", EncodingUtils.encodeCollection(value, "csv"));
return this;
}

View File

@@ -22,7 +22,9 @@ import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.openapitools.client.model.Category;
import org.openapitools.client.model.Tag;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -51,7 +53,7 @@ public class Pet {
private String name;
public static final String JSON_PROPERTY_PHOTO_URLS = "photoUrls";
private List<String> photoUrls = new ArrayList<String>();
private Set<String> photoUrls = new LinkedHashSet<String>();
public static final String JSON_PROPERTY_TAGS = "tags";
private List<Tag> tags = null;
@@ -171,7 +173,7 @@ public class Pet {
}
public Pet photoUrls(List<String> photoUrls) {
public Pet photoUrls(Set<String> photoUrls) {
this.photoUrls = photoUrls;
return this;
@@ -190,12 +192,12 @@ public class Pet {
@JsonProperty(JSON_PROPERTY_PHOTO_URLS)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public List<String> getPhotoUrls() {
public Set<String> getPhotoUrls() {
return photoUrls;
}
public void setPhotoUrls(List<String> photoUrls) {
public void setPhotoUrls(Set<String> photoUrls) {
this.photoUrls = photoUrls;
}