Skip to content

Fix Issue #136 new read-only property breaks PUT #137

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
Aug 27, 2020
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
12 changes: 10 additions & 2 deletions src/main/java/com/qdesrame/openapi/diff/model/ChangedSchema.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.qdesrame.openapi.diff.model;

import com.qdesrame.openapi.diff.model.schema.*;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.media.Schema;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -76,15 +77,22 @@ public DiffResult isCoreChanged() {
&& !discriminatorPropertyChanged) {
return DiffResult.NO_CHANGES;
}
boolean compatibleForRequest = (oldSchema != null || newSchema == null);
boolean compatibleForResponse =
missingProperties.isEmpty() && (oldSchema == null || newSchema != null);
if ((context.isRequest() && compatibleForRequest
if ((context.isRequest() && compatibleForRequest()
|| context.isResponse() && compatibleForResponse)
&& !changedType
&& !discriminatorPropertyChanged) {
return DiffResult.COMPATIBLE;
}
return DiffResult.INCOMPATIBLE;
}

private boolean compatibleForRequest() {
if (PathItem.HttpMethod.PUT.equals(context.getMethod())) {
if (increasedProperties.size() > 0) return false;
}

return (oldSchema != null || newSchema == null);
}
}
22 changes: 22 additions & 0 deletions src/test/java/com/qdesrame/openapi/test/AddPropPutDiffTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.qdesrame.openapi.test;

import static com.qdesrame.openapi.test.TestUtils.assertOpenApiAreEquals;
import static com.qdesrame.openapi.test.TestUtils.assertOpenApiBackwardIncompatible;

import org.junit.jupiter.api.Test;

/** Created by trohrberg on 23/03/19. */
public class AddPropPutDiffTest {
private final String OPENAPI_DOC1 = "add-prop-put-1.yaml";
private final String OPENAPI_DOC2 = "add-prop-put-2.yaml";

@Test
public void testDiffSame() {
assertOpenApiAreEquals(OPENAPI_DOC1, OPENAPI_DOC1);
}

@Test
public void testDiffDifferent() {
assertOpenApiBackwardIncompatible(OPENAPI_DOC1, OPENAPI_DOC2);
}
}
71 changes: 71 additions & 0 deletions src/test/resources/add-prop-put-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
openapi: 3.0.0
servers:
- description: SwaggerHub API Auto Mocking
url: https://virtserver.swaggerhub.com/anshul10s/pet-store/1.0.0
info:
description: |
This is a sample Petstore server. You can find
out more about Swagger at
[http://swagger.io](http://swagger.io) or on
[irc.freenode.net, #swagger](http://swagger.io/irc/).
version: "1.0.0"
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
paths:
/store/inventory/{id}:
put:
tags:
- store
summary: Updates the inventory with the given id
description: Updates the inventory with the given id and returns it
operationId: putInventory
parameters:
- name: id
in: path
description: Unique Id of the inventory
required: true
example: a-b-c-d
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Inventory'
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Inventory'
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
components:
schemas:
Inventory:
type: object
properties:
id:
type: string
details:
type: count
73 changes: 73 additions & 0 deletions src/test/resources/add-prop-put-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
openapi: 3.0.0
servers:
- description: SwaggerHub API Auto Mocking
url: https://virtserver.swaggerhub.com/anshul10s/pet-store/1.0.0
info:
description: |
This is a sample Petstore server. You can find
out more about Swagger at
[http://swagger.io](http://swagger.io) or on
[irc.freenode.net, #swagger](http://swagger.io/irc/).
version: "1.0.0"
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
paths:
/store/inventory/{id}:
put:
tags:
- store
summary: Updates the inventory with the given id
description: Updates the inventory with the given id and returns it
operationId: putInventory
parameters:
- name: id
in: path
description: Unique Id of the inventory
required: true
example: a-b-c-d
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Inventory'
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Inventory'
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
components:
schemas:
Inventory:
type: object
properties:
id:
type: string
details:
type: count
extra_info:
type: string