22
22
import java .nio .file .Path ;
23
23
import java .nio .file .Paths ;
24
24
import java .util .ArrayList ;
25
- import java .util .Arrays ;
26
25
import java .util .Collections ;
27
- import java .util .Iterator ;
28
26
import java .util .List ;
29
27
import java .util .Objects ;
30
28
import java .util .ServiceLoader ;
@@ -97,7 +95,7 @@ public SwaggerParseResult readLocation(String url, List<AuthorizationValue> auth
97
95
98
96
@ Override
99
97
public SwaggerParseResult readContents (String swaggerAsString , List <AuthorizationValue > auth ,
100
- ParseOptions options ) {
98
+ ParseOptions options ) {
101
99
return readContents (swaggerAsString , auth , options , null );
102
100
}
103
101
@@ -127,6 +125,11 @@ public OpenAPI read(String location, List<AuthorizationValue> auths, ParseOption
127
125
return null ;
128
126
}
129
127
128
+ @ Deprecated
129
+ public SwaggerParseResult readWithInfo (String path , JsonNode node ) {
130
+ return parseJsonNode (path , node );
131
+ }
132
+
130
133
public SwaggerParseResult parseJsonNode (String path , JsonNode node ) {
131
134
return new OpenAPIDeserializer ().deserialize (node , path );
132
135
}
@@ -138,30 +141,35 @@ public SwaggerParseResult readContents(String yaml) {
138
141
}
139
142
140
143
private SwaggerParseResult readContents (String swaggerAsString , List <AuthorizationValue > auth , ParseOptions options ,
141
- String parentFileLocation ) {
144
+ String location ) {
142
145
if (swaggerAsString == null || swaggerAsString .trim ().isEmpty ()) {
143
- return SwaggerParseResult .ofError ("No swagger supplied " );
146
+ return SwaggerParseResult .ofError ("Null or empty definition " );
144
147
}
145
148
146
149
try {
147
150
final ObjectMapper mapper = getRightMapper (swaggerAsString );
148
151
final JsonNode rootNode = mapper .readTree (swaggerAsString );
149
- final SwaggerParseResult result = parseJsonNode (parentFileLocation , rootNode );
150
- return resolve (result , auth , options , parentFileLocation );
152
+ final SwaggerParseResult result = parseJsonNode (location , rootNode );
153
+ return resolve (result , auth , options , location );
151
154
} catch (JsonProcessingException e ) {
152
155
LOGGER .warn ("Exception while parsing:" , e );
153
- final String message = getParseErrorMessage (e .getOriginalMessage (), parentFileLocation );
156
+ final String message = getParseErrorMessage (e .getOriginalMessage (), location );
154
157
return SwaggerParseResult .ofError (message );
155
158
}
156
159
}
157
160
161
+ @ Deprecated
162
+ public SwaggerParseResult readWithInfo (String location , List <AuthorizationValue > auths ) {
163
+ return readContents (readContentFromLocation (location , auths ), auths , null );
164
+ }
165
+
158
166
private SwaggerParseResult resolve (SwaggerParseResult result , List <AuthorizationValue > auth , ParseOptions options ,
159
- String parentFileLocation ) {
167
+ String location ) {
160
168
try {
161
169
if (options != null ) {
162
170
if (options .isResolve () || options .isResolveFully ()) {
163
171
result .setOpenAPI (new OpenAPIResolver (result .getOpenAPI (), emptyListIfNull (auth ),
164
- parentFileLocation ).resolve ());
172
+ location ).resolve ());
165
173
if (options .isResolveFully ()) {
166
174
new ResolverFully (options .isResolveCombinators ()).resolveFully (result .getOpenAPI ());
167
175
}
@@ -180,12 +188,12 @@ private SwaggerParseResult resolve(SwaggerParseResult result, List<Authorization
180
188
return result ;
181
189
}
182
190
183
- private String getParseErrorMessage (String originalMessage , String parentFileLocation ) {
191
+ private String getParseErrorMessage (String originalMessage , String location ) {
184
192
if (Objects .isNull (originalMessage )) {
185
- return String .format ("Unable to parse `%s`" , parentFileLocation );
193
+ return String .format ("Unable to parse `%s`" , location );
186
194
}
187
195
if (originalMessage .startsWith ("Duplicate field" )) {
188
- return String .format (originalMessage + " in `%s`" , parentFileLocation );
196
+ return String .format (originalMessage + " in `%s`" , location );
189
197
}
190
198
return originalMessage ;
191
199
}
@@ -225,4 +233,35 @@ private String readContentFromLocation(String location, List<AuthorizationValue>
225
233
throw new ReadContentException (String .format ("Unable to read location `%s`" , adjustedLocation ), e );
226
234
}
227
235
}
236
+
237
+ /**
238
+ * Transform the swagger-model version of AuthorizationValue into a parser-specific one, to avoid
239
+ * dependencies across extensions
240
+ *
241
+ * @param input
242
+ * @return
243
+ */
244
+ @ Deprecated
245
+ protected List <AuthorizationValue > transform (List <AuthorizationValue > input ) {
246
+ if (input == null ) {
247
+ return null ;
248
+ }
249
+
250
+ List <AuthorizationValue > output = new ArrayList <>();
251
+
252
+ for (AuthorizationValue value : input ) {
253
+ AuthorizationValue v = new AuthorizationValue ();
254
+
255
+ v .setKeyName (value .getKeyName ());
256
+ v .setValue (value .getValue ());
257
+ v .setType (value .getType ());
258
+ v .setUrlMatcher (value .getUrlMatcher ());
259
+
260
+ output .add (v );
261
+ }
262
+
263
+ return output ;
264
+ }
265
+
266
+
228
267
}
0 commit comments