forked from loafle/openapi-generator-original
[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:
@@ -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
|
||||
|
||||
@@ -9,7 +9,7 @@ Name | Type | Description | Notes
|
||||
**id** | **Long** | | [optional]
|
||||
**category** | [**Category**](Category.md) | | [optional]
|
||||
**name** | **String** | |
|
||||
**photoUrls** | **List<String>** | |
|
||||
**photoUrls** | **Set<String>** | |
|
||||
**tags** | [**List<Tag>**](Tag.md) | | [optional]
|
||||
**status** | [**StatusEnum**](#StatusEnum) | pet status in the store | [optional]
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ Name | Type | Description | Notes
|
||||
|
||||
<a name="findPetsByTags"></a>
|
||||
# **findPetsByTags**
|
||||
> List<Pet> findPetsByTags(tags)
|
||||
> Set<Pet> 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<String>**](String.md)| Tags to filter by |
|
||||
**tags** | [**Set<String>**](String.md)| Tags to filter by |
|
||||
|
||||
### Return type
|
||||
|
||||
[**List<Pet>**](Pet.md)
|
||||
[**Set<Pet>**](Pet.md)
|
||||
|
||||
### Authorization
|
||||
|
||||
|
||||
@@ -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<Pet>
|
||||
* @return Set<Pet>
|
||||
* @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<List<Pet>>
|
||||
* @return ApiResponse<Set<Pet>>
|
||||
* @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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user