Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Link> 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();
Expand Down
75 changes: 75 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/linkIssue.yaml
Original file line number Diff line number Diff line change
@@ -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'