This repository was archived by the owner on Nov 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
modules/swagger-parser-v3/src
main/java/io/swagger/v3/parser/util
java/io/swagger/v3/parser/test Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111import io .swagger .v3 .oas .models .links .Link ;
1212import io .swagger .v3 .oas .models .media .ArraySchema ;
1313import io .swagger .v3 .oas .models .media .ComposedSchema ;
14+ import io .swagger .v3 .oas .models .media .MapSchema ;
1415import io .swagger .v3 .oas .models .media .MediaType ;
1516import io .swagger .v3 .oas .models .media .ObjectSchema ;
1617import 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 ) {
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments