[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

@@ -144,6 +144,7 @@ paths:
items:
type: string
type: array
uniqueItems: true
style: form
responses:
"200":
@@ -153,11 +154,13 @@ paths:
items:
$ref: '#/components/schemas/Pet'
type: array
uniqueItems: true
application/json:
schema:
items:
$ref: '#/components/schemas/Pet'
type: array
uniqueItems: true
description: successful operation
"400":
content: {}
@@ -1384,6 +1387,7 @@ components:
items:
type: string
type: array
uniqueItems: true
xml:
name: photoUrl
wrapped: true

View File

@@ -9,7 +9,7 @@ Name | Type | Description | Notes
**id** | **Long** | | [optional]
**category** | [**Category**](Category.md) | | [optional]
**name** | **String** | |
**photoUrls** | **List&lt;String&gt;** | |
**photoUrls** | **Set&lt;String&gt;** | |
**tags** | [**List&lt;Tag&gt;**](Tag.md) | | [optional]
**status** | [**StatusEnum**](#StatusEnum) | pet status in the store | [optional]

View File

@@ -227,7 +227,7 @@ Name | Type | Description | Notes
## findPetsByTags
> List&lt;Pet&gt; findPetsByTags(tags)
> Set&lt;Pet&gt; findPetsByTags(tags)
Finds Pets by tags
@@ -254,9 +254,9 @@ public class Example {
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
PetApi apiInstance = new PetApi(defaultClient);
List<String> tags = Arrays.asList(); // List<String> | Tags to filter by
Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
try {
List<Pet> result = apiInstance.findPetsByTags(tags);
Set<Pet> result = apiInstance.findPetsByTags(tags);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#findPetsByTags");
@@ -274,11 +274,11 @@ public class Example {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**tags** | [**List&lt;String&gt;**](String.md)| Tags to filter by |
**tags** | [**Set&lt;String&gt;**](String.md)| Tags to filter by |
### Return type
[**List&lt;Pet&gt;**](Pet.md)
[**Set&lt;Pet&gt;**](Pet.md)
### Authorization

View File

@@ -11,6 +11,7 @@ import javax.ws.rs.core.GenericType;
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;
@@ -258,7 +259,7 @@ public class PetApi {
* 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;
* @throws ApiException if fails to make API call
* @http.response.details
<table summary="Response Details" border="1">
@@ -269,7 +270,7 @@ public class PetApi {
* @deprecated
*/
@Deprecated
public List<Pet> findPetsByTags(List<String> tags) throws ApiException {
public Set<Pet> findPetsByTags(Set<String> tags) throws ApiException {
return findPetsByTagsWithHttpInfo(tags).getData();
}
@@ -277,7 +278,7 @@ public class PetApi {
* 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 ApiResponse&lt;List&lt;Pet&gt;&gt;
* @return ApiResponse&lt;Set&lt;Pet&gt;&gt;
* @throws ApiException if fails to make API call
* @http.response.details
<table summary="Response Details" border="1">
@@ -288,7 +289,7 @@ public class PetApi {
* @deprecated
*/
@Deprecated
public ApiResponse<List<Pet>> findPetsByTagsWithHttpInfo(List<String> tags) throws ApiException {
public ApiResponse<Set<Pet>> findPetsByTagsWithHttpInfo(Set<String> tags) throws ApiException {
Object localVarPostBody = null;
// verify the required parameter 'tags' is set
@@ -322,7 +323,7 @@ public class PetApi {
String[] localVarAuthNames = new String[] { "petstore_auth" };
GenericType<List<Pet>> localVarReturnType = new GenericType<List<Pet>>() {};
GenericType<Set<Pet>> localVarReturnType = new GenericType<Set<Pet>>() {};
return apiClient.invokeAPI("PetApi.findPetsByTags", localVarPath, "GET", localVarQueryParams, localVarPostBody,
localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType,

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;
@@ -50,7 +52,7 @@ public class Pet {
private String name;
public static final String JSON_PROPERTY_PHOTO_URLS = "photoUrls";
private List<String> photoUrls = new ArrayList<>();
private Set<String> photoUrls = new LinkedHashSet<>();
public static final String JSON_PROPERTY_TAGS = "tags";
private List<Tag> tags = null;
@@ -170,7 +172,7 @@ public class Pet {
}
public Pet photoUrls(List<String> photoUrls) {
public Pet photoUrls(Set<String> photoUrls) {
this.photoUrls = photoUrls;
return this;
@@ -189,12 +191,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;
}

View File

@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* API tests for PetApi
@@ -90,8 +91,8 @@ public class PetApiTest {
*/
@Test
public void findPetsByTagsTest() throws ApiException {
List<String> tags = null;
List<Pet> response = api.findPetsByTags(tags);
Set<String> tags = null;
Set<Pet> response = api.findPetsByTags(tags);
// TODO: test validations
}