Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Webhooks model APIs #612

Merged
merged 2 commits into from
May 20, 2024
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 @@ -18,6 +18,7 @@
package org.eclipse.microprofile.openapi.models;

import java.util.List;
import java.util.Map;

import org.eclipse.microprofile.openapi.models.info.Info;
import org.eclipse.microprofile.openapi.models.security.SecurityRequirement;
Expand Down Expand Up @@ -275,6 +276,57 @@ default OpenAPI paths(Paths paths) {
return this;
}

/**
* Returns the webhooks property of this OpenAPI instance.
*
* @return a copy Map (potentially immutable) of named webhook definitions
* @since 4.0
*/
Map<String, PathItem> getWebhooks();

/**
* Sets the webhooks property of this OpenAPI instance.
*
* @param webhooks
* a map of named webhook definitions
* @since 4.0
*/
void setWebhooks(Map<String, PathItem> webhooks);

/**
* Sets the webhooks property of this OpenAPI instance.
*
* @param webhooks
* a map of named webhook definitions
* @return the current Schema instance
* @since 4.0
*/
default OpenAPI webhooks(Map<String, PathItem> webhooks) {
setWebhooks(webhooks);
return this;
}

/**
* Adds a webhook definition.
*
* @param name
* unique name of the webhook to add
* @param webhook
* webhook definition to add
* @return the current Schema instance
* @since 4.0
*/
OpenAPI addWebhook(String name, PathItem webhook);

/**
* Removes a webhook definition.
*
* @param name
* unique name of the webhook to remove
* @since 4.0
*/
void removeWebhook(String name);

/**
* Returns the components property from an OpenAPI instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
* </pre>
*/

@org.osgi.annotation.versioning.Version("2.0")
@org.osgi.annotation.versioning.Version("2.1")
@org.osgi.annotation.versioning.ProviderType
package org.eclipse.microprofile.openapi.models;
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
Loading