Skip to content

Commit

Permalink
Add webhook model API TCKs
Browse files Browse the repository at this point in the history
  • Loading branch information
Azquelt committed May 16, 2024
1 parent 7a5fb71 commit 61eb864
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,29 @@ public OpenAPI buildModel() {
.externalDocs(OASFactory.createObject(ExternalDocumentation.class)
.description("instructions for how to deploy this app")
.url("https://github.com/microservices-api/oas3-airlines/blob/master/README.md"))
.addWebhook("bookingEvent", OASFactory.createPathItem()
.PUT(OASFactory.createOperation()
.summary("Notifies that a booking has been created")
.requestBody(OASFactory.createRequestBody()
.content(OASFactory.createContent()
.addMediaType("application/json", OASFactory.createMediaType()
.schema(OASFactory.createSchema()
.ref("#/components/schemas/Booking")))))
.responses(OASFactory.createAPIResponses()
.addAPIResponse("204", OASFactory.createAPIResponse()
.description(
"Indicates that the creation event was processed successfully"))))
.DELETE(OASFactory.createOperation()
.summary("Notifies that a booking has been deleted")
.requestBody(OASFactory.createRequestBody()
.content(OASFactory.createContent()
.addMediaType("application/json", OASFactory.createMediaType()
.schema(OASFactory.createSchema()
.ref("#/components/schemas/Booking")))))
.responses(OASFactory.createAPIResponses()
.addAPIResponse("204", OASFactory.createAPIResponse()
.description(
"Indicates that the deletion event was processed successfully")))))
.paths(OASFactory.createObject(Paths.class)
.addPathItem("/modelReader/airlines", OASFactory.createObject(PathItem.class)
.GET(OASFactory.createObject(Operation.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,26 @@ public void testContentInAPIResponse(String type) {
vr.body(content1 + ".schema.type", itemOrSingleton("array"));
vr.body(content1 + ".schema.items", notNullValue());
}

@Test(dataProvider = "formatProvider")
public void testWebhooks(String type) {
ValidatableResponse vr = callEndpoint(type);

String webhookPut = "webhooks.bookingEvent.put";
vr.body(webhookPut, notNullValue());
vr.body(webhookPut + ".summary", equalTo("Notifies that a booking has been created"));
vr.body(webhookPut + ".requestBody.content.'application/json'.schema.$ref",
equalTo("#/components/schemas/Booking"));
vr.body(webhookPut + ".responses.'204'.description",
equalTo("Indicates that the creation event was processed successfully"));

String webhookDelete = "webhooks.bookingEvent.delete";
vr.body(webhookPut, notNullValue());
vr.body(webhookDelete + ".summary", equalTo("Notifies that a booking has been deleted"));
vr.body(webhookDelete + ".requestBody.content.'application/json'.schema.$ref",
equalTo("#/components/schemas/Booking"));
vr.body(webhookDelete + ".responses.'204'.description",
equalTo("Indicates that the deletion event was processed successfully"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;

Expand Down Expand Up @@ -123,5 +124,21 @@ public void testStaticDocument(String type) {
vr.body(inventoryPathTrace + ".summary", equalTo("trace operation"));
vr.body(inventoryPathTrace + ".operationId", equalTo("traceInventory"));
vr.body(inventoryPathTrace + ".description", equalTo("tests the trace operation"));

String webhookPut = "webhooks.bookingEvent.put";
vr.body(webhookPut, notNullValue());
vr.body(webhookPut + ".summary", equalTo("Notifies that a booking has been created"));
vr.body(webhookPut + ".requestBody.content.'application/json'.schema.$ref",
equalTo("#/components/schemas/Booking"));
vr.body(webhookPut + ".responses.'204'.description",
equalTo("Indicates that the creation event was processed successfully"));

String webhookDelete = "webhooks.bookingEvent.delete";
vr.body(webhookPut, notNullValue());
vr.body(webhookDelete + ".summary", equalTo("Notifies that a booking has been deleted"));
vr.body(webhookDelete + ".requestBody.content.'application/json'.schema.$ref",
equalTo("#/components/schemas/Booking"));
vr.body(webhookDelete + ".responses.'204'.description",
equalTo("Indicates that the deletion event was processed successfully"));
}
}
22 changes: 22 additions & 0 deletions tck/src/main/resources/simpleapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,28 @@ paths:
responses:
'200':
description: trace operation tested
webhooks:
bookingEvent:
put:
summary: Notifies that a booking has been created
requestBody:
content:
'application/json':
schema:
$ref: '#/components/schemas/Booking'
responses:
'204':
description: Indicates that the creation event was processed successfully
delete:
summary: Notifies that a booking has been deleted
requestBody:
content:
'application/json':
schema:
$ref: '#/components/schemas/Booking'
responses:
'204':
description: Indicates that the deletion event was processed successfully
components:
schemas:
InventoryItem:
Expand Down

0 comments on commit 61eb864

Please sign in to comment.