Skip to content

Commit a3b36f7

Browse files
peyerrogerjimschubert
authored andcommitted
Include testcase for issue 3248
1 parent 27ae0a6 commit a3b36f7

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,37 @@ public void shouldGenerateRequestParamForRefParams_3248_RegressionDates() throws
216216
"@RequestParam(value = \"start\"");
217217
}
218218

219+
@Test
220+
public void doGenerateRequestParamForSimpleParam() throws IOException {
221+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
222+
output.deleteOnExit();
223+
String outputPath = output.getAbsolutePath().replace('\\', '/');
224+
225+
OpenAPI openAPI = new OpenAPIParser()
226+
.readLocation("src/test/resources/3_0/issue_3248.yaml", null, new ParseOptions()).getOpenAPI();
227+
228+
SpringCodegen codegen = new SpringCodegen();
229+
codegen.setOutputDir(output.getAbsolutePath());
230+
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
231+
232+
ClientOptInput input = new ClientOptInput();
233+
input.openAPI(openAPI);
234+
input.config(codegen);
235+
236+
MockDefaultGenerator generator = new MockDefaultGenerator();
237+
generator.opts(input).generate();
238+
239+
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/MonkeysApi.java", "@RequestParam");
240+
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/ElephantsApi.java", "@RequestParam");
241+
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/ZebrasApi.java", "@RequestParam");
242+
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/BearsApi.java", "@RequestParam");
243+
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/CamelsApi.java", "@RequestParam");
244+
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/PandasApi.java", "@RequestParam");
245+
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/CrocodilesApi.java", "@RequestParam");
246+
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/PolarBearsApi.java", "@RequestParam");
247+
248+
}
249+
219250
private void checkFileNotContains(MockDefaultGenerator generator, String path, String... lines) {
220251
String file = generator.getFiles().get(path);
221252
assertNotNull(file);
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
openapi: 3.0.0
2+
servers:
3+
- url: 'localhost:8080'
4+
info:
5+
version: 1.0.0
6+
title: OpenAPI Zoo
7+
license:
8+
name: Apache-2.0
9+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
10+
paths:
11+
/monkeys:
12+
get:
13+
operationId: getMonkeys
14+
parameters:
15+
- $ref: '#/components/parameters/refDate'
16+
/elephants:
17+
get:
18+
operationId: getElephants
19+
parameters:
20+
- in: query
21+
name: someDate
22+
required: true
23+
schema:
24+
type: string
25+
format: date
26+
/girafes:
27+
get:
28+
operationId: getGirafes
29+
parameters:
30+
- $ref: '#/components/parameters/refStatus'
31+
/zebras:
32+
get:
33+
operationId: getZebras
34+
parameters:
35+
- in: query
36+
name: status
37+
required: true
38+
schema:
39+
type: integer
40+
enum: [0,1]
41+
default: 0
42+
/bears:
43+
get:
44+
operationId: getBears
45+
parameters:
46+
- $ref: '#/components/parameters/refCondition'
47+
/camels:
48+
get:
49+
operationId: getCamels
50+
parameters:
51+
- in: query
52+
name: condition
53+
required: true
54+
schema:
55+
type: string
56+
enum:
57+
- sleeping
58+
- awake
59+
/pandas:
60+
get:
61+
operationId: getPandas
62+
parameters:
63+
- $ref: '#/components/parameters/refName'
64+
/crocodiles:
65+
get:
66+
operationId: getCrocodiles
67+
parameters:
68+
- in: query
69+
name: name
70+
required: true
71+
schema:
72+
type: string
73+
/polarBears:
74+
get:
75+
operationId: getPolarBears
76+
parameters:
77+
- $ref: '#/components/parameters/refAge'
78+
/birds:
79+
get:
80+
operationId: getBirds
81+
parameters:
82+
- in: query
83+
name: age
84+
required: true
85+
schema:
86+
type: integer
87+
components:
88+
parameters:
89+
refDate:
90+
in: query
91+
name: refDate
92+
required: true
93+
schema:
94+
type: string
95+
format: date
96+
refStatus:
97+
in: query
98+
name: refStatus
99+
required: true
100+
schema:
101+
type: integer
102+
enum: [0,1]
103+
default: 0
104+
refCondition:
105+
in: query
106+
name: refCondition
107+
schema:
108+
type: string
109+
enum:
110+
- sleeping
111+
- awake
112+
refName:
113+
in: query
114+
name: refName
115+
schema:
116+
type: string
117+
refAge:
118+
in: query
119+
name: refAge
120+
schema:
121+
type: integer

0 commit comments

Comments
 (0)