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]
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ Name | Type | Description | Notes
|
||||
|
||||
## findPetsByTags
|
||||
|
||||
> List<Pet> findPetsByTags(tags)
|
||||
> Set<Pet> 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<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
|
||||
|
||||
|
||||
@@ -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<Pet>
|
||||
* @return Set<Pet>
|
||||
* @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<List<Pet>>
|
||||
* @return ApiResponse<Set<Pet>>
|
||||
* @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,
|
||||
|
||||
@@ -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<String>();
|
||||
private Set<String> photoUrls = new LinkedHashSet<String>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,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
|
||||
|
||||
Reference in New Issue
Block a user