@@ -40,7 +40,7 @@ public void testNPE_1685() {
4040 SwaggerParseResult swaggerParseResult = openAPIParser .readLocation ("issue1685.json" , null , options );
4141 assertNull (swaggerParseResult .getOpenAPI ());
4242 assertNotNull (swaggerParseResult .getMessages ());
43- assertTrue (swaggerParseResult .getMessages ().size () == 2 );
43+ assertTrue (swaggerParseResult .getMessages ().size () == 2 );
4444 assertEquals (swaggerParseResult .getMessages ().get (0 ), "attribute notswagger is unexpected" );
4545 assertEquals (swaggerParseResult .getMessages ().get (1 ), "attribute swagger is missing" );
4646 }
@@ -775,36 +775,24 @@ public void testIssue1552AdditionalProps() throws Exception {
775775
776776
777777 @ Test
778- public void testAdditionalPropertiesWithAllOfV1 () {
778+ public void testIssue2157_AllOf_SingleRefPreservesBoolean () {
779779 ParseOptions options = new ParseOptions ();
780780 options .setResolveFully (true );
781781 SwaggerParseResult result = new OpenAPIParser ().readLocation (
782- "additionalProperties_allOf_v1 .yaml" , null , options );
782+ "issue-2157/allOf-single-ref-boolean .yaml" , null , options );
783783 assertNotNull (result .getOpenAPI ());
784784 Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
785785 assertNotNull (schema );
786786 assertNotNull (schema .getAdditionalProperties ());
787787 assertTrue ((Boolean ) schema .getAdditionalProperties ());
788788 }
789- @ Test
790- public void testAdditionalPropertiesWithAllOfV2 () {
791- ParseOptions options = new ParseOptions ();
792- options .setResolveFully (true );
793- SwaggerParseResult result = new OpenAPIParser ().readLocation (
794- "additionalProperties_allOf_v2.yaml" , null , options );
795- assertNotNull (result .getOpenAPI ());
796- Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
797- assertNotNull (schema );
798- assertNotNull (schema .getAdditionalProperties ());
799- assertTrue ((Boolean ) schema .getAdditionalProperties ());
800- }
801789
802790 @ Test
803- public void testAdditionalPropertiesWithAllOfV3 () {
791+ public void testIssue2157_AllOf_RefAndInlineMerge () {
804792 ParseOptions options = new ParseOptions ();
805793 options .setResolveFully (true );
806794 SwaggerParseResult result = new OpenAPIParser ().readLocation (
807- "additionalProperties_allOf_v3 .yaml" , null , options );
795+ "issue-2157/allOf-ref-and-inline-merge .yaml" , null , options );
808796 assertNotNull (result .getOpenAPI ());
809797 Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
810798 assertNotNull (schema );
@@ -813,16 +801,212 @@ public void testAdditionalPropertiesWithAllOfV3() {
813801 }
814802
815803 @ Test
816- public void testAdditionalPropertiesWithAllOfV4 () {
804+ public void testIssue2157_AllOf_PreservesSchemaObject () {
805+ ParseOptions options = new ParseOptions ();
806+ options .setResolveFully (true );
807+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
808+ "issue-2157/allOf-preserves-schema-object.yaml" , null , options );
809+ assertNotNull (result .getOpenAPI ());
810+ RequestBody requestBody = result .getOpenAPI ().getPaths ().get ("/pet" ).getPut ().getRequestBody ();
811+ assertNotNull (requestBody );
812+ Schema schema = requestBody .getContent ().get ("application/json" ).getSchema ();
813+ assertNotNull (schema );
814+ assertNotNull (schema .getAdditionalProperties ());
815+ assertTrue (schema .getAdditionalProperties () instanceof Schema );
816+ Schema additionalPropsSchema = (Schema ) schema .getAdditionalProperties ();
817+ assertEquals (additionalPropsSchema .getType (), "string" );
818+ assertNotNull (schema .getProperties ());
819+ assertTrue (schema .getProperties ().containsKey ("id" ));
820+ assertTrue (schema .getProperties ().containsKey ("name" ));
821+ }
822+
823+ @ Test
824+ public void testIssue2157_AllOf_PreservesSchemaWithConstraints () {
817825 ParseOptions options = new ParseOptions ();
818826 options .setResolveFully (true );
819827 SwaggerParseResult result = new OpenAPIParser ().readLocation (
820- "additionalProperties_allOf_v4.yaml" , null , options );
828+ "issue-2157/allOf-preserves-schema-with-constraints.yaml" , null , options );
829+ assertNotNull (result .getOpenAPI ());
830+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
831+ assertNotNull (schema );
832+ assertNotNull (schema .getAdditionalProperties ());
833+ assertTrue (schema .getAdditionalProperties () instanceof Schema );
834+ Schema additionalPropsSchema = (Schema ) schema .getAdditionalProperties ();
835+ assertEquals (additionalPropsSchema .getType (), "string" );
836+ assertEquals (additionalPropsSchema .getMinLength (), Integer .valueOf (1 ));
837+ assertEquals (additionalPropsSchema .getMaxLength (), Integer .valueOf (100 ));
838+ assertNotNull (schema .getProperties ());
839+ assertTrue (schema .getProperties ().containsKey ("id" ));
840+ assertTrue (schema .getProperties ().containsKey ("name" ));
841+ }
842+
843+ @ Test
844+ public void testIssue2157_AllOf_ConflictLastWinsInline () {
845+ ParseOptions options = new ParseOptions ();
846+ options .setResolveFully (true );
847+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
848+ "issue-2157/allOf-conflict-last-wins-inline.yaml" , null , options );
821849 assertNotNull (result .getOpenAPI ());
822850 Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
823851 assertNotNull (schema );
824852 assertNotNull (schema .getAdditionalProperties ());
825853 assertFalse ((Boolean ) schema .getAdditionalProperties ());
826854 }
855+
856+ @ Test
857+ public void testIssue2157_AllOf_ConflictLastWinsRef () {
858+ ParseOptions options = new ParseOptions ();
859+ options .setResolveFully (true );
860+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
861+ "issue-2157/allOf-conflict-last-wins-ref.yaml" , null , options );
862+ assertNotNull (result .getOpenAPI ());
863+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
864+ assertNotNull (schema );
865+ assertNotNull (schema .getAdditionalProperties ());
866+ assertTrue ((Boolean ) schema .getAdditionalProperties ());
867+ }
868+
869+ @ Test
870+ public void testIssue2157_AllOf_NoAggregationPreservesStructure () {
871+ ParseOptions options = new ParseOptions ();
872+ options .setResolveFully (true );
873+ options .setResolveCombinators (false );
874+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
875+ "issue-2157/allOf-no-aggregation-preserves-structure.yaml" , null , options );
876+ assertNotNull (result .getOpenAPI ());
877+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
878+ assertNotNull (schema );
879+ assertNotNull (schema .getAllOf ());
880+ assertEquals (schema .getAllOf ().size (), 2 );
881+ Schema firstBranch = (Schema ) schema .getAllOf ().get (0 );
882+ assertNotNull (firstBranch .getAdditionalProperties ());
883+ assertTrue ((Boolean ) firstBranch .getAdditionalProperties ());
884+ }
885+
886+ @ Test
887+ public void testIssue2157_AllOf_ConflictSchemaObjects () {
888+ ParseOptions options = new ParseOptions ();
889+ options .setResolveFully (true );
890+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
891+ "issue-2157/allOf-conflict-schema-objects.yaml" , null , options );
892+ assertNotNull (result .getOpenAPI ());
893+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
894+ assertNotNull (schema );
895+ assertNotNull (schema .getAdditionalProperties ());
896+ assertTrue (schema .getAdditionalProperties () instanceof Schema );
897+ Schema additionalPropsSchema = (Schema ) schema .getAdditionalProperties ();
898+ assertEquals (additionalPropsSchema .getType (), "number" );
899+ assertNotNull (schema .getProperties ());
900+ assertTrue (schema .getProperties ().containsKey ("name" ));
901+ assertTrue (schema .getProperties ().containsKey ("id" ));
902+ }
903+
904+ @ Test
905+ public void testIssue2157_OneOf_PreservesBoolean () {
906+ ParseOptions options = new ParseOptions ();
907+ options .setResolveFully (true );
908+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
909+ "issue-2157/oneOf-preserves-boolean.yaml" , null , options );
910+ assertNotNull (result .getOpenAPI ());
911+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
912+ assertNotNull (schema );
913+ assertNotNull (schema .getOneOf ());
914+ assertEquals (schema .getOneOf ().size (), 1 );
915+ Schema oneOfBranch = (Schema ) schema .getOneOf ().get (0 );
916+ assertNotNull (oneOfBranch .getAdditionalProperties ());
917+ assertTrue ((Boolean ) oneOfBranch .getAdditionalProperties ());
918+ }
919+
920+ @ Test
921+ public void testIssue2157_OneOf_PreservesSchemaObject () {
922+ ParseOptions options = new ParseOptions ();
923+ options .setResolveFully (true );
924+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
925+ "issue-2157/oneOf-preserves-schema-object.yaml" , null , options );
926+ assertNotNull (result .getOpenAPI ());
927+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
928+ assertNotNull (schema );
929+ assertNotNull (schema .getOneOf ());
930+ assertEquals (schema .getOneOf ().size (), 1 );
931+ Schema oneOfBranch = (Schema ) schema .getOneOf ().get (0 );
932+ assertNotNull (oneOfBranch .getAdditionalProperties ());
933+ assertTrue (oneOfBranch .getAdditionalProperties () instanceof Schema );
934+ Schema additionalPropsSchema = (Schema ) oneOfBranch .getAdditionalProperties ();
935+ assertEquals (additionalPropsSchema .getType (), "string" );
936+ assertEquals (additionalPropsSchema .getMinLength (), Integer .valueOf (1 ));
937+ }
938+
939+ @ Test
940+ public void testIssue2157_OneOf_MultipleBranchesIndependent () {
941+ ParseOptions options = new ParseOptions ();
942+ options .setResolveFully (true );
943+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
944+ "issue-2157/oneOf-multiple-branches-independent.yaml" , null , options );
945+ assertNotNull (result .getOpenAPI ());
946+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
947+ assertNotNull (schema );
948+ assertNotNull (schema .getOneOf ());
949+ assertEquals (schema .getOneOf ().size (), 2 );
950+ Schema firstBranch = (Schema ) schema .getOneOf ().get (0 );
951+ Schema secondBranch = (Schema ) schema .getOneOf ().get (1 );
952+ assertNotNull (firstBranch .getAdditionalProperties ());
953+ assertTrue ((Boolean ) firstBranch .getAdditionalProperties ());
954+ assertNotNull (secondBranch .getAdditionalProperties ());
955+ assertFalse ((Boolean ) secondBranch .getAdditionalProperties ());
956+ }
957+
958+ @ Test
959+ public void testIssue2157_AnyOf_PreservesBoolean () {
960+ ParseOptions options = new ParseOptions ();
961+ options .setResolveFully (true );
962+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
963+ "issue-2157/anyOf-preserves-boolean.yaml" , null , options );
964+ assertNotNull (result .getOpenAPI ());
965+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
966+ assertNotNull (schema );
967+ assertNotNull (schema .getAnyOf ());
968+ assertEquals (schema .getAnyOf ().size (), 1 );
969+ Schema anyOfBranch = (Schema ) schema .getAnyOf ().get (0 );
970+ assertNotNull (anyOfBranch .getAdditionalProperties ());
971+ assertTrue ((Boolean ) anyOfBranch .getAdditionalProperties ());
972+ }
973+
974+ @ Test
975+ public void testIssue2157_AnyOf_PreservesSchemaObject () {
976+ ParseOptions options = new ParseOptions ();
977+ options .setResolveFully (true );
978+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
979+ "issue-2157/anyOf-preserves-schema-object.yaml" , null , options );
980+ assertNotNull (result .getOpenAPI ());
981+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
982+ assertNotNull (schema );
983+ assertNotNull (schema .getAnyOf ());
984+ assertEquals (schema .getAnyOf ().size (), 1 );
985+ Schema anyOfBranch = (Schema ) schema .getAnyOf ().get (0 );
986+ assertNotNull (anyOfBranch .getAdditionalProperties ());
987+ assertTrue (anyOfBranch .getAdditionalProperties () instanceof Schema );
988+ Schema additionalPropsSchema = (Schema ) anyOfBranch .getAdditionalProperties ();
989+ assertEquals (additionalPropsSchema .getType (), "string" );
990+ assertEquals (additionalPropsSchema .getMinLength (), Integer .valueOf (1 ));
991+ }
992+
993+ @ Test
994+ public void testIssue2157_AnyOf_MultipleBranchesIndependent () {
995+ ParseOptions options = new ParseOptions ();
996+ options .setResolveFully (true );
997+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
998+ "issue-2157/anyOf-multiple-branches-independent.yaml" , null , options );
999+ assertNotNull (result .getOpenAPI ());
1000+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
1001+ assertNotNull (schema );
1002+ assertNotNull (schema .getAnyOf ());
1003+ assertEquals (schema .getAnyOf ().size (), 2 );
1004+ Schema firstBranch = (Schema ) schema .getAnyOf ().get (0 );
1005+ Schema secondBranch = (Schema ) schema .getAnyOf ().get (1 );
1006+ assertNotNull (firstBranch .getAdditionalProperties ());
1007+ assertTrue ((Boolean ) firstBranch .getAdditionalProperties ());
1008+ assertNotNull (secondBranch .getAdditionalProperties ());
1009+ assertFalse ((Boolean ) secondBranch .getAdditionalProperties ());
1010+ }
8271011}
8281012
0 commit comments