Skip to content

Fix NullPointerException with oneOf discriminator change #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public Optional<ChangedSchema> diff(HashSet<String> refSet, Components leftCompo
changedSchema.setOldSchema(left);
changedSchema.setNewSchema(right);
changedSchema.setDiscriminatorPropertyChanged(true);
changedSchema.setContext(context);
return Optional.of(changedSchema);
}

Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/qdesrame/openapi/test/OneOfDiffTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class OneOfDiffTest {
private final String OPENAPI_DOC3 = "oneOf_diff_3.yaml";
private final String OPENAPI_DOC4 = "composed_schema_1.yaml";
private final String OPENAPI_DOC5 = "composed_schema_2.yaml";
private final String OPENAPI_DOC6 = "oneOf_discriminator-changed_1.yaml";
private final String OPENAPI_DOC7 = "oneOf_discriminator-changed_2.yaml";

@Test
public void testDiffSame() {
Expand All @@ -37,4 +39,10 @@ public void testComposedSchema() {
assertOpenApiBackwardIncompatible(OPENAPI_DOC4, OPENAPI_DOC5);
}

@Test
public void testOneOfDiscrimitatorChanged() {
//The oneOf 'discriminator' changed: 'realtype' -> 'othertype':
assertOpenApiBackwardIncompatible(OPENAPI_DOC6, OPENAPI_DOC7);
}

}
49 changes: 49 additions & 0 deletions src/test/resources/oneOf_discriminator-changed_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
openapi: 3.0.1
info:
title: oneOf test for issue 29
version: '1.0'
servers:
- url: 'http://localhost:8000/'
paths:
/state:
post:
operationId: update
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/A'
- $ref: '#/components/schemas/B'
discriminator:
propertyName: realtype
mapping:
a-type: '#/components/schemas/A'
b-type: '#/components/schemas/B'
required: true
responses:
'201':
description: OK
components:
schemas:
A:
type: object
properties:
realtype:
type: string
othertype:
type: string
message:
type: string
B:
type: object
properties:
realtype:
type: string
othertype:
type: string
description:
type: string
code:
type: integer
format: int32
49 changes: 49 additions & 0 deletions src/test/resources/oneOf_discriminator-changed_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
openapi: 3.0.1
info:
title: oneOf test for issue 29
version: '1.0'
servers:
- url: 'http://localhost:8000/'
paths:
/state:
post:
operationId: update
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/A'
- $ref: '#/components/schemas/B'
discriminator:
propertyName: othertype
mapping:
a-type: '#/components/schemas/A'
b-type: '#/components/schemas/B'
required: true
responses:
'201':
description: OK
components:
schemas:
A:
type: object
properties:
realtype:
type: string
othertype:
type: string
message:
type: string
B:
type: object
properties:
realtype:
type: string
othertype:
type: string
description:
type: string
code:
type: integer
format: int32