Skip to content

Commit e6b3f65

Browse files
authored
Merge pull request #1124 from douglasbgray/resolve-fully-map
Fix for fully resoling map schema.
2 parents aa83ef4 + 5836def commit e6b3f65

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.swagger.v3.oas.models.links.Link;
1212
import io.swagger.v3.oas.models.media.ArraySchema;
1313
import io.swagger.v3.oas.models.media.ComposedSchema;
14+
import io.swagger.v3.oas.models.media.MapSchema;
1415
import io.swagger.v3.oas.models.media.MediaType;
1516
import io.swagger.v3.oas.models.media.ObjectSchema;
1617
import io.swagger.v3.oas.models.media.Schema;
@@ -307,6 +308,15 @@ public Schema resolveSchema(Schema schema) {
307308

308309
return arrayModel;
309310
}
311+
312+
if (schema instanceof MapSchema) {
313+
MapSchema mapSchema = (MapSchema) schema;
314+
if (mapSchema.getAdditionalProperties() instanceof Schema) {
315+
Schema additionalPropertiesSchema = (Schema) mapSchema.getAdditionalProperties();
316+
mapSchema.setAdditionalProperties(resolveSchema(additionalPropertiesSchema));
317+
}
318+
}
319+
310320
if (schema instanceof ObjectSchema) {
311321
ObjectSchema obj = (ObjectSchema) schema;
312322
if(obj.getProperties() != null) {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,21 @@ public void testIssue1063() {
19311931

19321932
}
19331933

1934+
@Test
1935+
public void testResolveFullyMap() {
1936+
ParseOptions options = new ParseOptions();
1937+
options.setResolveFully(false);
1938+
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("resolve-fully-map.yaml", null, options).getOpenAPI();
1939+
String yaml = Yaml.pretty(openAPI);
1940+
assertTrue(yaml.contains("$ref"));
1941+
1942+
options = new ParseOptions();
1943+
options.setResolveFully(true);
1944+
openAPI = new OpenAPIV3Parser().readLocation("resolve-fully-map.yaml", null, options).getOpenAPI();
1945+
yaml = Yaml.pretty(openAPI);
1946+
assertFalse(yaml.contains("$ref"));
1947+
}
1948+
19341949
private static int getDynamicPort() {
19351950
return new Random().ints(10000, 20000).findFirst().getAsInt();
19361951
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
openapi: 3.0.0
2+
servers:
3+
- url: 'http://localhost:8080/sample'
4+
info:
5+
description: A simple API to learn how to write OpenAPI Specification
6+
version: 1.0.1
7+
title: Simple API
8+
paths:
9+
/sample:
10+
get:
11+
tags:
12+
- Sample
13+
operationId: getSample
14+
responses:
15+
'200':
16+
description: Sample
17+
content:
18+
application/json:
19+
schema:
20+
$ref: '#/components/schemas/MyModelMap'
21+
components:
22+
schemas:
23+
MyModel:
24+
type: object
25+
properties:
26+
name:
27+
type: string
28+
MyModelMap:
29+
type: object
30+
additionalProperties:
31+
$ref: "#/components/schemas/MyModel"

0 commit comments

Comments
 (0)