File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed
modules/swagger-parser-v3/src
main/java/io/swagger/v3/parser/util
java/io/swagger/v3/parser/test Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 11
11
import io .swagger .v3 .oas .models .links .Link ;
12
12
import io .swagger .v3 .oas .models .media .ArraySchema ;
13
13
import io .swagger .v3 .oas .models .media .ComposedSchema ;
14
+ import io .swagger .v3 .oas .models .media .MapSchema ;
14
15
import io .swagger .v3 .oas .models .media .MediaType ;
15
16
import io .swagger .v3 .oas .models .media .ObjectSchema ;
16
17
import io .swagger .v3 .oas .models .media .Schema ;
@@ -307,6 +308,15 @@ public Schema resolveSchema(Schema schema) {
307
308
308
309
return arrayModel ;
309
310
}
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
+
310
320
if (schema instanceof ObjectSchema ) {
311
321
ObjectSchema obj = (ObjectSchema ) schema ;
312
322
if (obj .getProperties () != null ) {
Original file line number Diff line number Diff line change @@ -1931,6 +1931,21 @@ public void testIssue1063() {
1931
1931
1932
1932
}
1933
1933
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
+
1934
1949
private static int getDynamicPort () {
1935
1950
return new Random ().ints (10000 , 20000 ).findFirst ().getAsInt ();
1936
1951
}
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