Skip to content
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

Fix for issue 1601 #1624

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -737,7 +737,7 @@ public PathItem getPathItem(ObjectNode obj, String location, ParseResult result)

ObjectNode node = getObject("get", obj, false, location, result);
if (node != null) {
Operation operation = getOperation(node, location + "(get)", result);
Operation operation = getOperation(node, location + "(get)", result, true);
if (operation != null) {
pathItem.setGet(operation);
}
Expand All @@ -758,14 +758,14 @@ public PathItem getPathItem(ObjectNode obj, String location, ParseResult result)
}
node = getObject("head", obj, false, location, result);
if (node != null) {
Operation operation = getOperation(node, location + "(head)", result);
Operation operation = getOperation(node, location + "(head)", result, true);
if (operation != null) {
pathItem.setHead(operation);
}
}
node = getObject("delete", obj, false, location, result);
if (node != null) {
Operation operation = getOperation(node, location + "(delete)", result);
Operation operation = getOperation(node, location + "(delete)", result, true);
if (operation != null) {
pathItem.setDelete(operation);
}
Expand Down Expand Up @@ -2905,8 +2905,11 @@ public List<String> getTagsStrings(ArrayNode nodes, String location, ParseResult
return tags;
}


public Operation getOperation(ObjectNode obj, String location, ParseResult result) {
return getOperation(obj, location, result, false);
}

public Operation getOperation(ObjectNode obj, String location, ParseResult result, boolean ignoreRequestBody) {
if (obj == null) {
return null;
}
Expand Down Expand Up @@ -2946,8 +2949,11 @@ public Operation getOperation(ObjectNode obj, String location, ParseResult resul

final ObjectNode requestObjectNode = getObject("requestBody", obj, false, location, result);
if (requestObjectNode != null) {
if (ignoreRequestBody) {
result.warning(location, " is no longer allowed to have request body because it does not have defined semantics as per RFC 7231");
}
operation.setRequestBody(getRequestBody(requestObjectNode, String.format("%s.%s", location,
"requestBody"), result));
"requestBody"), result));
}

ObjectNode responsesNode = getObject("responses", obj, true, location, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ public void testPetstore() throws Exception {
SwaggerParseResult result = parser.readLocation("src/test/resources/petstore.yaml", null, options);

assertNotNull(result);
assertTrue(result.getMessages().size()==2);
assertTrue(result.getMessages().size()==3);

OpenAPI openAPI = result.getOpenAPI();
Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
Expand Down Expand Up @@ -2914,4 +2914,13 @@ public void testIssue1540() throws Exception{
Assert.assertNotNull(testPutExtensions.get("x-order"));
Assert.assertEquals((String)testPutExtensions.get("x-order"),"2147483647");
}

@Test
public void testIssue1601() {
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/issue-1601.yaml", null, null);
List<String> messages = result.getMessages();
Assert.assertEquals(messages.get(0), "attribute paths.'/inventory'(get). is no longer allowed to have request body because it does not have defined semantics as per RFC 7231");
Assert.assertEquals(messages.size(), 1);
Assert.assertNotNull(result.getOpenAPI().getPaths().get("/inventory").getGet().getRequestBody());
}
}
65 changes: 65 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue-1601.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
openapi: 3.0.3
info:
description: This is a simple API
version: "1.0.0"
title: Simple Inventory API
contact:
email: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/inventory:
get:
tags:
- admins
summary: adds an inventory item
operationId: addInventory
description: Adds an item to the system
responses:
'201':
description: item created
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/InventoryItem'
description: Inventory item to add
components:
schemas:
InventoryItem:
type: object
required:
- id
- name
- manufacturer
- releaseDate
properties:
id:
type: string
format: uuid
example: d290f1ee-6c54-4b01-90e6-d701748f0851
name:
type: string
example: Widget Adapter
releaseDate:
type: string
format: date-time
example: '2016-08-29T09:12:33.001Z'
manufacturer:
$ref: '#/components/schemas/Manufacturer'
Manufacturer:
required:
- name
properties:
name:
type: string
example: ACME Corporation
homePage:
type: string
format: url
example: 'https://www.acme-corp.com'
phone:
type: string
example: 408-867-5309
type: object