1
1
package io .swagger .parser ;
2
2
3
- import com .fasterxml .jackson .databind .JsonNode ;
4
- import com .fasterxml .jackson .databind .node .ObjectNode ;
5
3
import io .swagger .models .ArrayModel ;
6
4
import io .swagger .models .AuthorizationScope ;
7
5
import io .swagger .models .Contact ;
39
37
import io .swagger .models .properties .Property ;
40
38
import io .swagger .models .properties .PropertyBuilder ;
41
39
import io .swagger .models .properties .RefProperty ;
40
+ import io .swagger .models .properties .StringProperty ;
42
41
import io .swagger .models .resourcelisting .ApiInfo ;
43
42
import io .swagger .models .resourcelisting .ApiKeyAuthorization ;
44
43
import io .swagger .models .resourcelisting .ApiListingReference ;
60
59
import java .util .List ;
61
60
import java .util .Map ;
62
61
62
+ import com .fasterxml .jackson .databind .JsonNode ;
63
+ import com .fasterxml .jackson .databind .node .ObjectNode ;
64
+
63
65
// legacy models
64
66
65
67
public class SwaggerCompatConverter implements SwaggerParserExtension {
@@ -234,6 +236,12 @@ public Parameter convertParameter(io.swagger.models.apideclaration.Parameter par
234
236
p = arrayProperty ;
235
237
} else {
236
238
p = propertyFromTypedObject (param );
239
+ if (p == null ) {
240
+ System .out .println (String .format (
241
+ "WARNING! No property detected for parameter '%s' (%s)! Falling back to string!" ,
242
+ param .getName (), param .getParamType ()));
243
+ p = new StringProperty ();
244
+ }
237
245
}
238
246
if (p instanceof ArrayProperty ) {
239
247
ArrayProperty ap = (ArrayProperty ) p ;
@@ -336,15 +344,11 @@ public Property propertyFromTypedObject(ExtendedTypedObject obj) {
336
344
}
337
345
}
338
346
339
- if (output == null ) {
340
- System .out .println ("WARNING! No property detected! Falling back to string!" );
341
- output = PropertyBuilder .build ("string" , null , null );
342
- }
343
-
344
347
return output ;
345
348
}
346
349
347
- public Operation convertOperation (String tag , io .swagger .models .apideclaration .Operation operation ) {
350
+ public Operation convertOperation (String tag , io .swagger .models .apideclaration .Operation operation ,
351
+ ApiDeclaration apiDeclaration ) {
348
352
Method method ;
349
353
350
354
if (operation .getMethod () == null ) {
@@ -366,16 +370,25 @@ public Operation convertOperation(String tag, io.swagger.models.apideclaration.O
366
370
output .parameter (convertParameter (parameter ));
367
371
}
368
372
369
- if (operation .getConsumes () != null ) {
373
+ if (operation .getConsumes () != null && ! operation . getConsumes (). isEmpty () ) {
370
374
for (String consumes : operation .getConsumes ()) {
371
375
output .consumes (consumes );
372
376
}
377
+ } else if (apiDeclaration .getConsumes () != null ) {
378
+ for (String consumes : apiDeclaration .getConsumes ()) {
379
+ output .consumes (consumes );
380
+ }
373
381
}
374
- if (operation .getProduces () != null ) {
382
+ if (operation .getProduces () != null && ! operation . getProduces (). isEmpty () ) {
375
383
for (String produces : operation .getProduces ()) {
376
384
output .produces (produces );
377
385
}
386
+ } else if (apiDeclaration .getProduces () != null ) {
387
+ for (String produces : apiDeclaration .getProduces ()) {
388
+ output .produces (produces );
389
+ }
378
390
}
391
+
379
392
for (ResponseMessage message : operation .getResponseMessages ()) {
380
393
Response response = new Response ().description (message .getMessage ());
381
394
@@ -502,7 +515,7 @@ public Swagger convert(ResourceListing resourceListing, List<ApiDeclaration> api
502
515
paths .put (apiPath , path );
503
516
}
504
517
for (io .swagger .models .apideclaration .Operation op : ops ) {
505
- Operation operation = convertOperation (tag , op );
518
+ Operation operation = convertOperation (tag , op , apiDeclaration );
506
519
507
520
if (op .getMethod () != null ) {
508
521
path .set (op .getMethod ().toString ().toLowerCase (), operation );
@@ -541,6 +554,7 @@ public Swagger convert(ResourceListing resourceListing, List<ApiDeclaration> api
541
554
}
542
555
}
543
556
557
+
544
558
Swagger swagger = new Swagger ()
545
559
.host (host )
546
560
.scheme (Scheme .forValue (scheme ))
0 commit comments