Skip to content

Commit 16638e3

Browse files
committed
refs #4065 - fix 'explode' resolution for parameters
1 parent 140d5ea commit 16638e3

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

Diff for: modules/swagger-core/src/main/java/io/swagger/v3/core/util/ParameterProcessor.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.lang.annotation.Annotation;
2222
import java.lang.reflect.Type;
2323
import java.util.ArrayList;
24+
import java.util.Arrays;
2425
import java.util.LinkedHashMap;
2526
import java.util.List;
2627
import java.util.Map;
@@ -311,13 +312,14 @@ public static void setParameterExplode(Parameter parameter, io.swagger.v3.oas.an
311312
private static boolean isExplodable(io.swagger.v3.oas.annotations.Parameter p, Parameter parameter) {
312313
io.swagger.v3.oas.annotations.media.Schema schema = AnnotationsUtils.hasArrayAnnotation(p.array()) ? p.array().schema() : p.schema();
313314
boolean explode = true;
314-
if ("form".equals(parameter.getIn())){
315-
return true;
316-
}
317315
if (schema != null) {
318316
Class implementation = schema.implementation();
319317
if (implementation == Void.class) {
320-
if (!schema.type().equals("object") && !schema.type().equals("array")) {
318+
if (!schema.type().equals("object") && !schema.type().equals("array") && !schema.type().isEmpty()) {
319+
explode = false;
320+
}
321+
if (schema.types().length != 0 &&
322+
(!Arrays.asList(schema.types()).contains("array") && !Arrays.asList(schema.types()).contains("object"))) {
321323
explode = false;
322324
}
323325
}

Diff for: modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/ReaderTest.java

+31
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import io.swagger.v3.jaxrs2.resources.Ticket3587Resource;
8383
import io.swagger.v3.jaxrs2.resources.Ticket3731BisResource;
8484
import io.swagger.v3.jaxrs2.resources.Ticket3731Resource;
85+
import io.swagger.v3.jaxrs2.resources.Ticket4065Resource;
8586
import io.swagger.v3.jaxrs2.resources.Ticket4412Resource;
8687
import io.swagger.v3.jaxrs2.resources.Ticket4446Resource;
8788
import io.swagger.v3.jaxrs2.resources.Ticket4483Resource;
@@ -5311,4 +5312,34 @@ public void testTicket4879() {
53115312
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
53125313
ModelConverters.reset();
53135314
}
5315+
5316+
@Test(description = "test explode FALSE")
5317+
public void testTicket4065() {
5318+
ModelConverters.reset();
5319+
SwaggerConfiguration config = new SwaggerConfiguration();
5320+
Reader reader = new Reader(config);
5321+
5322+
OpenAPI openAPI = reader.read(Ticket4065Resource.class);
5323+
String yaml = "openapi: 3.0.1\n" +
5324+
"paths:\n" +
5325+
" /bar:\n" +
5326+
" get:\n" +
5327+
" operationId: test\n" +
5328+
" parameters:\n" +
5329+
" - name: blub\n" +
5330+
" in: query\n" +
5331+
" explode: false\n" +
5332+
" schema:\n" +
5333+
" type: array\n" +
5334+
" items:\n" +
5335+
" type: integer\n" +
5336+
" format: int64\n" +
5337+
" responses:\n" +
5338+
" default:\n" +
5339+
" description: default response\n" +
5340+
" content:\n" +
5341+
" application/json: {}\n";
5342+
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
5343+
ModelConverters.reset();
5344+
}
53145345
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.swagger.v3.jaxrs2.resources;
2+
3+
import io.swagger.v3.oas.annotations.Parameter;
4+
import io.swagger.v3.oas.annotations.enums.Explode;
5+
import io.swagger.v3.oas.annotations.enums.ParameterIn;
6+
7+
import javax.ws.rs.GET;
8+
import javax.ws.rs.Path;
9+
import javax.ws.rs.Produces;
10+
11+
@Path("/bar")
12+
public class Ticket4065Resource {
13+
@GET
14+
@Path("")
15+
@Produces({"application/json"})
16+
public void test(
17+
@Parameter(in = ParameterIn.QUERY, name = "blub", explode = Explode.FALSE) Long[] ids
18+
) {}
19+
}

0 commit comments

Comments
 (0)