55import io .swagger .models .Swagger ;
66import io .swagger .models .auth .AuthorizationValue ;
77import io .swagger .parser .util .DeserializationUtils ;
8+ import io .swagger .parser .util .InlineModelResolver ;
9+ import io .swagger .parser .util .ParseOptions ;
810import io .swagger .parser .util .SwaggerDeserializationResult ;
911import io .swagger .util .Json ;
1012
@@ -59,6 +61,12 @@ public Swagger read(String location) {
5961 }
6062
6163 public Swagger read (String location , List <AuthorizationValue > auths , boolean resolve ) {
64+ ParseOptions options = new ParseOptions ();
65+ options .setResolve (resolve );
66+ return read (location , auths , options );
67+ }
68+
69+ public Swagger read (String location , List <AuthorizationValue > auths , ParseOptions options ) {
6270 if (location == null ) {
6371 return null ;
6472 }
@@ -68,11 +76,16 @@ public Swagger read(String location, List<AuthorizationValue> auths, boolean res
6876 try {
6977 output = new Swagger20Parser ().read (location , auths );
7078 if (output != null ) {
71- if (resolve ){
72- return new SwaggerResolver (output , auths , location ).resolve ();
73- } else {
74- return output ;
75- }
79+ if (options != null ) {
80+ if (options .isResolve ()) {
81+ output = new SwaggerResolver (output , auths , location ).resolve ();
82+ }
83+ if (options .isFlatten ()) {
84+ InlineModelResolver inlineModelResolver = new InlineModelResolver ();
85+ inlineModelResolver .flatten (output );
86+ }
87+ }
88+ return output ;
7689 }
7790 } catch (IOException e ) {
7891 }
@@ -146,14 +159,20 @@ public Swagger parse(String swaggerAsString, List<AuthorizationValue> auths) {
146159 }
147160
148161 public Swagger read (JsonNode node ) {
149- return read (node , new ArrayList < AuthorizationValue >(), false );
162+ return read (node , false );
150163 }
151164
152165 public Swagger read (JsonNode node , boolean resolve ) {
153- return read (node , new ArrayList <AuthorizationValue >(), resolve );
166+ return read (node , new ArrayList <>(), resolve );
154167 }
155168
156169 public Swagger read (JsonNode node , List <AuthorizationValue > authorizationValues , boolean resolve ) {
170+ ParseOptions options = new ParseOptions ();
171+ options .setResolve (resolve );
172+ return read (node , authorizationValues , options );
173+ }
174+
175+ public Swagger read (JsonNode node , List <AuthorizationValue > authorizationValues , ParseOptions options ) {
157176 if (node == null ) {
158177 return null ;
159178 }
@@ -164,11 +183,16 @@ public Swagger read(JsonNode node, List<AuthorizationValue> authorizationValues,
164183 try {
165184 output = new Swagger20Parser ().read (node );
166185 if (output != null ) {
167- if (resolve ) {
168- return new SwaggerResolver (output , authorizationValues ).resolve ();
169- } else {
170- return output ;
186+ if (options != null ) {
187+ if (options .isResolve ()) {
188+ output = new SwaggerResolver (output , authorizationValues ).resolve ();
189+ }
190+ if (options .isFlatten ()) {
191+ InlineModelResolver inlineModelResolver = new InlineModelResolver ();
192+ inlineModelResolver .flatten (output );
193+ }
171194 }
195+ return output ;
172196 }
173197 } catch (IOException e ) {
174198 }
0 commit comments