@@ -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,177 @@ public void testAdditionalPropertiesWithAllOfV3() {
813801 }
814802
815803 @ Test
816- public void testAdditionalPropertiesWithAllOfV4 () {
804+ public void testIssue2157_AllOf_PreservesSchemaObject () {
817805 ParseOptions options = new ParseOptions ();
818806 options .setResolveFully (true );
819807 SwaggerParseResult result = new OpenAPIParser ().readLocation (
820- "additionalProperties_allOf_v4.yaml" , null , options );
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 () {
825+ ParseOptions options = new ParseOptions ();
826+ options .setResolveFully (true );
827+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
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_OneOf_PreservesBoolean () {
871+ ParseOptions options = new ParseOptions ();
872+ options .setResolveFully (true );
873+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
874+ "issue-2157/oneOf-preserves-boolean.yaml" , null , options );
875+ assertNotNull (result .getOpenAPI ());
876+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
877+ assertNotNull (schema );
878+ assertNotNull (schema .getOneOf ());
879+ assertEquals (schema .getOneOf ().size (), 1 );
880+ Schema oneOfBranch = (Schema ) schema .getOneOf ().get (0 );
881+ assertNotNull (oneOfBranch .getAdditionalProperties ());
882+ assertTrue ((Boolean ) oneOfBranch .getAdditionalProperties ());
883+ }
884+
885+ @ Test
886+ public void testIssue2157_OneOf_PreservesSchemaObject () {
887+ ParseOptions options = new ParseOptions ();
888+ options .setResolveFully (true );
889+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
890+ "issue-2157/oneOf-preserves-schema-object.yaml" , null , options );
891+ assertNotNull (result .getOpenAPI ());
892+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
893+ assertNotNull (schema );
894+ assertNotNull (schema .getOneOf ());
895+ assertEquals (schema .getOneOf ().size (), 1 );
896+ Schema oneOfBranch = (Schema ) schema .getOneOf ().get (0 );
897+ assertNotNull (oneOfBranch .getAdditionalProperties ());
898+ assertTrue (oneOfBranch .getAdditionalProperties () instanceof Schema );
899+ Schema additionalPropsSchema = (Schema ) oneOfBranch .getAdditionalProperties ();
900+ assertEquals (additionalPropsSchema .getType (), "string" );
901+ assertEquals (additionalPropsSchema .getMinLength (), Integer .valueOf (1 ));
902+ }
903+
904+ @ Test
905+ public void testIssue2157_OneOf_MultipleBranchesIndependent () {
906+ ParseOptions options = new ParseOptions ();
907+ options .setResolveFully (true );
908+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
909+ "issue-2157/oneOf-multiple-branches-independent.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 (), 2 );
915+ Schema firstBranch = (Schema ) schema .getOneOf ().get (0 );
916+ Schema secondBranch = (Schema ) schema .getOneOf ().get (1 );
917+ assertNotNull (firstBranch .getAdditionalProperties ());
918+ assertTrue ((Boolean ) firstBranch .getAdditionalProperties ());
919+ assertNotNull (secondBranch .getAdditionalProperties ());
920+ assertFalse ((Boolean ) secondBranch .getAdditionalProperties ());
921+ }
922+
923+ @ Test
924+ public void testIssue2157_AnyOf_PreservesBoolean () {
925+ ParseOptions options = new ParseOptions ();
926+ options .setResolveFully (true );
927+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
928+ "issue-2157/anyOf-preserves-boolean.yaml" , null , options );
929+ assertNotNull (result .getOpenAPI ());
930+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
931+ assertNotNull (schema );
932+ assertNotNull (schema .getAnyOf ());
933+ assertEquals (schema .getAnyOf ().size (), 1 );
934+ Schema anyOfBranch = (Schema ) schema .getAnyOf ().get (0 );
935+ assertNotNull (anyOfBranch .getAdditionalProperties ());
936+ assertTrue ((Boolean ) anyOfBranch .getAdditionalProperties ());
937+ }
938+
939+ @ Test
940+ public void testIssue2157_AnyOf_PreservesSchemaObject () {
941+ ParseOptions options = new ParseOptions ();
942+ options .setResolveFully (true );
943+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
944+ "issue-2157/anyOf-preserves-schema-object.yaml" , null , options );
945+ assertNotNull (result .getOpenAPI ());
946+ Schema schema = result .getOpenAPI ().getComponents ().getSchemas ().get ("TestSchema" );
947+ assertNotNull (schema );
948+ assertNotNull (schema .getAnyOf ());
949+ assertEquals (schema .getAnyOf ().size (), 1 );
950+ Schema anyOfBranch = (Schema ) schema .getAnyOf ().get (0 );
951+ assertNotNull (anyOfBranch .getAdditionalProperties ());
952+ assertTrue (anyOfBranch .getAdditionalProperties () instanceof Schema );
953+ Schema additionalPropsSchema = (Schema ) anyOfBranch .getAdditionalProperties ();
954+ assertEquals (additionalPropsSchema .getType (), "string" );
955+ assertEquals (additionalPropsSchema .getMinLength (), Integer .valueOf (1 ));
956+ }
957+
958+ @ Test
959+ public void testIssue2157_AnyOf_MultipleBranchesIndependent () {
960+ ParseOptions options = new ParseOptions ();
961+ options .setResolveFully (true );
962+ SwaggerParseResult result = new OpenAPIParser ().readLocation (
963+ "issue-2157/anyOf-multiple-branches-independent.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 (), 2 );
969+ Schema firstBranch = (Schema ) schema .getAnyOf ().get (0 );
970+ Schema secondBranch = (Schema ) schema .getAnyOf ().get (1 );
971+ assertNotNull (firstBranch .getAdditionalProperties ());
972+ assertTrue ((Boolean ) firstBranch .getAdditionalProperties ());
973+ assertNotNull (secondBranch .getAdditionalProperties ());
974+ assertFalse ((Boolean ) secondBranch .getAdditionalProperties ());
975+ }
827976}
828977
0 commit comments