[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

@@ -217,7 +217,7 @@ Name | Type | Description | Notes
<a name="findPetsByTags"></a>
# **findPetsByTags**
> List&lt;Pet&gt; findPetsByTags(tags)
> Set&lt;Pet&gt; findPetsByTags(tags)
Finds Pets by tags
@@ -243,9 +243,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");
@@ -262,11 +262,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

@@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.File;
import org.openapitools.client.model.ModelApiResponse;
import org.openapitools.client.model.Pet;
import java.util.Set;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -418,7 +419,7 @@ public class PetApi {
* @deprecated
*/
@Deprecated
public okhttp3.Call findPetsByTagsCall(List<String> tags, final ApiCallback _callback) throws ApiException {
public okhttp3.Call findPetsByTagsCall(Set<String> tags, final ApiCallback _callback) throws ApiException {
Object localVarPostBody = null;
// create path and map variables
@@ -453,7 +454,7 @@ public class PetApi {
@Deprecated
@SuppressWarnings("rawtypes")
private okhttp3.Call findPetsByTagsValidateBeforeCall(List<String> tags, final ApiCallback _callback) throws ApiException {
private okhttp3.Call findPetsByTagsValidateBeforeCall(Set<String> tags, final ApiCallback _callback) throws ApiException {
// verify the required parameter 'tags' is set
if (tags == null) {
@@ -470,7 +471,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 fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
@@ -481,8 +482,8 @@ public class PetApi {
* @deprecated
*/
@Deprecated
public List<Pet> findPetsByTags(List<String> tags) throws ApiException {
ApiResponse<List<Pet>> localVarResp = findPetsByTagsWithHttpInfo(tags);
public Set<Pet> findPetsByTags(Set<String> tags) throws ApiException {
ApiResponse<Set<Pet>> localVarResp = findPetsByTagsWithHttpInfo(tags);
return localVarResp.getData();
}
@@ -490,7 +491,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 fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
@@ -501,9 +502,9 @@ 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 {
okhttp3.Call localVarCall = findPetsByTagsValidateBeforeCall(tags, null);
Type localVarReturnType = new TypeToken<List<Pet>>(){}.getType();
Type localVarReturnType = new TypeToken<Set<Pet>>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
@@ -523,10 +524,10 @@ public class PetApi {
* @deprecated
*/
@Deprecated
public okhttp3.Call findPetsByTagsAsync(List<String> tags, final ApiCallback<List<Pet>> _callback) throws ApiException {
public okhttp3.Call findPetsByTagsAsync(Set<String> tags, final ApiCallback<Set<Pet>> _callback) throws ApiException {
okhttp3.Call localVarCall = findPetsByTagsValidateBeforeCall(tags, _callback);
Type localVarReturnType = new TypeToken<List<Pet>>(){}.getType();
Type localVarReturnType = new TypeToken<Set<Pet>>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}

View File

@@ -23,7 +23,9 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
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;
@@ -46,7 +48,7 @@ public class Pet {
public static final String SERIALIZED_NAME_PHOTO_URLS = "photoUrls";
@SerializedName(SERIALIZED_NAME_PHOTO_URLS)
private List<String> photoUrls = new ArrayList<String>();
private Set<String> photoUrls = new LinkedHashSet<String>();
public static final String SERIALIZED_NAME_TAGS = "tags";
@SerializedName(SERIALIZED_NAME_TAGS)
@@ -174,7 +176,7 @@ public class Pet {
}
public Pet photoUrls(List<String> photoUrls) {
public Pet photoUrls(Set<String> photoUrls) {
this.photoUrls = photoUrls;
return this;
@@ -191,12 +193,12 @@ public class Pet {
**/
@ApiModelProperty(required = true, value = "")
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
@@ -93,8 +94,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
}