Skip to content

Commit cb92534

Browse files
committed
[Java] add okhttp template test and regenerate sample
1 parent 5ac583c commit cb92534

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,4 +3178,32 @@ public void testQueryParamsExploded_whenQueryParamIsNull() throws IOException {
31783178
Path petApi = Paths.get(output + "/src/main/java/xyz/abcdef/api/DepartmentApi.java");
31793179
TestUtils.assertFileContains(petApi, "if (filter != null) {");
31803180
}
3181+
3182+
@Test
3183+
public void testRequiredAndNullableAreBothTrue() throws IOException {
3184+
File output = Files.createTempDirectory("test").toFile();
3185+
output.deleteOnExit();
3186+
3187+
final CodegenConfigurator configurator = new CodegenConfigurator()
3188+
.setGeneratorName("java")
3189+
.setLibrary(JavaClientCodegen.OKHTTP_GSON)
3190+
.setInputSpec("src/test/resources/bugs/issue_18516.yaml")
3191+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
3192+
3193+
3194+
DefaultGenerator generator = new DefaultGenerator();
3195+
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
3196+
files.forEach(File::deleteOnExit);
3197+
3198+
validateJavaSourceFiles(files);
3199+
3200+
Path modelFile = Paths.get(output + "/src/main/java/org/openapitools/client/model/SomeObject.java");
3201+
TestUtils.assertFileContains(
3202+
modelFile,
3203+
"} else if (!jsonObj.get(\"ids\").isJsonArray() && !jsonObj.get(\"ids\").isJsonNull()) {",
3204+
"if (!jsonObj.get(\"users\").isJsonArray() && !jsonObj.get(\"users\").isJsonNull()) {",
3205+
"if (jsonObj.get(\"user\") != null && !jsonObj.get(\"user\").isJsonNull()) {",
3206+
"if (jsonObj.get(\"role\") != null && !jsonObj.get(\"role\").isJsonNull()) {",
3207+
"if (jsonObj.get(\"custom\") != null && !jsonObj.get(\"custom\").isJsonNull()) {");
3208+
}
31813209
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
description: Test API
5+
version: 1.0.1
6+
7+
paths:
8+
/test:
9+
get:
10+
responses:
11+
200:
12+
description: Valid response
13+
content:
14+
application/json:
15+
schema:
16+
$ref: "#/components/schemas/SomeObject"
17+
18+
components:
19+
schemas:
20+
SomeObject:
21+
type: object
22+
required:
23+
- ids
24+
- users
25+
- user
26+
- role
27+
- custom
28+
properties:
29+
ids:
30+
type: array
31+
nullable: true
32+
items:
33+
type: integer
34+
users:
35+
type: array
36+
nullable: true
37+
items:
38+
type: object
39+
properties:
40+
id:
41+
type: string
42+
user:
43+
type: object
44+
nullable: true
45+
properties:
46+
id:
47+
type: string
48+
role:
49+
type: string
50+
nullable: true
51+
enum:
52+
- admin
53+
- tenant
54+
custom:
55+
$ref: "#/components/schemas/customEnum"
56+
customEnum:
57+
type: string
58+
nullable: true
59+
enum:
60+
- custom
61+

0 commit comments

Comments
 (0)