Skip to content

Commit bd87160

Browse files
author
Rudolf Brisuda
committed
NPE in JavaClientCodegen when having #/components/ prefixes #731
Signed-off-by: Rudolf Brisuda <[email protected]>
1 parent 50e6795 commit bd87160

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

src/main/java/io/swagger/codegen/v3/generators/java/JavaClientCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ protected List<Map<String, Object>> modelInheritanceSupportInGson(List<?> allMod
524524
List<Map<String, Object>> childrenList = new ArrayList<>();
525525
Map<String, Object> parent = new HashMap<>();
526526
parent.put("classname", parentModel.classname);
527-
List<CodegenModel> childrenModels = byParent.get(parentModel);
527+
List<CodegenModel> childrenModels = parentModelEntry.getValue();
528528
for (CodegenModel model : childrenModels) {
529529
Map<String, Object> child = new HashMap<>();
530530
child.put("name", model.name);

src/test/java/io/swagger/codegen/v3/generators/java/JavaModelTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,4 +1055,22 @@ public void generateModel() throws Exception {
10551055
folder.delete();
10561056
}
10571057

1058+
@Test
1059+
public void generateModelDiscriminatorOrderSchemas() throws Exception {
1060+
folder.create();
1061+
final File output = folder.getRoot();
1062+
1063+
final CodegenConfigurator configurator = new CodegenConfigurator()
1064+
.setLang("java")
1065+
.setInputSpecURL("src/test/resources/3_0_0/discriminator_order_schemas.yaml")
1066+
.setOutputDir(output.getAbsolutePath());
1067+
1068+
final ClientOptInput clientOptInput = configurator.toClientOptInput();
1069+
new DefaultGenerator().opts(clientOptInput).generate();
1070+
1071+
File orderFile = new File(output, "src/main/java/io/swagger/client/model/DSubSubSubBase.java");
1072+
Assert.assertTrue(orderFile.exists());
1073+
folder.delete();
1074+
}
1075+
10581076
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
openapi: 3.0.2
2+
info:
3+
title: OAI Specification example for NPE
4+
version: 1.0.0
5+
paths:
6+
/sampleObjectResponse:
7+
get:
8+
responses:
9+
'200':
10+
description: desc
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/A_Base'
15+
components:
16+
schemas:
17+
18+
A_Base:
19+
type: object
20+
properties:
21+
relations:
22+
type: string
23+
24+
B_Sub_Base:
25+
allOf:
26+
- "$ref": '#/components/schemas/A_Base'
27+
type: object
28+
required:
29+
- type
30+
properties:
31+
type:
32+
type: string
33+
discriminator:
34+
propertyName: type
35+
mapping:
36+
aPersonalProperty: '#/components/schemas/APersonalProperty'
37+
38+
C_Sub_Sub_Base:
39+
allOf:
40+
- "$ref": '#/components/schemas/B_Sub_Base'
41+
- required:
42+
- type
43+
type: object
44+
properties:
45+
type:
46+
type: string
47+
discriminator:
48+
propertyName: type
49+
mapping:
50+
motorVehicle: '#/components/schemas/D_Sub_Sub_Sub_Base'
51+
52+
D_Sub_Sub_Sub_Base:
53+
allOf:
54+
- "$ref": '#/components/schemas/C_Sub_Sub_Base'
55+
- type: object
56+
properties:
57+
bark:
58+
type: string

0 commit comments

Comments
 (0)