From 741aed73cde8bda2e2afd18f455fe73b56dd6651 Mon Sep 17 00:00:00 2001 From: Mohammed Rizwan Date: Mon, 15 Oct 2018 22:42:29 +0530 Subject: [PATCH] Fix for issue 882 RequestBody parameter is missing under links --- .../v3/parser/util/OpenAPIDeserializer.java | 5 ++ .../v3/parser/test/OpenAPIV3ParserTest.java | 11 +++ .../src/test/resources/linkIssue.yaml | 75 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 modules/swagger-parser-v3/src/test/resources/linkIssue.yaml diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java index a7dcca31f1..be0a462355 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java @@ -1050,6 +1050,11 @@ public Link getLink(ObjectNode linkNode, String location, ParseResult result) { link.setParameters(getLinkParameters(parametersObject, location, result)); } + String requestBody = getString("requestBody",linkNode,false,location,result); + if (requestBody!= null) { + link.setRequestBody(requestBody); + } + ObjectNode headerObject = getObject("headers",linkNode,false,location,result); if (headerObject!= null) { link.setHeaders(getHeaders(headerObject, location, result)); diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java index bd308ce65c..85e1c915c3 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java @@ -12,6 +12,7 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.PathItem; +import io.swagger.v3.oas.models.links.Link; import io.swagger.v3.oas.models.media.*; import io.swagger.v3.oas.models.examples.Example; import io.swagger.v3.oas.models.media.ArraySchema; @@ -1537,6 +1538,16 @@ public void shouldParseRequestBody() { assertEquals(actualPathContent, actualComponentContent); } + @Test + public void testLinkIssue() { + ParseOptions parseOptions = new ParseOptions(); + parseOptions.setResolveFully(true); + OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/linkIssue.yaml", null, parseOptions); + Map links = openAPI.getPaths().get("/2.0/repositories/{username}").getGet().getResponses().get("200").getLinks(); + Object requestBody = links.get("userRepository").getRequestBody(); + assertEquals(requestBody, "$response.body#/slug"); + } + private static int getDynamicPort() { return new Random().ints(10000, 20000).findFirst().getAsInt(); diff --git a/modules/swagger-parser-v3/src/test/resources/linkIssue.yaml b/modules/swagger-parser-v3/src/test/resources/linkIssue.yaml new file mode 100644 index 0000000000..fa575fff7b --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/linkIssue.yaml @@ -0,0 +1,75 @@ +openapi: 3.0.0 +info: + title: Link Example + version: 1.0.0 +paths: + /2.0/repositories/{username}: + get: + operationId: getRepositoriesByOwner + parameters: + - name: username + in: path + required: true + schema: + type: string + responses: + '200': + description: repositories owned by the supplied user + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/repository' + links: + userRepository: + operationId: getRepository + requestBody: '$response.body#/slug' + /2.0/repositories/{username}/{slug}: + get: + operationId: getRepository + parameters: + - name: username + in: path + required: true + schema: + type: string + - name: slug + in: path + required: true + schema: + type: string + responses: + '200': + description: The repository + content: + application/json: + schema: + $ref: '#/components/schemas/repository' +components: + schemas: + user: + type: object + properties: + username: + type: string + uuid: + type: string + repository: + type: object + properties: + slug: + type: string + owner: + $ref: '#/components/schemas/user' + pullrequest: + type: object + properties: + id: + type: integer + title: + type: string + repository: + $ref: '#/components/schemas/repository' + author: + $ref: '#/components/schemas/user' \ No newline at end of file