Skip to content

Commit 61eb864

Browse files
committed
Add webhook model API TCKs
1 parent 7a5fb71 commit 61eb864

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

tck/src/main/java/org/eclipse/microprofile/openapi/reader/MyOASModelReaderImpl.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,29 @@ public OpenAPI buildModel() {
255255
.externalDocs(OASFactory.createObject(ExternalDocumentation.class)
256256
.description("instructions for how to deploy this app")
257257
.url("https://github.com/microservices-api/oas3-airlines/blob/master/README.md"))
258+
.addWebhook("bookingEvent", OASFactory.createPathItem()
259+
.PUT(OASFactory.createOperation()
260+
.summary("Notifies that a booking has been created")
261+
.requestBody(OASFactory.createRequestBody()
262+
.content(OASFactory.createContent()
263+
.addMediaType("application/json", OASFactory.createMediaType()
264+
.schema(OASFactory.createSchema()
265+
.ref("#/components/schemas/Booking")))))
266+
.responses(OASFactory.createAPIResponses()
267+
.addAPIResponse("204", OASFactory.createAPIResponse()
268+
.description(
269+
"Indicates that the creation event was processed successfully"))))
270+
.DELETE(OASFactory.createOperation()
271+
.summary("Notifies that a booking has been deleted")
272+
.requestBody(OASFactory.createRequestBody()
273+
.content(OASFactory.createContent()
274+
.addMediaType("application/json", OASFactory.createMediaType()
275+
.schema(OASFactory.createSchema()
276+
.ref("#/components/schemas/Booking")))))
277+
.responses(OASFactory.createAPIResponses()
278+
.addAPIResponse("204", OASFactory.createAPIResponse()
279+
.description(
280+
"Indicates that the deletion event was processed successfully")))))
258281
.paths(OASFactory.createObject(Paths.class)
259282
.addPathItem("/modelReader/airlines", OASFactory.createObject(PathItem.class)
260283
.GET(OASFactory.createObject(Operation.class)

tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelReaderAppTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,26 @@ public void testContentInAPIResponse(String type) {
346346
vr.body(content1 + ".schema.type", itemOrSingleton("array"));
347347
vr.body(content1 + ".schema.items", notNullValue());
348348
}
349+
350+
@Test(dataProvider = "formatProvider")
351+
public void testWebhooks(String type) {
352+
ValidatableResponse vr = callEndpoint(type);
353+
354+
String webhookPut = "webhooks.bookingEvent.put";
355+
vr.body(webhookPut, notNullValue());
356+
vr.body(webhookPut + ".summary", equalTo("Notifies that a booking has been created"));
357+
vr.body(webhookPut + ".requestBody.content.'application/json'.schema.$ref",
358+
equalTo("#/components/schemas/Booking"));
359+
vr.body(webhookPut + ".responses.'204'.description",
360+
equalTo("Indicates that the creation event was processed successfully"));
361+
362+
String webhookDelete = "webhooks.bookingEvent.delete";
363+
vr.body(webhookPut, notNullValue());
364+
vr.body(webhookDelete + ".summary", equalTo("Notifies that a booking has been deleted"));
365+
vr.body(webhookDelete + ".requestBody.content.'application/json'.schema.$ref",
366+
equalTo("#/components/schemas/Booking"));
367+
vr.body(webhookDelete + ".responses.'204'.description",
368+
equalTo("Indicates that the deletion event was processed successfully"));
369+
370+
}
349371
}

tck/src/main/java/org/eclipse/microprofile/openapi/tck/StaticDocumentTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.hamcrest.Matchers.containsString;
2222
import static org.hamcrest.Matchers.equalTo;
2323
import static org.hamcrest.Matchers.hasSize;
24+
import static org.hamcrest.Matchers.notNullValue;
2425
import static org.hamcrest.Matchers.startsWith;
2526
import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
2627

@@ -123,5 +124,21 @@ public void testStaticDocument(String type) {
123124
vr.body(inventoryPathTrace + ".summary", equalTo("trace operation"));
124125
vr.body(inventoryPathTrace + ".operationId", equalTo("traceInventory"));
125126
vr.body(inventoryPathTrace + ".description", equalTo("tests the trace operation"));
127+
128+
String webhookPut = "webhooks.bookingEvent.put";
129+
vr.body(webhookPut, notNullValue());
130+
vr.body(webhookPut + ".summary", equalTo("Notifies that a booking has been created"));
131+
vr.body(webhookPut + ".requestBody.content.'application/json'.schema.$ref",
132+
equalTo("#/components/schemas/Booking"));
133+
vr.body(webhookPut + ".responses.'204'.description",
134+
equalTo("Indicates that the creation event was processed successfully"));
135+
136+
String webhookDelete = "webhooks.bookingEvent.delete";
137+
vr.body(webhookPut, notNullValue());
138+
vr.body(webhookDelete + ".summary", equalTo("Notifies that a booking has been deleted"));
139+
vr.body(webhookDelete + ".requestBody.content.'application/json'.schema.$ref",
140+
equalTo("#/components/schemas/Booking"));
141+
vr.body(webhookDelete + ".responses.'204'.description",
142+
equalTo("Indicates that the deletion event was processed successfully"));
126143
}
127144
}

tck/src/main/resources/simpleapi.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,28 @@ paths:
120120
responses:
121121
'200':
122122
description: trace operation tested
123+
webhooks:
124+
bookingEvent:
125+
put:
126+
summary: Notifies that a booking has been created
127+
requestBody:
128+
content:
129+
'application/json':
130+
schema:
131+
$ref: '#/components/schemas/Booking'
132+
responses:
133+
'204':
134+
description: Indicates that the creation event was processed successfully
135+
delete:
136+
summary: Notifies that a booking has been deleted
137+
requestBody:
138+
content:
139+
'application/json':
140+
schema:
141+
$ref: '#/components/schemas/Booking'
142+
responses:
143+
'204':
144+
description: Indicates that the deletion event was processed successfully
123145
components:
124146
schemas:
125147
InventoryItem:

0 commit comments

Comments
 (0)