Skip to content

Commit 985a18e

Browse files
authored
Merge pull request #1216 from swagger-api/callback-issue
callback with $ref not being resolved
2 parents 57c7b2b + 9472428 commit 985a18e

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/OperationProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ public void processOperation(Operation operation) {
7575
for (String name : callbacks.keySet()) {
7676
Callback callback = callbacks.get(name);
7777
if(callback != null) {
78-
if (callback.get("$ref") != null){
79-
String $ref = callback.get("$ref").get$ref();
78+
if (callback.get$ref() != null){
79+
String $ref = callback.get$ref();
8080
RefFormat refFormat = computeRefFormat($ref);
8181
if (isAnExternalRefFormat(refFormat)){
8282
final String newRef = externalRefProcessor.processRefToExternalCallback($ref, refFormat);
8383
if (newRef != null) {
84-
callback.get("$ref").set$ref(newRef);
84+
callback.set$ref(newRef);
8585
}
8686
}
8787
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ public class OpenAPIV3ParserTest {
6666
protected int serverPort = getDynamicPort();
6767
protected WireMockServer wireMockServer;
6868

69+
@Test
70+
public void testIssueResolveCallBacks() {
71+
ParseOptions options = new ParseOptions();
72+
options.setResolve(true);
73+
options.setFlatten(true);
74+
SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("callbacks-issue/swagger.yaml", null, options);
75+
OpenAPI spec = parseResult.getOpenAPI();
76+
assertNotNull(spec);
77+
assertEquals(spec.getPaths().get("/webhook").getPost().getCallbacks().get("WebhookVerificationEvent").get$ref(),"#/components/callbacks/WebhookVerificationEvent");
78+
}
79+
6980
@Test
7081
public void testIssue1190() {
7182
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# OpenAPI version identifier - required for OpenAPI 3.0 domains
2+
openapi: 3.0.0
3+
4+
#######################
5+
# Optional info section
6+
#######################
7+
info:
8+
title: Common
9+
description: Common Components for REST API's
10+
version: '1.0.1'
11+
12+
components:
13+
14+
#########################
15+
# Common callback definitions
16+
# See: https://swagger.io/docs/specification/callbacks/
17+
#########################
18+
callbacks:
19+
#### Webhooks ####
20+
WebhookVerificationEvent:
21+
'https://yourdomain.com/css/yourCallbackEndpoint':
22+
post:
23+
parameters:
24+
- $ref: '#/components/parameters/x-api-key'
25+
requestBody:
26+
required: true
27+
description: description
28+
content:
29+
application/json:
30+
schema:
31+
$ref: '#/components/schemas/WebhookVerification'
32+
responses:
33+
'202':
34+
description: Your server returns this code if it accepts the message it was sent
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
openapi: 3.0.2
2+
servers:
3+
- description: Dev server
4+
url: 'https://api.net'
5+
info:
6+
title: API
7+
version: 1.0.0
8+
description:
9+
tags:
10+
- name: Webhook API
11+
description: Endpoints related to the subscription and management of Webhooks
12+
paths:
13+
'/webhook':
14+
post:
15+
tags:
16+
- Webhook API
17+
summary: Subscribe to events for a Market Participant
18+
description: description
19+
operationId: subscribe-webhook
20+
callbacks:
21+
WebhookVerificationEvent:
22+
$ref: 'domain.yaml#/components/callbacks/WebhookVerificationEvent'

0 commit comments

Comments
 (0)