Skip to content

Commit 30b7dba

Browse files
committed
deserialize into MapSchema for bool additionalProperties
1 parent afba79c commit 30b7dba

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/util/ModelDeserializer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ private Schema deserializeObjectSchema(JsonNode node) {
9797
ms.setAdditionalProperties(innerSchema);
9898
schema = ms;
9999
} catch (Exception e) {
100-
schema = Json.mapper().convertValue(node, ObjectSchema.class);
101100
Boolean additionalPropsBoolean = Json.mapper().convertValue(additionalProperties, Boolean.class);
101+
if (additionalPropsBoolean) {
102+
schema = Json.mapper().convertValue(node, MapSchema.class);
103+
} else {
104+
schema = Json.mapper().convertValue(node, ObjectSchema.class);
105+
}
102106
schema.setAdditionalProperties(additionalPropsBoolean);
103107
}
104108

modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/properties/MapPropertyDeserializerTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.swagger.v3.oas.models.media.ObjectSchema;
99
import io.swagger.v3.oas.models.media.Schema;
1010
import io.swagger.v3.oas.models.responses.ApiResponse;
11+
import org.testng.Assert;
1112
import org.testng.annotations.Test;
1213

1314
import static io.swagger.v3.core.util.TestUtils.normalizeLineEnds;
@@ -83,6 +84,38 @@ public class MapPropertyDeserializerTest {
8384
" ]\n" +
8485
"}";
8586

87+
private static final String jsonAdditionalPropertiesBooleanTrue = "{\n" +
88+
" \"tags\": [\n" +
89+
" \"store\"\n" +
90+
" ],\n" +
91+
" \"summary\": \"Returns pet inventories by status\",\n" +
92+
" \"description\": \"Returns a map of status codes to quantities\",\n" +
93+
" \"operationId\": \"getInventory\",\n" +
94+
" \"produces\": [\n" +
95+
" \"application/json\"\n" +
96+
" ],\n" +
97+
" \"parameters\": [],\n" +
98+
" \"responses\": {\n" +
99+
" \"200\": {\n" +
100+
" \"description\": \"successful operation\",\n" +
101+
" \"content\": {\n" +
102+
" \"*/*\": {\n" +
103+
" \"schema\": {\n" +
104+
" \"type\": \"object\",\n" +
105+
" \"x-foo\": \"vendor x\",\n" +
106+
" \"additionalProperties\": true\n" +
107+
" }\n" +
108+
" }\n" +
109+
" }\n" +
110+
" }\n" +
111+
" },\n" +
112+
" \"security\": [\n" +
113+
" {\n" +
114+
" \"api_key\": []\n" +
115+
" }\n" +
116+
" ]\n" +
117+
"}";
118+
86119
@Test(description = "it should deserialize a response per #1349")
87120
public void testMapDeserialization() throws Exception {
88121

@@ -110,6 +143,18 @@ public void testBooleanAdditionalPropertiesDeserialization() throws Exception {
110143
assertTrue(responseSchema instanceof ObjectSchema);
111144

112145
assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
146+
Assert.assertFalse((Boolean)responseSchema.getAdditionalProperties());
147+
148+
operation = Json.mapper().readValue(jsonAdditionalPropertiesBooleanTrue, Operation.class);
149+
response = operation.getResponses().get("200");
150+
assertNotNull(response);
151+
152+
responseSchema = response.getContent().get("*/*").getSchema();
153+
assertNotNull(responseSchema);
154+
assertTrue(responseSchema instanceof MapSchema);
155+
156+
assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
157+
Assert.assertTrue((Boolean)responseSchema.getAdditionalProperties());
113158
}
114159

115160
@Test(description = "it should serialize a boolean additionalProperties")

0 commit comments

Comments
 (0)