Repository navigation
Fix #357: ignore changes inside readOnly properties in requests #934
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
Open
Inf1mum
wants to merge
2
commits into
OpenAPITools:master
Choose a base branch
from
Inf1mum:fix/357-readonly-requestbody-schema
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
104 changes: 104 additions & 0 deletions
104
core/src/test/java/org/openapitools/openapidiff/core/Issue357Test.java
This file contains hidden or 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,104 @@ | ||
| package org.openapitools.openapidiff.core; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.openapitools.openapidiff.core.model.ChangedOpenApi; | ||
| import org.openapitools.openapidiff.core.model.ChangedSchema; | ||
|
|
||
| public class Issue357Test { | ||
|
|
||
| private final String READONLY_REQUEST_OLD = "issue-357_1.json"; | ||
| private final String READONLY_REQUEST_NEW = "issue-357_2.json"; | ||
| private final String WRITEONLY_RESPONSE_OLD = "issue-357-writeonly-response_1.json"; | ||
| private final String WRITEONLY_RESPONSE_NEW = "issue-357-writeonly-response_2.json"; | ||
| private final String READONLY_RESPONSE_OLD = "issue-357-readonly-response_1.json"; | ||
| private final String READONLY_RESPONSE_NEW = "issue-357-readonly-response_2.json"; | ||
| private final String READONLY_REQUIRED_OLD = "issue-357-readonly-required_1.json"; | ||
| private final String READONLY_REQUIRED_NEW = "issue-357-readonly-required_2.json"; | ||
| private final String READONLY_REF_OLD = "issue-357-readonly-ref_1.json"; | ||
| private final String READONLY_REF_NEW = "issue-357-readonly-ref_2.json"; | ||
| private final String READONLY_TRANSITION_OFF_OLD = "issue-357-readonly-transition-off_1.json"; | ||
| private final String READONLY_TRANSITION_OFF_NEW = "issue-357-readonly-transition-off_2.json"; | ||
| private final String READONLY_TRANSITION_ON_OLD = "issue-357-readonly-transition-on_1.json"; | ||
| private final String READONLY_TRANSITION_ON_NEW = "issue-357-readonly-transition-on_2.json"; | ||
|
|
||
| @Test // issue #357 | ||
| public void changesInsideReadOnlyPropertyInRequestAreIgnored() { | ||
| ChangedOpenApi changedOpenApi = | ||
| OpenApiCompare.fromLocations(READONLY_REQUEST_OLD, READONLY_REQUEST_NEW); | ||
|
|
||
| assertThat(changedOpenApi.getChangedOperations()).isEmpty(); | ||
| assertThat(changedOpenApi.getChangedSchemas()).isEmpty(); | ||
| assertThat(changedOpenApi.isUnchanged()).isTrue(); | ||
| } | ||
|
|
||
| @Test // changes to the parent `required` list of a skipped readOnly property are ignored too | ||
| public void requiredChangeForReadOnlyPropertyInRequestIsIgnored() { | ||
| ChangedOpenApi changedOpenApi = | ||
| OpenApiCompare.fromLocations(READONLY_REQUIRED_OLD, READONLY_REQUIRED_NEW); | ||
|
|
||
| assertThat(changedOpenApi.getChangedOperations()).isEmpty(); | ||
| assertThat(changedOpenApi.getChangedSchemas()).isEmpty(); | ||
| assertThat(changedOpenApi.isUnchanged()).isTrue(); | ||
| } | ||
|
|
||
| @Test // a property referenced via `$ref` that resolves to a readOnly schema is ignored too, | ||
| // including parent `required` changes for the referenced property | ||
| public void changesInsideReferencedReadOnlyPropertyInRequestAreIgnored() { | ||
| ChangedOpenApi changedOpenApi = | ||
| OpenApiCompare.fromLocations(READONLY_REF_OLD, READONLY_REF_NEW); | ||
|
|
||
| assertThat(changedOpenApi.getChangedOperations()).isEmpty(); | ||
| assertThat(changedOpenApi.getChangedSchemas()).isEmpty(); | ||
| assertThat(changedOpenApi.isUnchanged()).isTrue(); | ||
| } | ||
|
|
||
| @Test // readOnly true -> false: the flag change is a real wire change and must be reported | ||
| public void readOnlyFlagRemovedInRequestStillReportsNestedChanges() { | ||
| ChangedOpenApi changedOpenApi = | ||
| OpenApiCompare.fromLocations(READONLY_TRANSITION_OFF_OLD, READONLY_TRANSITION_OFF_NEW); | ||
|
|
||
| assertThat(changedOpenApi.getChangedSchemas()).isNotEmpty(); | ||
| assertThat(changedOpenApi.isChanged().isDifferent()).isTrue(); | ||
| assertThat(changedOpenApi.isIncompatible()).isTrue(); | ||
| assertThat(anyNestedTypeChange(changedOpenApi)).isTrue(); | ||
| } | ||
|
|
||
| @Test // readOnly false -> true: the flag change is a real wire change and must be reported | ||
| public void readOnlyFlagAddedInRequestStillReportsNestedChanges() { | ||
| ChangedOpenApi changedOpenApi = | ||
| OpenApiCompare.fromLocations(READONLY_TRANSITION_ON_OLD, READONLY_TRANSITION_ON_NEW); | ||
|
|
||
| assertThat(changedOpenApi.getChangedSchemas()).isNotEmpty(); | ||
| assertThat(changedOpenApi.isChanged().isDifferent()).isTrue(); | ||
| assertThat(changedOpenApi.isIncompatible()).isTrue(); | ||
| assertThat(anyNestedTypeChange(changedOpenApi)).isTrue(); | ||
| } | ||
|
|
||
| private static boolean anyNestedTypeChange(ChangedOpenApi changedOpenApi) { | ||
| return changedOpenApi.getChangedSchemas().stream() | ||
| .flatMap(changedSchema -> changedSchema.getChangedProperties().values().stream()) | ||
| .anyMatch(ChangedSchema::isChangedType); | ||
| } | ||
|
|
||
| @Test // counter-case: writeOnly in a response is still reported | ||
| public void changesInsideWriteOnlyPropertyInResponseAreStillReported() { | ||
| ChangedOpenApi changedOpenApi = | ||
| OpenApiCompare.fromLocations(WRITEONLY_RESPONSE_OLD, WRITEONLY_RESPONSE_NEW); | ||
|
|
||
| assertThat(changedOpenApi.getChangedSchemas()).isNotEmpty(); | ||
| assertThat(changedOpenApi.isChanged().isDifferent()).isTrue(); | ||
| assertThat(changedOpenApi.isIncompatible()).isTrue(); | ||
| } | ||
|
|
||
| @Test // response-side behavior must stay unchanged: readOnly in a response is still reported | ||
| public void changesInsideReadOnlyPropertyInResponseAreStillReported() { | ||
| ChangedOpenApi changedOpenApi = | ||
| OpenApiCompare.fromLocations(READONLY_RESPONSE_OLD, READONLY_RESPONSE_NEW); | ||
|
|
||
| assertThat(changedOpenApi.getChangedOperations()).isNotEmpty(); | ||
| assertThat(changedOpenApi.isChanged().isDifferent()).isTrue(); | ||
| assertThat(changedOpenApi.isIncompatible()).isTrue(); | ||
| } | ||
| } | ||
This file contains hidden or 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,68 @@ | ||
| { | ||
| "openapi": "3.0.0", | ||
| "info": { | ||
| "title": "API", | ||
| "version": "0.1.0" | ||
| }, | ||
| "paths": { | ||
| "/resource": { | ||
| "post": { | ||
| "responses": { | ||
| "200": { | ||
| "description": "Created resource", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/CreateResourceResponse" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "summary": "Create resource", | ||
| "requestBody": { | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/CreateResourceRequest" | ||
| } | ||
| } | ||
| }, | ||
| "description": "Definition of the resource" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "components": { | ||
| "schemas": { | ||
| "CreateResourceResponse": { | ||
| "type": "object", | ||
| "properties": { | ||
| "resources": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "CreateResourceRequest": { | ||
| "type": "object", | ||
| "properties": { | ||
| "foo": { | ||
| "$ref": "#/components/schemas/Foo" | ||
| } | ||
| } | ||
| }, | ||
| "Foo": { | ||
| "type": "object", | ||
| "readOnly": true, | ||
| "properties": { | ||
| "bar": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,69 @@ | ||
| { | ||
| "openapi": "3.0.0", | ||
| "info": { | ||
| "title": "API", | ||
| "version": "0.1.0" | ||
| }, | ||
| "paths": { | ||
| "/resource": { | ||
| "post": { | ||
| "responses": { | ||
| "200": { | ||
| "description": "Created resource", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/CreateResourceResponse" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "summary": "Create resource", | ||
| "requestBody": { | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/CreateResourceRequest" | ||
| } | ||
| } | ||
| }, | ||
| "description": "Definition of the resource" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "components": { | ||
| "schemas": { | ||
| "CreateResourceResponse": { | ||
| "type": "object", | ||
| "properties": { | ||
| "resources": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "CreateResourceRequest": { | ||
| "type": "object", | ||
| "required": ["foo"], | ||
| "properties": { | ||
| "foo": { | ||
| "$ref": "#/components/schemas/Foo" | ||
| } | ||
| } | ||
| }, | ||
| "Foo": { | ||
| "type": "object", | ||
| "readOnly": true, | ||
| "properties": { | ||
| "bar": { | ||
| "type": "integer" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
core/src/test/resources/issue-357-readonly-required_1.json
This file contains hidden or 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,79 @@ | ||
| { | ||
| "openapi": "3.0.0", | ||
| "info": { | ||
| "title": "API", | ||
| "version": "0.1.0" | ||
| }, | ||
| "paths": { | ||
| "/resource": { | ||
| "post": { | ||
| "responses": { | ||
| "200": { | ||
| "description": "Created resource", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/CreateResourceResponse" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "summary": "Create resource", | ||
| "requestBody": { | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/CreateResourceRequest" | ||
| } | ||
| } | ||
| }, | ||
| "description": "Definition of the resource" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "components": { | ||
| "schemas": { | ||
| "CreateResourceResponse": { | ||
| "type": "object", | ||
| "properties": { | ||
| "resources": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "CreateResourceRequest": { | ||
| "type": "object", | ||
| "properties": { | ||
| "foo": { | ||
| "$ref": "#/components/schemas/Foo" | ||
| } | ||
| } | ||
| }, | ||
| "Foo": { | ||
| "type": "object", | ||
| "properties": { | ||
| "bar": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/components/schemas/Bar" | ||
| }, | ||
| "readOnly": true | ||
| } | ||
| } | ||
| }, | ||
| "Bar": { | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.