@@ -367,7 +367,8 @@ public Map<String, Property> parseResponseHeaders(com.wordnik.swagger.annotation
367367 if (!cls .equals (java .lang .Void .class ) && !"void" .equals (cls .toString ())) {
368368 Property property = ModelConverters .getInstance ().readAsProperty (cls );
369369 if (property != null ) {
370- Property responseProperty = wrapContainer (header .responseContainer (), property );
370+ Property responseProperty = ContainerWrapper .wrapContainer (header .responseContainer (), property ,
371+ ContainerWrapper .ARRAY , ContainerWrapper .LIST , ContainerWrapper .SET );
371372 responseProperty .setDescription (description );
372373 responseHeaders .put (name , responseProperty );
373374 }
@@ -455,7 +456,7 @@ public Operation parseMethod(Method method) {
455456 if (isPrimitive (responseClass )) {
456457 Property property = ModelConverters .getInstance ().readAsProperty (responseClass );
457458 if (property != null ) {
458- Property responseProperty = wrapContainer (responseContainer , property );
459+ Property responseProperty = ContainerWrapper . wrapContainer (responseContainer , property );
459460 operation .response (responseCode , new Response ()
460461 .description (SUCCESSFUL_OPERATION )
461462 .schema (responseProperty )
@@ -473,7 +474,7 @@ else if(!responseClass.equals(java.lang.Void.class) && !"void".equals(responseCl
473474 }
474475 for (String key : models .keySet ()) {
475476 Property property = new RefProperty ().asDefault (key );
476- Property responseProperty = wrapContainer (responseContainer , property );
477+ Property responseProperty = ContainerWrapper . wrapContainer (responseContainer , property );
477478 operation .response (responseCode , new Response ()
478479 .description (SUCCESSFUL_OPERATION )
479480 .schema (responseProperty )
@@ -527,7 +528,7 @@ else if(!responseClass.equals(java.lang.Void.class) && !"void".equals(responseCl
527528 Map <String , Model > models = ModelConverters .getInstance ().read (responseClass );
528529 for (String key : models .keySet ()) {
529530 Property property = new RefProperty ().asDefault (key );
530- Property responseProperty = wrapContainer (apiResponse .responseContainer (), property );
531+ Property responseProperty = ContainerWrapper . wrapContainer (apiResponse .responseContainer (), property );
531532 response .schema (responseProperty );
532533 swagger .model (key , models .get (key ));
533534 }
@@ -568,19 +569,6 @@ else if(!responseClass.equals(java.lang.Void.class) && !"void".equals(responseCl
568569 return operation ;
569570 }
570571
571- private Property wrapContainer (String container , Property property ) {
572- if ("list" .equalsIgnoreCase (container ) || "array" .equalsIgnoreCase (container )) {
573- return new ArrayProperty (property );
574- } else if ("set" .equalsIgnoreCase (container )) {
575- ArrayProperty arrayProperty = new ArrayProperty (property );
576- arrayProperty .setUniqueItems (true );
577- return arrayProperty ;
578- } else if ("map" .equalsIgnoreCase (container )) {
579- return new MapProperty (property );
580- }
581- return property ;
582- }
583-
584572 List <Parameter > getParameters (Class <?> cls , Type type , Annotation [] annotations ) {
585573 // look for path, query
586574 boolean isArray = ParameterUtils .isMethodArgumentAnArray (cls , type );
@@ -682,4 +670,60 @@ private static Set<Scheme> parseSchemes(String schemes) {
682670 }
683671 return result ;
684672 }
673+
674+ enum ContainerWrapper {
675+ LIST ("list" ) {
676+ @ Override
677+ protected Property doWrap (Property property ) {
678+ return new ArrayProperty (property );
679+ }
680+ },
681+ ARRAY ("array" ) {
682+ @ Override
683+ protected Property doWrap (Property property ) {
684+ return new ArrayProperty (property );
685+ }
686+ },
687+ MAP ("map" ) {
688+ @ Override
689+ protected Property doWrap (Property property ) {
690+ return new MapProperty (property );
691+ }
692+ },
693+ SET ("set" ) {
694+ @ Override
695+ protected Property doWrap (Property property ) {
696+ ArrayProperty arrayProperty = new ArrayProperty (property );
697+ arrayProperty .setUniqueItems (true );
698+ return arrayProperty ;
699+ }
700+ };
701+
702+ private final String container ;
703+
704+ ContainerWrapper (String container ) {
705+ this .container = container ;
706+ }
707+
708+ public Property wrap (String container , Property property ) {
709+ if (this .container .equalsIgnoreCase (container )) {
710+ return doWrap (property );
711+ }
712+ return null ;
713+ }
714+
715+ public static Property wrapContainer (String container , Property property , ContainerWrapper ... allowed ) {
716+ final Set <ContainerWrapper > tmp = allowed .length > 0 ? EnumSet .copyOf (Arrays .asList (allowed )) : EnumSet .allOf (ContainerWrapper .class );
717+ for (ContainerWrapper wrapper : tmp ) {
718+ final Property prop = wrapper .wrap (container , property );
719+ if (prop != null ) {
720+ return prop ;
721+ }
722+ }
723+ return property ;
724+ }
725+
726+ protected abstract Property doWrap (Property property );
727+ }
728+
685729}
0 commit comments