Skip to content

Commit 87beaa2

Browse files
authored
Merge pull request #880 from ymohdriz/branch_issue_878
Fix for issue 878
2 parents 9889832 + 43c951c commit 87beaa2

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,14 +1128,13 @@ public Callback getCallback(ObjectNode node,String location, ParseResult result)
11281128
JsonNode ref = node.get("$ref");
11291129
if (ref != null) {
11301130
if (ref.getNodeType().equals(JsonNodeType.STRING)) {
1131-
PathItem pathItem = new PathItem();
11321131
String mungedRef = mungedRef(ref.textValue());
11331132
if (mungedRef != null) {
1134-
pathItem.set$ref(mungedRef);
1133+
callback.set$ref(mungedRef);
11351134
}else{
1136-
pathItem.set$ref(ref.textValue());
1135+
callback.set$ref(ref.textValue());
11371136
}
1138-
return callback.addPathItem(name,pathItem);
1137+
return callback;
11391138
} else {
11401139
result.invalidType(location, "$ref", "string", node);
11411140
return null;

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,11 @@ public void componentsResolver() throws Exception {
339339

340340
Map<String, Callback> callbacks = openAPI.getComponents().getCallbacks();
341341
// internal callback reference
342-
assertEquals(callbacks.get("referenced").get("$ref").get$ref(),"#/components/callbacks/failed");
342+
assertEquals(callbacks.get("referenced").get$ref(),"#/components/callbacks/failed");
343343
//callback pathItem -> operation ->requestBody
344344
assertEquals(callbacks.get("heartbeat").get("$request.query.heartbeat-url").getPost().getRequestBody().get$ref(),"#/components/requestBodies/requestBody3");
345345
//remote callback ref
346-
assertEquals(callbacks.get("remoteCallback").get("$ref").get$ref(),"#/components/callbacks/callback");
346+
assertEquals(callbacks.get("remoteCallback").get$ref(),"http://localhost:" + serverPort + "/remote/callback");
347347

348348
}
349349

modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,19 @@ public void testIssueRelativeRefs1(){
415415

416416
assertEquals(prop.get$ref(),"#/components/schemas/simpleIDType_v01");
417417
}
418+
419+
@Test
420+
public void testIssue879() {
421+
OpenAPIParser openApiParser = new OpenAPIParser();
422+
ParseOptions options = new ParseOptions();
423+
OpenAPI openAPI = openApiParser.readLocation("issue_879.yaml", null, options).getOpenAPI();
424+
425+
String ref = openAPI.getPaths()
426+
.get("/register")
427+
.getPost()
428+
.getCallbacks()
429+
.get("myEvent")
430+
.get$ref();
431+
assertEquals(ref, "#/components/callbacks/callbackEvent");
432+
}
418433
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Callback with ref Example
4+
version: 1.0.0
5+
paths:
6+
/register:
7+
post:
8+
summary: Subscribe to a webhook
9+
requestBody:
10+
required: true
11+
content:
12+
application/json:
13+
schema:
14+
type: object
15+
properties:
16+
callbackUrl: # Callback URL
17+
type: string
18+
format: uri
19+
example: https://myserver.com/send/callback/here
20+
required:
21+
- callbackUrl
22+
responses:
23+
'200':
24+
description: subscription successfully created
25+
content:
26+
application/json:
27+
schema:
28+
type: object
29+
description: subscription information
30+
required:
31+
- subscriptionId
32+
properties:
33+
subscriptionId:
34+
description: unique identifier
35+
type: string
36+
example: 2531329f-fb09-4ef7-887e-84e648214436
37+
callbacks:
38+
myEvent:
39+
$ref: '#/components/callbacks/callbackEvent'
40+
components:
41+
callbacks:
42+
callbackEvent:
43+
'{$request.body#/callbackUrl}':
44+
post:
45+
requestBody: # Contents of the callback message
46+
required: true
47+
content:
48+
application/json:
49+
schema:
50+
type: object
51+
properties:
52+
message:
53+
type: string
54+
example: Some event happened
55+
required:
56+
- message
57+
responses:
58+
'200':
59+
description: ok

0 commit comments

Comments
 (0)