From 1d7e4d67407ca0d0a261e709c6f660c346859c22 Mon Sep 17 00:00:00 2001 From: Charles Andre Outin Date: Fri, 11 Dec 2020 11:54:22 +0200 Subject: [PATCH] Add explode support in combination with arrayShema annotation --- .../org/springdoc/core/GenericParameterService.java | 7 +++++-- .../test/org/springdoc/api/app1/ItemController.java | 5 ++++- .../src/test/resources/results/app1.json | 12 ++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericParameterService.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericParameterService.java index 418661997..8f17adcd8 100644 --- a/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericParameterService.java +++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericParameterService.java @@ -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 { @@ -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; diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app1/ItemController.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app1/ItemController.java index 0472a96ac..f0712b584 100644 --- a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app1/ItemController.java +++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app1/ItemController.java @@ -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; @@ -47,7 +49,8 @@ public class ItemController { @GetMapping("/items") public List 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 filterIds) { return new ArrayList(); } diff --git a/springdoc-openapi-webmvc-core/src/test/resources/results/app1.json b/springdoc-openapi-webmvc-core/src/test/resources/results/app1.json index ce08aaceb..10e9cdce0 100644 --- a/springdoc-openapi-webmvc-core/src/test/resources/results/app1.json +++ b/springdoc-openapi-webmvc-core/src/test/resources/results/app1.json @@ -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": {