Skip to content

Commit e7ae959

Browse files
committed
✨ feat: add openapi webhook docs
1 parent 8172bc2 commit e7ae959

File tree

2 files changed

+141
-2
lines changed

2 files changed

+141
-2
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import type { useSofa } from "sofa-api";
2+
3+
export const sofaOpenAPIWebhookDocs: Parameters<typeof useSofa>[0]["openAPI"] =
4+
{
5+
paths: {
6+
"/webhook": {
7+
post: {
8+
operationId: "webhook_create",
9+
description: "Creates a webhook subscription.",
10+
tags: [],
11+
parameters: [],
12+
requestBody: {
13+
content: {
14+
"application/json": {
15+
schema: {
16+
$ref: "#/components/schemas/WebhookCreateBody",
17+
},
18+
},
19+
},
20+
},
21+
responses: {
22+
"200": {
23+
content: {
24+
"application/json": {
25+
schema: {
26+
$ref: "#/components/schemas/WebhookDetailResponse",
27+
},
28+
},
29+
},
30+
},
31+
},
32+
},
33+
},
34+
"/webhook/{id}": {
35+
post: {
36+
operationId: "webhook_update",
37+
description: "Updates a webhook subscription.",
38+
parameters: [
39+
{
40+
name: "id",
41+
in: "path",
42+
description: "The ID of the webhook to update",
43+
required: true,
44+
schema: {
45+
type: "string",
46+
},
47+
} as any,
48+
],
49+
requestBody: {
50+
content: {
51+
"application/json": {
52+
schema: {
53+
$ref: "#/components/schemas/WebhookCreateBody",
54+
},
55+
},
56+
},
57+
},
58+
responses: {
59+
"200": {
60+
content: {
61+
"application/json": {
62+
schema: {
63+
$ref: "#/components/schemas/WebhookDetailResponse",
64+
},
65+
},
66+
},
67+
},
68+
},
69+
},
70+
delete: {
71+
operationId: "webhook_delete",
72+
description: "Removes a webhook subscription.",
73+
tags: [],
74+
parameters: [
75+
{
76+
name: "id",
77+
in: "path",
78+
description: "The ID of the webhook to delete",
79+
required: true,
80+
schema: {
81+
type: "string",
82+
},
83+
} as any,
84+
],
85+
responses: {
86+
"200": {
87+
content: {
88+
"application/json": {
89+
schema: {
90+
$ref: "#/components/schemas/WebhookDetailResponse",
91+
},
92+
},
93+
},
94+
},
95+
},
96+
},
97+
},
98+
},
99+
components: {
100+
schemas: {
101+
WebhookCreateBody: {
102+
type: "object",
103+
properties: {
104+
subscription: {
105+
description:
106+
"The subscription to subscribe to. In many cases, these match the available query IDs without the '_query' suffix. E.g., 'findFirstUser_query' -> 'findFirstUser'. See the graphql schema for more details on what subscriptions are available.",
107+
type: "string",
108+
},
109+
variables: {
110+
description: "The variables to pass to the subscription.",
111+
type: "object",
112+
},
113+
url: {
114+
description: "The URL to send the webhook to.",
115+
type: "string",
116+
},
117+
},
118+
},
119+
WebhookDetailResponse: {
120+
type: "object",
121+
properties: {
122+
id: {
123+
description:
124+
"The ID of the webhook. Can be used as reference in update or delete calls.",
125+
type: "string",
126+
},
127+
},
128+
},
129+
},
130+
},
131+
};

lib/rumble.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { createAbilityBuilder } from "./abilityBuilder";
77
import { createContextFunction } from "./context";
88
import { createEnumImplementer } from "./enum";
99
import { lazy } from "./helpers/lazy";
10+
import { sofaOpenAPIWebhookDocs } from "./helpers/sofaOpenAPIWebhookDocs";
1011
import { createObjectImplementer } from "./object";
1112
import { createPubSubInstance } from "./pubsub";
1213
import { createQueryImplementer } from "./query";
@@ -147,12 +148,19 @@ export const rumble = <
147148

148149
const createSofa = (
149150
args: Omit<Parameters<typeof useSofa>[0], "schema" | "context">,
150-
) =>
151-
useSofa({
151+
) => {
152+
if (args.openAPI) {
153+
args.openAPI = {
154+
...sofaOpenAPIWebhookDocs,
155+
...args.openAPI,
156+
};
157+
}
158+
return useSofa({
152159
...args,
153160
schema: builtSchema(),
154161
context,
155162
});
163+
};
156164

157165
return {
158166
/**

0 commit comments

Comments
 (0)