Skip to content

Commit 4ebff86

Browse files
authored
Merge pull request OpenAPITools#49 from jmini/patch-4
Fix NullPointerException with oneOf discriminator change
2 parents 9d85697 + 65488aa commit 4ebff86

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

src/main/java/com/qdesrame/openapi/diff/compare/schemadiffresult/ComposedSchemaDiffResult.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public Optional<ChangedSchema> diff(HashSet<String> refSet, Components leftCompo
4646
changedSchema.setOldSchema(left);
4747
changedSchema.setNewSchema(right);
4848
changedSchema.setDiscriminatorPropertyChanged(true);
49+
changedSchema.setContext(context);
4950
return Optional.of(changedSchema);
5051
}
5152

src/test/java/com/qdesrame/openapi/test/OneOfDiffTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class OneOfDiffTest {
1616
private final String OPENAPI_DOC3 = "oneOf_diff_3.yaml";
1717
private final String OPENAPI_DOC4 = "composed_schema_1.yaml";
1818
private final String OPENAPI_DOC5 = "composed_schema_2.yaml";
19+
private final String OPENAPI_DOC6 = "oneOf_discriminator-changed_1.yaml";
20+
private final String OPENAPI_DOC7 = "oneOf_discriminator-changed_2.yaml";
1921

2022
@Test
2123
public void testDiffSame() {
@@ -37,4 +39,10 @@ public void testComposedSchema() {
3739
assertOpenApiBackwardIncompatible(OPENAPI_DOC4, OPENAPI_DOC5);
3840
}
3941

42+
@Test
43+
public void testOneOfDiscrimitatorChanged() {
44+
//The oneOf 'discriminator' changed: 'realtype' -> 'othertype':
45+
assertOpenApiBackwardIncompatible(OPENAPI_DOC6, OPENAPI_DOC7);
46+
}
47+
4048
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
openapi: 3.0.1
2+
info:
3+
title: oneOf test for issue 29
4+
version: '1.0'
5+
servers:
6+
- url: 'http://localhost:8000/'
7+
paths:
8+
/state:
9+
post:
10+
operationId: update
11+
requestBody:
12+
content:
13+
application/json:
14+
schema:
15+
oneOf:
16+
- $ref: '#/components/schemas/A'
17+
- $ref: '#/components/schemas/B'
18+
discriminator:
19+
propertyName: realtype
20+
mapping:
21+
a-type: '#/components/schemas/A'
22+
b-type: '#/components/schemas/B'
23+
required: true
24+
responses:
25+
'201':
26+
description: OK
27+
components:
28+
schemas:
29+
A:
30+
type: object
31+
properties:
32+
realtype:
33+
type: string
34+
othertype:
35+
type: string
36+
message:
37+
type: string
38+
B:
39+
type: object
40+
properties:
41+
realtype:
42+
type: string
43+
othertype:
44+
type: string
45+
description:
46+
type: string
47+
code:
48+
type: integer
49+
format: int32
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
openapi: 3.0.1
2+
info:
3+
title: oneOf test for issue 29
4+
version: '1.0'
5+
servers:
6+
- url: 'http://localhost:8000/'
7+
paths:
8+
/state:
9+
post:
10+
operationId: update
11+
requestBody:
12+
content:
13+
application/json:
14+
schema:
15+
oneOf:
16+
- $ref: '#/components/schemas/A'
17+
- $ref: '#/components/schemas/B'
18+
discriminator:
19+
propertyName: othertype
20+
mapping:
21+
a-type: '#/components/schemas/A'
22+
b-type: '#/components/schemas/B'
23+
required: true
24+
responses:
25+
'201':
26+
description: OK
27+
components:
28+
schemas:
29+
A:
30+
type: object
31+
properties:
32+
realtype:
33+
type: string
34+
othertype:
35+
type: string
36+
message:
37+
type: string
38+
B:
39+
type: object
40+
properties:
41+
realtype:
42+
type: string
43+
othertype:
44+
type: string
45+
description:
46+
type: string
47+
code:
48+
type: integer
49+
format: int32

0 commit comments

Comments
 (0)