3030import static org .testng .Assert .*;
3131
3232public class OpenAPINormalizerTest {
33+
34+ private static final String REF_AS_PARENT_IN_ALLOF = "REF_AS_PARENT_IN_ALLOF" ;
35+ private static final String X_PARENT = "x-parent" ;
36+
3337 @ Test
3438 public void testOpenAPINormalizerRefAsParentInAllOf () {
3539 // to test the rule REF_AS_PARENT_IN_ALLOF
3640 OpenAPI openAPI = TestUtils .parseSpec ("src/test/resources/3_0/allOf_extension_parent.yaml" );
3741
38- Schema schema = openAPI .getComponents ().getSchemas ().get ("AnotherPerson" );
39- assertNull (schema .getExtensions ());
42+ Schema <?> anotherPerson = openAPI .getComponents ().getSchemas ().get ("AnotherPerson" );
43+ assertNull (anotherPerson .getExtensions ());
4044
41- Schema schema2 = openAPI .getComponents ().getSchemas ().get ("Person" );
42- assertEquals (schema2 .getExtensions ().get ("x-parent" ), "abstract" );
45+ Schema <?>person = openAPI .getComponents ().getSchemas ().get ("Person" );
46+ assertEquals (person .getExtensions ().get (X_PARENT ), "abstract" );
47+
48+ Schema <?> preNormPersonA = openAPI .getComponents ().getSchemas ().get ("PersonA" );
49+ assertNull (preNormPersonA .getExtensions ());
50+ Schema <?> preNormPersonB = openAPI .getComponents ().getSchemas ().get ("PersonB" );
51+ assertNull (preNormPersonB .getExtensions ());
4352
4453 Map <String , String > options = new HashMap <>();
45- options .put (" REF_AS_PARENT_IN_ALLOF" , "true" );
54+ options .put (REF_AS_PARENT_IN_ALLOF , "true" );
4655 OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
4756 openAPINormalizer .normalize ();
4857
49- Schema schema3 = openAPI .getComponents ().getSchemas ().get ("AnotherPerson" );
50- assertEquals (schema3 .getExtensions ().get ("x-parent" ), true );
58+ Schema <?>schema3 = openAPI .getComponents ().getSchemas ().get ("AnotherPerson" );
59+ assertEquals (schema3 .getExtensions ().get (X_PARENT ), true );
60+
61+ Schema <?>schema4 = openAPI .getComponents ().getSchemas ().get ("AnotherParent" );
62+ assertEquals (schema4 .getExtensions ().get (X_PARENT ), true );
5163
52- Schema schema4 = openAPI .getComponents ().getSchemas ().get ("AnotherParent " );
53- assertEquals (schema4 .getExtensions ().get ("x-parent" ), true );
64+ Schema <?> schema5 = openAPI .getComponents ().getSchemas ().get ("Person " );
65+ assertEquals (schema5 .getExtensions ().get (X_PARENT ), "abstract" );
5466
55- Schema schema5 = openAPI .getComponents ().getSchemas ().get ("Person" );
56- assertEquals (schema5 .getExtensions ().get ("x-parent" ), "abstract" );
67+ // Verify that all allOf refs gets marked as parents
68+ Schema <?>schemaWithTwoParents = openAPI .getComponents ().getSchemas ().get ("SchemaWithTwoParents" );
69+ assertNull (schemaWithTwoParents .getExtensions ());
70+ Schema <?>personA = openAPI .getComponents ().getSchemas ().get ("PersonA" );
71+ assertEquals (personA .getExtensions ().get (X_PARENT ), true );
72+ Schema <?>personB = openAPI .getComponents ().getSchemas ().get ("PersonB" );
73+ assertEquals (personB .getExtensions ().get (X_PARENT ), true );
5774 }
5875
5976 @ Test
@@ -68,13 +85,13 @@ public void testOpenAPINormalizerRefAsParentInAllOfAndRefactorAllOfWithPropertie
6885 assertNull (schema2 .getExtensions ());
6986
7087 Map <String , String > options = new HashMap <>();
71- options .put (" REF_AS_PARENT_IN_ALLOF" , "true" );
88+ options .put (REF_AS_PARENT_IN_ALLOF , "true" );
7289 options .put ("REFACTOR_ALLOF_WITH_PROPERTIES_ONLY" , "true" );
7390 OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer (openAPI , options );
7491 openAPINormalizer .normalize ();
7592
7693 Schema schema3 = openAPI .getComponents ().getSchemas ().get ("Ancestor" );
77- assertEquals (schema3 .getExtensions ().get ("x-parent" ), true );
94+ assertEquals (schema3 .getExtensions ().get (X_PARENT ), true );
7895
7996 Schema schema4 = openAPI .getComponents ().getSchemas ().get ("Child" );
8097 assertNull (schema4 .getExtensions ());
0 commit comments