11package org .apiaddicts .apitools .apigen .generatorcore .config .extractors ;
22
33import io .swagger .v3 .oas .models .OpenAPI ;
4+ import io .swagger .v3 .oas .models .media .Schema ;
45import io .swagger .v3 .parser .OpenAPIV3Parser ;
56import io .swagger .v3 .parser .core .models .ParseOptions ;
67import org .apiaddicts .apitools .apigen .generatorcore .config .Configuration ;
1213import org .apiaddicts .apitools .apigen .generatorcore .config .validation .Validation ;
1314import org .apiaddicts .apitools .apigen .generatorcore .config .validation .ValidationType ;
1415import org .apiaddicts .apitools .apigen .generatorcore .spec .OpenAPIExtended ;
15- import org .junit .jupiter .api .BeforeAll ;
1616import org .junit .jupiter .api .Test ;
1717
1818import java .math .BigDecimal ;
1919import java .util .List ;
20+ import java .util .Map ;
2021
2122import static org .apiaddicts .apitools .apigen .generatorcore .config .controller .Endpoint .Method .*;
2223import static org .junit .jupiter .api .Assertions .*;
2324
2425// TODO #14909 refactor tests to use individualized api fragments
2526class ConfigurationExtractorTest {
2627
27- private static Configuration configuration ;
28-
29- @ BeforeAll
30- static void prepareTest () {
31- OpenAPIExtended openAPIExtended = load ("testApi.yaml" );
32- configuration = new ConfigurationExtractor (openAPIExtended ).extract ();
33- assertNotNull (configuration );
34- }
35-
3628 private static OpenAPIExtended load (String fileName ) {
3729 ParseOptions parseOptions = new ParseOptions ();
3830 parseOptions .setResolveFully (true );
@@ -42,6 +34,8 @@ private static OpenAPIExtended load(String fileName) {
4234
4335 @ Test
4436 void checkExtractedProjectInfoFromYAML () {
37+ OpenAPIExtended openAPIExtended = load ("testApi.yaml" );
38+ Configuration configuration = new ConfigurationExtractor (openAPIExtended ).extract ();
4539 assertEquals (configuration .getName (), "test" );
4640 assertEquals (configuration .getDescription (), "test" );
4741 assertEquals ("the.test" , configuration .getGroup ());
@@ -51,6 +45,8 @@ void checkExtractedProjectInfoFromYAML() {
5145
5246 @ Test
5347 void checkExtractedEntitiesFromYAML () {
48+ OpenAPIExtended openAPIExtended = load ("testApi.yaml" );
49+ Configuration configuration = new ConfigurationExtractor (openAPIExtended ).extract ();
5450 assertNotNull (configuration .getEntities ());
5551
5652 List <Entity > entities = configuration .getEntities ();
@@ -105,6 +101,8 @@ void checkExtractedEntitiesFromYAML() {
105101
106102 @ Test
107103 void checkExtractedValidationsFromYAMLModels () {
104+ OpenAPIExtended openAPIExtended = load ("testApi.yaml" );
105+ Configuration configuration = new ConfigurationExtractor (openAPIExtended ).extract ();
108106 assertNotNull (configuration .getEntities ());
109107
110108 List <Validation > validations = configuration .getEntities ().get (0 ).getAttributes ().get (0 ).getValidations ();
@@ -160,12 +158,16 @@ void checkExtractedValidationsFromYAMLModels() {
160158
161159 @ Test
162160 void checkExtractedValidationsFromYAMLResources () {
161+ OpenAPIExtended openAPIExtended = load ("testApi.yaml" );
162+ Configuration configuration = new ConfigurationExtractor (openAPIExtended ).extract ();
163163 List <Validation > validations = configuration .getControllers ().get (0 ).getEndpoints ().get (0 ).getRequest ().getAttributes ().get (0 ).getValidations ();
164164 assertEquals (ValidationType .NOT_NULL , validations .get (0 ).getType (), "Check NotNull Validation" );
165165 }
166166
167167 @ Test
168168 void checkExtractedControllersFromYAML () {
169+ OpenAPIExtended openAPIExtended = load ("testApi.yaml" );
170+ Configuration configuration = new ConfigurationExtractor (openAPIExtended ).extract ();
169171 assertNotNull (configuration .getControllers ());
170172
171173 List <Controller > controllers = configuration .getControllers ();
@@ -199,6 +201,8 @@ void checkExtractedControllersFromYAML() {
199201
200202 @ Test
201203 void checkExtractedEndpointsParametersFromYAML () {
204+ OpenAPIExtended openAPIExtended = load ("testApi.yaml" );
205+ Configuration configuration = new ConfigurationExtractor (openAPIExtended ).extract ();
202206 assertNotNull (configuration .getControllers ());
203207 Controller controller = configuration .getControllers ().get (0 );
204208
@@ -273,4 +277,12 @@ private void checkBooleanParameter(Parameter parameter) {
273277 assertEquals ("boolean" , parameter .getType (), "Check Endpoint BooleanParameter type" );
274278 }
275279
280+ @ Test
281+ void allOfWithProperties () {
282+ OpenAPIExtended openAPIExtended = load ("0001_allOffProps.yaml" );
283+ Schema <?> schema = openAPIExtended .getSchemas ().get ("standard_response_res_one" );
284+ Map <String , Schema > props = schema .getProperties ();
285+ assertTrue (props .containsKey ("data" ), "'data' property expected" );
286+ assertTrue (props .containsKey ("result" ), "'result' property expected" );
287+ }
276288}
0 commit comments