Skip to content

Add explode support in combination with arrayShema annotation #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;

import static java.util.Objects.isNull;

/**
* The type Generic parameter builder.
* @author bnasslahsen
* @author bnasslahsen, coutin
*/
@SuppressWarnings("rawtypes")
public class GenericParameterService {
Expand Down Expand Up @@ -397,9 +399,10 @@ private void setParameterStyle(Parameter parameter, io.swagger.v3.oas.annotation
*/
private boolean isExplodable(io.swagger.v3.oas.annotations.Parameter p) {
io.swagger.v3.oas.annotations.media.Schema schema = p.schema();
io.swagger.v3.oas.annotations.media.ArraySchema arraySchema = p.array();
boolean explode = true;
Class<?> implementation = schema.implementation();
if (implementation == Void.class && !schema.type().equals("object") && !schema.type().equals("array")) {
if (implementation == Void.class && !schema.type().equals("object") && !schema.type().equals("array") && isNull(arraySchema)) {
explode = false;
}
return explode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import javax.validation.constraints.Size;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.Explode;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;

Expand All @@ -47,7 +49,8 @@ public class ItemController {
@GetMapping("/items")
public List<ItemDTO> showItems(@RequestParam("cusID") @Size(min = 4, max = 6) final String customerID,
@Size(min = 4, max = 6) int toto,
@Parameter(name = "start", in = ParameterIn.QUERY, required = false, schema = @Schema(type = "string", format = "date-time", required = false, example = "1970-01-01T00:00:00.000Z")) @RequestParam(value = "start", required = false) Instant startDate) {
@Parameter(name = "start", in = ParameterIn.QUERY, required = false, schema = @Schema(type = "string", format = "date-time", required = false, example = "1970-01-01T00:00:00.000Z")) @RequestParam(value = "start", required = false) Instant startDate,
@Parameter(name = "filterIds", in = ParameterIn.QUERY, array = @ArraySchema(schema = @Schema(type = "string")), explode = Explode.FALSE) @RequestParam(required = false) List<String> filterIds) {
return new ArrayList<ItemDTO>();
}

Expand Down
12 changes: 12 additions & 0 deletions springdoc-openapi-webmvc-core/src/test/resources/results/app1.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@
"format": "date-time",
"example": "1970-01-01T00:00:00.000Z"
}
},
{
"name": "filterIds",
"in": "query",
"required": false,
"explode": false,
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
],
"responses": {
Expand Down