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:
@@ -8,6 +8,7 @@ package org.openapitools.api;
|
||||
import org.openapitools.model.ModelApiResponse;
|
||||
import org.openapitools.model.Pet;
|
||||
import org.springframework.core.io.Resource;
|
||||
import java.util.Set;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -140,19 +141,19 @@ public interface PetApi {
|
||||
* or Invalid tag value (status code 400)
|
||||
* @deprecated
|
||||
*/
|
||||
@ApiOperation(value = "Finds Pets by tags", nickname = "findPetsByTags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = {
|
||||
@ApiOperation(value = "Finds Pets by tags", nickname = "findPetsByTags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "Set", authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ "pet", })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "Set"),
|
||||
@ApiResponse(code = 400, message = "Invalid tag value") })
|
||||
@RequestMapping(value = "/pet/findByTags",
|
||||
produces = { "application/xml", "application/json" },
|
||||
method = RequestMethod.GET)
|
||||
default CompletableFuture<ResponseEntity<List<Pet>>> findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> tags) {
|
||||
default CompletableFuture<ResponseEntity<Set<Pet>>> findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) Set<String> tags) {
|
||||
return CompletableFuture.supplyAsync(()-> {
|
||||
getRequest().ifPresent(request -> {
|
||||
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
|
||||
|
||||
@@ -7,7 +7,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.model.Category;
|
||||
import org.openapitools.model.Tag;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
@@ -30,7 +32,7 @@ public class Pet {
|
||||
|
||||
@JsonProperty("photoUrls")
|
||||
@Valid
|
||||
private List<String> photoUrls = new ArrayList<>();
|
||||
private Set<String> photoUrls = new LinkedHashSet<>();
|
||||
|
||||
@JsonProperty("tags")
|
||||
@Valid
|
||||
@@ -138,7 +140,7 @@ public class Pet {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Pet photoUrls(List<String> photoUrls) {
|
||||
public Pet photoUrls(Set<String> photoUrls) {
|
||||
this.photoUrls = photoUrls;
|
||||
return this;
|
||||
}
|
||||
@@ -156,11 +158,11 @@ public class Pet {
|
||||
@NotNull
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user