-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change of 'nullable' is not detected (#747)
Fixes #482
- Loading branch information
Showing
9 changed files
with
168 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedNullable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.openapitools.openapidiff.core.model.schema; | ||
|
||
import java.util.Objects; | ||
import org.openapitools.openapidiff.core.model.Changed; | ||
import org.openapitools.openapidiff.core.model.DiffResult; | ||
|
||
public class ChangedNullable implements Changed { | ||
|
||
private final Boolean left; | ||
private final Boolean right; | ||
|
||
public ChangedNullable(Boolean leftNullable, Boolean rightNullable) { | ||
this.left = leftNullable; | ||
this.right = rightNullable; | ||
} | ||
|
||
@Override | ||
public DiffResult isChanged() { | ||
boolean leftValue = left != null && left; | ||
boolean rightValue = right != null && right; | ||
|
||
if (leftValue != rightValue) { | ||
return DiffResult.COMPATIBLE; | ||
} | ||
|
||
return DiffResult.NO_CHANGES; | ||
} | ||
|
||
public Boolean getLeft() { | ||
return left; | ||
} | ||
|
||
public Boolean getRight() { | ||
return right; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ChangedNullable [left=" + left + ", right=" + right + "]"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ChangedNullable that = (ChangedNullable) o; | ||
return Objects.equals(left, that.getLeft()) && Objects.equals(right, that.getRight()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(left, right); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/src/test/resources/schemaDiff/schema-nullable-diff-1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
openapi: 3.0.1 | ||
info: | ||
description: Schema diff nullable | ||
title: schema diff nullable | ||
version: 1.0.0 | ||
paths: | ||
/schema/nullable: | ||
post: | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/TestDTO' | ||
components: | ||
schemas: | ||
TestDTO: | ||
type: object | ||
properties: | ||
field0: | ||
type: integer | ||
field1: | ||
type: integer | ||
nullable: true | ||
field2: | ||
type: integer | ||
nullable: true | ||
field3: | ||
type: integer |
28 changes: 28 additions & 0 deletions
28
core/src/test/resources/schemaDiff/schema-nullable-diff-2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
openapi: 3.0.1 | ||
info: | ||
description: Schema diff nullable | ||
title: schema diff nullable | ||
version: 1.0.0 | ||
paths: | ||
/schema/nullable: | ||
post: | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/TestDTO' | ||
components: | ||
schemas: | ||
TestDTO: | ||
type: object | ||
properties: | ||
field0: | ||
type: integer | ||
field1: | ||
type: integer | ||
nullable: false | ||
field2: | ||
type: integer | ||
field3: | ||
type: integer | ||
nullable: true |