-
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.
- Loading branch information
Showing
19 changed files
with
1,054 additions
and
22 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
40 changes: 40 additions & 0 deletions
40
core/src/main/java/org/openapitools/openapidiff/core/compare/MediaTypeDiff.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,40 @@ | ||
package org.openapitools.openapidiff.core.compare; | ||
|
||
import static org.openapitools.openapidiff.core.utils.ChangedUtils.isChanged; | ||
|
||
import io.swagger.v3.oas.models.media.MediaType; | ||
import org.openapitools.openapidiff.core.model.Changed; | ||
import org.openapitools.openapidiff.core.model.ChangedExample; | ||
import org.openapitools.openapidiff.core.model.ChangedExamples; | ||
import org.openapitools.openapidiff.core.model.ChangedMediaType; | ||
import org.openapitools.openapidiff.core.model.DiffContext; | ||
import org.openapitools.openapidiff.core.model.deferred.DeferredBuilder; | ||
import org.openapitools.openapidiff.core.model.deferred.DeferredChanged; | ||
|
||
public class MediaTypeDiff { | ||
|
||
private final OpenApiDiff openApiDiff; | ||
|
||
public MediaTypeDiff(OpenApiDiff openApiDiff) { | ||
this.openApiDiff = openApiDiff; | ||
} | ||
|
||
public DeferredChanged<ChangedMediaType> diff( | ||
MediaType left, MediaType right, DiffContext context) { | ||
DeferredBuilder<Changed> builder = new DeferredBuilder<>(); | ||
|
||
ChangedMediaType changedMediaType = | ||
new ChangedMediaType(left.getSchema(), right.getSchema(), context) | ||
.setExample(new ChangedExample(left.getExample(), right.getExample())) | ||
.setExamples(new ChangedExamples(left.getExamples(), right.getExamples())); | ||
|
||
builder | ||
.with( | ||
openApiDiff | ||
.getSchemaDiff() | ||
.diff(left.getSchema(), right.getSchema(), context.copyWithRequired(true))) | ||
.ifPresent(changedMediaType::setSchema); | ||
|
||
return builder.build().mapOptional(value -> isChanged(changedMediaType)); | ||
} | ||
} |
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
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
66 changes: 66 additions & 0 deletions
66
core/src/main/java/org/openapitools/openapidiff/core/model/ChangedExample.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,66 @@ | ||
package org.openapitools.openapidiff.core.model; | ||
|
||
import java.util.Objects; | ||
|
||
public class ChangedExample implements Changed { | ||
|
||
private Object leftExample; | ||
private Object rightExample; | ||
|
||
public ChangedExample(Object leftExample, Object rightExample) { | ||
this.leftExample = leftExample; | ||
this.rightExample = rightExample; | ||
} | ||
|
||
public Object getLeftExample() { | ||
return leftExample; | ||
} | ||
|
||
public void setLeftExample(Object leftExample) { | ||
this.leftExample = leftExample; | ||
} | ||
|
||
public Object getRightExample() { | ||
return rightExample; | ||
} | ||
|
||
public void setRightExample(Object rightExample) { | ||
this.rightExample = rightExample; | ||
} | ||
|
||
@Override | ||
public DiffResult isChanged() { | ||
if (!Objects.equals(leftExample, rightExample)) { | ||
return DiffResult.METADATA; | ||
} | ||
return DiffResult.NO_CHANGES; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) { | ||
return true; | ||
} | ||
if (object == null || getClass() != object.getClass()) { | ||
return false; | ||
} | ||
ChangedExample that = (ChangedExample) object; | ||
return Objects.equals(leftExample, that.leftExample) | ||
&& Objects.equals(rightExample, that.rightExample); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(leftExample, rightExample); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ChangedExample{" | ||
+ "leftExample=" | ||
+ leftExample | ||
+ ", rightExample=" | ||
+ rightExample | ||
+ '}'; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
core/src/main/java/org/openapitools/openapidiff/core/model/ChangedExamples.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,66 @@ | ||
package org.openapitools.openapidiff.core.model; | ||
|
||
import java.util.Objects; | ||
|
||
public class ChangedExamples implements Changed { | ||
|
||
private Object leftExamples; | ||
private Object rightExamples; | ||
|
||
public ChangedExamples(Object leftExamples, Object rightExamples) { | ||
this.leftExamples = leftExamples; | ||
this.rightExamples = rightExamples; | ||
} | ||
|
||
public Object getLeftExamples() { | ||
return leftExamples; | ||
} | ||
|
||
public void setLeftExamples(Object leftExamples) { | ||
this.leftExamples = leftExamples; | ||
} | ||
|
||
public Object getRightExamples() { | ||
return rightExamples; | ||
} | ||
|
||
public void setRightExamples(Object rightExamples) { | ||
this.rightExamples = rightExamples; | ||
} | ||
|
||
@Override | ||
public DiffResult isChanged() { | ||
if (!Objects.equals(leftExamples, rightExamples)) { | ||
return DiffResult.METADATA; | ||
} | ||
return DiffResult.NO_CHANGES; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) { | ||
return true; | ||
} | ||
if (object == null || getClass() != object.getClass()) { | ||
return false; | ||
} | ||
ChangedExamples that = (ChangedExamples) object; | ||
return Objects.equals(leftExamples, that.leftExamples) | ||
&& Objects.equals(rightExamples, that.rightExamples); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(leftExamples, rightExamples); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ChangedExamples{" | ||
+ ", leftExamples=" | ||
+ leftExamples | ||
+ ", rightExamples=" | ||
+ rightExamples | ||
+ '}'; | ||
} | ||
} |
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
Oops, something went wrong.