Skip to content

Commit 4f8c258

Browse files
committed
improve API docs
thanks @david-crespo and @benjaminleonard for advice!
1 parent d0b91e3 commit 4f8c258

File tree

3 files changed

+70
-24
lines changed

3 files changed

+70
-24
lines changed

nexus/external-api/src/lib.rs

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,7 +3532,7 @@ pub trait NexusExternalApi {
35323532
query_params: Query<PaginatedByNameOrId>,
35333533
) -> Result<HttpResponseOk<ResultsPage<views::WebhookReceiver>>, HttpError>;
35343534

3535-
/// Get the configuration for a webhook receiver.
3535+
/// Fetch webhook receiver
35363536
#[endpoint {
35373537
method = GET,
35383538
path = "/v1/webhooks/receivers/{receiver}",
@@ -3543,7 +3543,7 @@ pub trait NexusExternalApi {
35433543
path_params: Path<params::WebhookReceiverSelector>,
35443544
) -> Result<HttpResponseOk<views::WebhookReceiver>, HttpError>;
35453545

3546-
/// Create a new webhook receiver.
3546+
/// Create webhook receiver.
35473547
#[endpoint {
35483548
method = POST,
35493549
path = "/v1/webhooks/receivers",
@@ -3554,7 +3554,11 @@ pub trait NexusExternalApi {
35543554
params: TypedBody<params::WebhookCreate>,
35553555
) -> Result<HttpResponseCreated<views::WebhookReceiver>, HttpError>;
35563556

