Skip to content

Commit df5a4b7

Browse files
Add test to swagger problem
2 parents 9360750 + 12a1dab commit df5a4b7

File tree

3 files changed

+120
-12
lines changed

3 files changed

+120
-12
lines changed

generator-core/src/test/java/org/apiaddicts/apitools/apigen/generatorcore/config/extractors/ConfigurationExtractorTest.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.apiaddicts.apitools.apigen.generatorcore.config.extractors;
22

33
import io.swagger.v3.oas.models.OpenAPI;
4+
import io.swagger.v3.oas.models.media.Schema;
45
import io.swagger.v3.parser.OpenAPIV3Parser;
56
import io.swagger.v3.parser.core.models.ParseOptions;
67
import org.apiaddicts.apitools.apigen.generatorcore.config.Configuration;
@@ -12,27 +13,18 @@
1213
import org.apiaddicts.apitools.apigen.generatorcore.config.validation.Validation;
1314
import org.apiaddicts.apitools.apigen.generatorcore.config.validation.ValidationType;
1415
import org.apiaddicts.apitools.apigen.generatorcore.spec.OpenAPIExtended;
15-
import org.junit.jupiter.api.BeforeAll;
1616
import org.junit.jupiter.api.Test;
1717

1818
import java.math.BigDecimal;
1919
import java.util.List;
20+
import java.util.Map;
2021

2122
import static org.apiaddicts.apitools.apigen.generatorcore.config.controller.Endpoint.Method.*;
2223
import static org.junit.jupiter.api.Assertions.*;
2324

2425
// TODO #14909 refactor tests to use individualized api fragments
2526
class 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
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: 0001_allOffProps
5+
6+
x-apigen-project:
7+
name: test
8+
description: test
9+
version: 1.0.0
10+
java-properties:
11+
group-id: the.test
12+
artifact-id: test
13+
14+
paths:
15+
/sample_resource:
16+
x-apigen-binding:
17+
model: ResOne
18+
post:
19+
operationId: createResOne
20+
requestBody:
21+
content:
22+
application/json:
23+
schema:
24+
$ref: "#/components/schemas/create_res_one"
25+
responses:
26+
'201':
27+
description: Ok
28+
content:
29+
application/json:
30+
schema:
31+
$ref: "#/components/schemas/standard_response_res_one"
32+
33+
components:
34+
schemas:
35+
standard_response_result:
36+
properties:
37+
result:
38+
type: object
39+
properties:
40+
status:
41+
type: boolean
42+
http_code:
43+
type: integer
44+
errors:
45+
type: array
46+
items:
47+
$ref: '#/components/schemas/standard_error'
48+
info:
49+
type: string
50+
trace_id:
51+
type: string
52+
num_elements:
53+
type: integer
54+
required:
55+
- status
56+
- http_code
57+
- trace_id
58+
59+
standard_error:
60+
type: object
61+
properties:
62+
code:
63+
type: integer
64+
message:
65+
type: string
66+
67+
standard_response_res_one:
68+
x-apigen-mapping:
69+
model: ResOne
70+
type: object
71+
allOf:
72+
- $ref: '#/components/schemas/standard_response_result'
73+
properties:
74+
data:
75+
properties:
76+
name:
77+
type: string
78+
79+
create_res_one:
80+
x-apigen-mapping:
81+
model: ResOne
82+
type: object
83+
properties:
84+
name:
85+
type: string
86+
87+
x-apigen-models:
88+
ResOne:
89+
relational-persistence:
90+
table: res_one
91+
attributes:
92+
- name: name
93+
type: String
94+
relational-persistence:
95+
column: id
96+
primary-key: true

generator-core/src/test/resources/api_fragments/standard_request.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: "3.0.0"
1+
openapi: "3.0.3"
22
info:
33
version: 1.0.0
44
title: standard_request
@@ -89,4 +89,4 @@ components:
8989
type: String
9090
relational-persistence:
9191
column: id
92-
primary-key: true
92+
primary-key: true

0 commit comments

Comments
 (0)