@@ -384,7 +384,8 @@ public Map<String, Property> parseResponseHeaders(com.wordnik.swagger.annotation
384384 if (!cls .equals (java .lang .Void .class ) && !"void" .equals (cls .toString ())) {
385385 Property property = ModelConverters .getInstance ().readAsProperty (cls );
386386 if (property != null ) {
387- Property responseProperty = wrapContainer (header .responseContainer (), property );
387+ Property responseProperty = ContainerWrapper .wrapContainer (header .responseContainer (), property ,
388+ ContainerWrapper .ARRAY , ContainerWrapper .LIST , ContainerWrapper .SET );
388389 responseProperty .setDescription (description );
389390 responseHeaders .put (name , responseProperty );
390391 }
@@ -472,7 +473,7 @@ public Operation parseMethod(Method method) {
472473 if (isPrimitive (responseClass )) {
473474 Property property = ModelConverters .getInstance ().readAsProperty (responseClass );
474475 if (property != null ) {
475- Property responseProperty = wrapContainer (responseContainer , property );
476+ Property responseProperty = ContainerWrapper . wrapContainer (responseContainer , property );
476477 operation .response (responseCode , new Response ()
477478 .description (SUCCESSFUL_OPERATION )
478479 .schema (responseProperty )
@@ -490,7 +491,7 @@ else if(!responseClass.equals(java.lang.Void.class) && !"void".equals(responseCl
490491 }
491492 for (String key : models .keySet ()) {
492493 Property property = new RefProperty ().asDefault (key );
493- Property responseProperty = wrapContainer (responseContainer , property );
494+ Property responseProperty = ContainerWrapper . wrapContainer (responseContainer , property );
494495 operation .response (responseCode , new Response ()
495496 .description (SUCCESSFUL_OPERATION )
496497 .schema (responseProperty )
@@ -544,7 +545,7 @@ else if(!responseClass.equals(java.lang.Void.class) && !"void".equals(responseCl
544545 Map <String , Model > models = ModelConverters .getInstance ().read (responseClass );
545546 for (String key : models .keySet ()) {
546547 Property property = new RefProperty ().asDefault (key );
547- Property responseProperty = wrapContainer (apiResponse .responseContainer (), property );
548+ Property responseProperty = ContainerWrapper . wrapContainer (apiResponse .responseContainer (), property );
548549 response .schema (responseProperty );
549550 swagger .model (key , models .get (key ));
550551 }
@@ -585,19 +586,6 @@ else if(!responseClass.equals(java.lang.Void.class) && !"void".equals(responseCl
585586 return operation ;
586587 }
587588
588- private Property wrapContainer (String container , Property property ) {
589- if ("list" .equalsIgnoreCase (container ) || "array" .equalsIgnoreCase (container )) {
590- return new ArrayProperty (property );
591- } else if ("set" .equalsIgnoreCase (container )) {
592- ArrayProperty arrayProperty = new ArrayProperty (property );
593- arrayProperty .setUniqueItems (true );
594- return arrayProperty ;
595- } else if ("map" .equalsIgnoreCase (container )) {
596- return new MapProperty (property );
597- }
598- return property ;
599- }
600-
601589 List <Parameter > getParameters (Class <?> cls , Type type , Annotation [] annotations ) {
602590 // look for path, query
603591 boolean isArray = ParameterUtils .isMethodArgumentAnArray (cls , type );
@@ -714,4 +702,58 @@ private boolean isIgnored(String path) {
714702 return false ;
715703 }
716704
705+ enum ContainerWrapper {
706+ LIST ("list" ) {
707+ @ Override
708+ protected Property doWrap (Property property ) {
709+ return new ArrayProperty (property );
710+ }
711+ },
712+ ARRAY ("array" ) {
713+ @ Override
714+ protected Property doWrap (Property property ) {
715+ return new ArrayProperty (property );
716+ }
717+ },
718+ MAP ("map" ) {
719+ @ Override
720+ protected Property doWrap (Property property ) {
721+ return new MapProperty (property );
722+ }
723+ },
724+ SET ("set" ) {
725+ @ Override
726+ protected Property doWrap (Property property ) {
727+ ArrayProperty arrayProperty = new ArrayProperty (property );
728+ arrayProperty .setUniqueItems (true );
729+ return arrayProperty ;
730+ }
731+ };
732+
733+ private final String container ;
734+
735+ ContainerWrapper (String container ) {
736+ this .container = container ;
737+ }
738+
739+ public Property wrap (String container , Property property ) {
740+ if (this .container .equalsIgnoreCase (container )) {
741+ return doWrap (property );
742+ }
743+ return null ;
744+ }
745+
746+ public static Property wrapContainer (String container , Property property , ContainerWrapper ... allowed ) {
747+ final Set <ContainerWrapper > tmp = allowed .length > 0 ? EnumSet .copyOf (Arrays .asList (allowed )) : EnumSet .allOf (ContainerWrapper .class );
748+ for (ContainerWrapper wrapper : tmp ) {
749+ final Property prop = wrapper .wrap (container , property );
750+ if (prop != null ) {
751+ return prop ;
752+ }
753+ }
754+ return property ;
755+ }
756+
757+ protected abstract Property doWrap (Property property );
758+ }
717759}
0 commit comments