3557-
/// Update the configuration of an existing webhook receiver.
3557+
/// Update webhook receiver
3558+
///
3559+
/// Note that receiver secrets are NOT added or removed using this endpoint.
3560+
/// Instead, use the /v1/webhooks/{secrets}/?receiver={receiver} endpoint
3561+
/// to add and remove secrets.
35583562
#[endpoint {
35593563
method = PUT,
35603564
path = "/v1/webhooks/receivers/{receiver}",
@@ -3566,7 +3570,7 @@ pub trait NexusExternalApi {
35663570
params: TypedBody<params::WebhookReceiverUpdate>,
35673571
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
35683572

3569-
/// Delete a webhook receiver.
3573+
/// Delete webhook receiver.
35703574
#[endpoint {
35713575
method = DELETE,
35723576
path = "/v1/webhooks/receivers/{receiver}",
@@ -3577,10 +3581,23 @@ pub trait NexusExternalApi {
35773581
path_params: Path<params::WebhookReceiverSelector>,
35783582
) -> Result<HttpResponseDeleted, HttpError>;
35793583

3580-
/// Send a liveness probe request to a webhook receiver.
3581-
// TODO(eliza): this return type isn't quite right, as the response should
3582-
// have a typed body, but any status code, as we return a resposne with the
3583-
// status code from the webhook endpoint...
3584+
/// Send liveness probe to webhook receiver
3585+
///
3586+
/// This endpoint synchronously sends a liveness probe request to the
3587+
/// selected webhook receiver. The response message describes the outcome of
3588+
/// the probe request: either the response from the receiver endpoint, or an
3589+
/// indication of why the probe failed.
3590+
///
3591+
/// Note that the response status is 200 OK as long as a probe request was
3592+
/// able to be sent to the receiver endpoint. If the receiver responds with
3593+
/// another status code, including an error, this will be indicated by the
3594+
/// response body, NOT the status of the response.
3595+
///
3596+
/// The "resend" query parameter can be used to request re-delivery of
3597+
/// failed events if the liveness probe succeeds. If it is set to true and
3598+
/// the webhook receiver responds to the probe request with a 2xx status
3599+
/// code, any events for which delivery to this receiver has failed will be
3600+
/// queued for re-delivery.
35843601
#[endpoint {
35853602
method = POST,
35863603
path = "/v1/webhooks/receivers/{receiver}/probe",
@@ -3592,7 +3609,7 @@ pub trait NexusExternalApi {
35923609
query_params: Query<params::WebhookProbe>,
35933610
) -> Result<HttpResponseOk<views::WebhookProbeResult>, HttpError>;
35943611

3595-
/// List the IDs of secrets for a webhook receiver.
3612+
/// List webhook receiver secret IDs
35963613
#[endpoint {
35973614
method = GET,
35983615
path = "/v1/webhooks/secrets",
@@ -3603,7 +3620,7 @@ pub trait NexusExternalApi {
36033620
query_params: Query<params::WebhookReceiverSelector>,
36043621
) -> Result<HttpResponseOk<views::WebhookSecrets>, HttpError>;
36053622

3606-
/// Add a secret to a webhook receiver.
3623+
/// Add secret to webhook receiver
36073624
#[endpoint {
36083625
method = POST,
36093626
path = "/v1/webhooks/secrets",
@@ -3615,7 +3632,7 @@ pub trait NexusExternalApi {
36153632
params: TypedBody<params::WebhookSecretCreate>,
36163633
) -> Result<HttpResponseCreated<views::WebhookSecretId>, HttpError>;
36173634

3618-
/// Delete a secret associated with a webhook receiver by ID.
3635+
/// Remove secret from webhook receiver
36193636
#[endpoint {
36203637
method = DELETE,
36213638
path = "/v1/webhooks/secrets/{secret_id}",
@@ -3626,7 +3643,13 @@ pub trait NexusExternalApi {
36263643
path_params: Path<params::WebhookSecretSelector>,
36273644
) -> Result<HttpResponseDeleted, HttpError>;
36283645

3629-
/// List delivery attempts to a webhook receiver.
3646+
/// List delivery attempts to a webhook receiver
3647+
///
3648+
/// Optional query parameters to this endpoint may be used to filter
3649+
/// deliveries by state. If none of the "failed", "pending", or "delivered"
3650+
/// query parameters are present, all deliveries are returned. If one or
3651+
/// more of these parameters are provided, only those which are set to
3652+
/// "true" are included in the response.
36303653
#[endpoint {
36313654
method = GET,
36323655
path = "/v1/webhooks/deliveries",
@@ -3639,7 +3662,7 @@ pub trait NexusExternalApi {
36393662
pagination: Query<PaginatedById>,
36403663
) -> Result<HttpResponseOk<ResultsPage<views::WebhookDelivery>>, HttpError>;
36413664

3642-
/// Request re-delivery of a webhook event.
3665+
/// Request re-delivery of webhook event
36433666
#[endpoint {
36443667
method = POST,
36453668
path = "/v1/webhooks/deliveries/{event_id}/resend",

nexus/types/src/external_api/params.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,9 @@ pub struct DeviceAccessTokenRequest {
23812381
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
23822382
pub struct EventClassFilter {
23832383
/// An optional glob pattern for filtering event class names.
2384+
///
2385+
/// If provided, only event classes which match this glob pattern will be
2386+
/// included in the response.
23842387
pub filter: Option<String>,
23852388
}
23862389

@@ -2432,6 +2435,7 @@ pub struct WebhookReceiverUpdate {
24322435

24332436
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
24342437
pub struct WebhookSecretCreate {
2438+
/// The value of the shared secret key.
24352439
pub secret: String,
24362440
}
24372441

@@ -2443,13 +2447,24 @@ pub struct WebhookSecretSelector {
24432447

24442448
#[derive(Deserialize, JsonSchema)]
24452449
pub struct WebhookEventSelector {
2450+
/// UUID of the event
24462451
pub event_id: Uuid,
24472452
}
24482453

24492454
#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema)]
24502455
pub struct WebhookDeliveryStateFilter {
2456+
/// If true, include only deliveries which are currently in progress.
2457+
///
2458+
/// A delivery is considered "pending" if it has not yet been sent at all,
2459+
/// or if a delivery attempt has failed but the delivery has retries
2460+
/// remaining.
24512461
pub pending: Option<bool>,
2462+
/// If true, include only deliveries which have failed permanently.
2463+
///
2464+
/// A delivery fails permanently when the retry limit of three total
2465+
/// attempts is reached without a successful delivery.
24522466
pub failed: Option<bool>,
2467+
/// If true, include only deliveries which have succeeded.
24532468
pub delivered: Option<bool>,
24542469
}
24552470

openapi/nexus.json

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11935,7 +11935,8 @@
1193511935
"tags": [
1193611936
"system/webhooks"
1193711937
],
11938-
"summary": "List delivery attempts to a webhook receiver.",
11938+
"summary": "List delivery attempts to a webhook receiver",
11939+
"description": "Optional query parameters to this endpoint may be used to filter deliveries by state. If none of the \"failed\", \"pending\", or \"delivered\" query parameters are present, all deliveries are returned. If one or more of these parameters are provided, only those which are set to \"true\" are included in the response.",
1193911940
"operationId": "webhook_delivery_list",
1194011941
"parameters": [
1194111942
{
@@ -11950,6 +11951,7 @@
1195011951
{
1195111952
"in": "query",
1195211953
"name": "delivered",
11954+
"description": "If true, include only deliveries which have succeeded.",
1195311955
"schema": {
1195411956
"nullable": true,
1195511957
"type": "boolean"
@@ -11958,6 +11960,7 @@
1195811960
{
1195911961
"in": "query",
1196011962
"name": "failed",
11963+
"description": "If true, include only deliveries which have failed permanently.\n\nA delivery fails permanently when the retry limit of three total attempts is reached without a successful delivery.",
1196111964
"schema": {
1196211965
"nullable": true,
1196311966
"type": "boolean"
@@ -11966,6 +11969,7 @@
1196611969
{
1196711970
"in": "query",
1196811971
"name": "pending",
11972+
"description": "If true, include only deliveries which are currently in progress.\n\nA delivery is considered \"pending\" if it has not yet been sent at all, or if a delivery attempt has failed but the delivery has retries remaining.",
1196911973
"schema": {
1197011974
"nullable": true,
1197111975
"type": "boolean"
@@ -12027,12 +12031,13 @@
1202712031
"tags": [
1202812032
"system/webhooks"
1202912033
],
12030-
"summary": "Request re-delivery of a webhook event.",
12034+
"summary": "Request re-delivery of webhook event",
1203112035
"operationId": "webhook_delivery_resend",
1203212036
"parameters": [
1203312037
{
1203412038
"in": "path",
1203512039
"name": "event_id",
12040+
"description": "UUID of the event",
1203612041
"required": true,
1203712042
"schema": {
1203812043
"type": "string",
@@ -12100,7 +12105,7 @@
1210012105
{
1210112106
"in": "query",
1210212107
"name": "filter",
12103-
"description": "An optional glob pattern for filtering event class names.",
12108+
"description": "An optional glob pattern for filtering event class names.\n\nIf provided, only event classes which match this glob pattern will be included in the response.",
1210412109
"schema": {
1210512110
"nullable": true,
1210612111
"type": "string"
@@ -12192,7 +12197,7 @@
1219212197
"tags": [
1219312198
"system/webhooks"
1219412199
],
12195-
"summary": "Create a new webhook receiver.",
12200+
"summary": "Create webhook receiver.",
1219612201
"operationId": "webhook_receiver_create",
1219712202
"requestBody": {
1219812203
"content": {
@@ -12229,7 +12234,7 @@
1222912234
"tags": [
1223012235
"system/webhooks"
1223112236
],
12232-
"summary": "Get the configuration for a webhook receiver.",
12237+
"summary": "Fetch webhook receiver",
1223312238
"operationId": "webhook_receiver_view",
1223412239
"parameters": [
1223512240
{
@@ -12265,7 +12270,8 @@
1226512270
"tags": [
1226612271
"system/webhooks"
1226712272
],
12268-
"summary": "Update the configuration of an existing webhook receiver.",
12273+
"summary": "Update webhook receiver",
12274+
"description": "Note that receiver secrets are NOT added or removed using this endpoint. Instead, use the /v1/webhooks/{secrets}/?receiver={receiver} endpoint to add and remove secrets.",
1226912275
"operationId": "webhook_receiver_update",
1227012276
"parameters": [
1227112277
{
@@ -12304,7 +12310,7 @@
1230412310
"tags": [
1230512311
"system/webhooks"
1230612312
],
12307-
"summary": "Delete a webhook receiver.",
12313+
"summary": "Delete webhook receiver.",
1230812314
"operationId": "webhook_receiver_delete",
1230912315
"parameters": [
1231012316
{
@@ -12335,7 +12341,8 @@
1233512341
"tags": [
1233612342
"system/webhooks"
1233712343
],
12338-
"summary": "Send a liveness probe request to a webhook receiver.",
12344+
"summary": "Send liveness probe to webhook receiver",
12345+
"description": "This endpoint synchronously sends a liveness probe request to the selected webhook receiver. The response message describes the outcome of the probe request: either the response from the receiver endpoint, or an indication of why the probe failed.\n\nNote that the response status is 200 OK as long as a probe request was able to be sent to the receiver endpoint. If the receiver responds with another status code, including an error, this will be indicated by the response body, NOT the status of the response.\n\nThe \"resend\" query parameter can be used to request re-delivery of failed events if the liveness probe succeeds. If it is set to true and the webhook receiver responds to the probe request with a 2xx status code, any events for which delivery to this receiver has failed will be queued for re-delivery.",
1233912346
"operationId": "webhook_receiver_probe",
1234012347
"parameters": [
1234112348
{
@@ -12381,7 +12388,7 @@
1238112388
"tags": [
1238212389
"system/webhooks"
1238312390
],
12384-
"summary": "List the IDs of secrets for a webhook receiver.",
12391+
"summary": "List webhook receiver secret IDs",
1238512392
"operationId": "webhook_secrets_list",
1238612393
"parameters": [
1238712394
{
@@ -12417,7 +12424,7 @@
1241712424
"tags": [
1241812425
"system/webhooks"
1241912426
],
12420-
"summary": "Add a secret to a webhook receiver.",
12427+
"summary": "Add secret to webhook receiver",
1242112428
"operationId": "webhook_secrets_add",
1242212429
"parameters": [
1242312430
{
@@ -12465,7 +12472,7 @@
1246512472
"tags": [
1246612473
"system/webhooks"
1246712474
],
12468-
"summary": "Delete a secret associated with a webhook receiver by ID.",
12475+
"summary": "Remove secret from webhook receiver",
1246912476
"operationId": "webhook_secrets_delete",
1247012477
"parameters": [
1247112478
{
@@ -25657,6 +25664,7 @@
2565725664
"type": "object",
2565825665
"properties": {
2565925666
"secret": {
25667+
"description": "The value of the shared secret key.",
2566025668
"type": "string"
2566125669
}
2566225670
},

0 commit comments

Comments
 (0)