Skip to content

Commit d773844

Browse files
authored
feat(http): surface callbacks webhooks and links (#250)
1 parent 0c44adc commit d773844

File tree

8 files changed

+740
-82
lines changed

8 files changed

+740
-82
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ autosdk generate openapi.yaml \
3737
It will generate the code in the "Generated" subdirectory.
3838
It also will include polyfills for .Net Framework/.Net Standard TargetFrameworks.
3939

40+
## HTTP Artifacts
41+
`autosdk http` emits executable request files for regular OpenAPI path operations. It also surfaces response links and callbacks as commented documentation blocks next to the owning operation, and writes root-level OpenAPI webhooks to `webhooks.http` as inbound contract documentation instead of outbound client calls.
42+
4043
## Source generator
4144
- Install the package
4245
```bash
@@ -213,4 +216,4 @@ Skill source: [`skills/generating-dotnet-sdks/`](skills/generating-dotnet-sdks/)
213216
- https://github.com/tryAGI/Replicate
214217
- https://github.com/tryAGI/DeepInfra
215218
- https://github.com/tryAGI/Leonardo
216-
- https://github.com/HavenDV/GitHub.NET
219+
- https://github.com/HavenDV/GitHub.NET
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Callback Webhook Link Fixture
4+
version: 1.0.0
5+
paths:
6+
/subscriptions:
7+
post:
8+
operationId: createSubscription
9+
summary: Create subscription
10+
tags:
11+
- subscriptions
12+
requestBody:
13+
required: true
14+
content:
15+
application/json:
16+
schema:
17+
type: object
18+
required:
19+
- callbackUrl
20+
- topic
21+
properties:
22+
callbackUrl:
23+
type: string
24+
format: uri
25+
topic:
26+
type: string
27+
callbacks:
28+
subscriptionStatus:
29+
'{$request.body#/callbackUrl}':
30+
post:
31+
operationId: subscriptionStatusCallback
32+
summary: Receive subscription status
33+
requestBody:
34+
required: true
35+
content:
36+
application/json:
37+
schema:
38+
type: object
39+
required:
40+
- subscriptionId
41+
- state
42+
properties:
43+
subscriptionId:
44+
type: string
45+
state:
46+
type: string
47+
responses:
48+
'200':
49+
description: Callback acknowledged
50+
responses:
51+
'201':
52+
description: Created
53+
content:
54+
application/json:
55+
schema:
56+
$ref: '#/components/schemas/SubscriptionAccepted'
57+
links:
58+
subscriptionStatus:
59+
operationId: getSubscriptionStatus
60+
description: Follow the created subscription status
61+
parameters:
62+
subscriptionId: '$response.body#/id'
63+
/subscriptions/{subscriptionId}:
64+
get:
65+
operationId: getSubscriptionStatus
66+
summary: Get subscription status
67+
tags:
68+
- subscriptions
69+
parameters:
70+
- in: path
71+
name: subscriptionId
72+
required: true
73+
schema:
74+
type: string
75+
responses:
76+
'200':
77+
description: Current subscription status
78+
content:
79+
application/json:
80+
schema:
81+
$ref: '#/components/schemas/SubscriptionStatus'
82+
webhooks:
83+
subscription.updated:
84+
post:
85+
operationId: subscriptionUpdatedWebhook
86+
summary: Subscription updated webhook
87+
requestBody:
88+
required: true
89+
content:
90+
application/json:
91+
schema:
92+
type: object
93+
required:
94+
- event
95+
- data
96+
properties:
97+
event:
98+
type: string
99+
data:
100+
type: object
101+
required:
102+
- id
103+
- state
104+
properties:
105+
id:
106+
type: string
107+
state:
108+
type: string
109+
responses:
110+
'200':
111+
description: Webhook acknowledged
112+
components:
113+
schemas:
114+
SubscriptionAccepted:
115+
type: object
116+
required:
117+
- id
118+
properties:
119+
id:
120+
type: string
121+
status:
122+
type: string
123+
SubscriptionStatus:
124+
type: object
125+
required:
126+
- id
127+
- state
128+
properties:
129+
id:
130+
type: string
131+
state:
132+
type: string

src/libs/AutoSDK.CLI/Commands/HttpCommand.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private async Task HandleAsync(ParseResult parseResult)
104104
var openApiDocument = yaml.GetOpenApiDocument(settings);
105105
var schemas = openApiDocument.GetSchemas(settings);
106106
var operations = openApiDocument.GetOperations(settings, globalSettings: settings, schemas);
107+
var webhookOperations = openApiDocument.GetWebhookOperations(settings, globalSettings: settings, schemas);
107108

108109
// Extract security schemes from document components
109110
var securitySchemes = (openApiDocument.Components?.SecuritySchemes?.Values ?? [])
@@ -143,6 +144,12 @@ private async Task HandleAsync(ParseResult parseResult)
143144
}
144145
}
145146

147+
var webhooksFile = Sources.WebhooksHttpFile(webhookOperations);
148+
if (!webhooksFile.IsEmpty)
149+
{
150+
httpFiles.Add(webhooksFile);
151+
}
152+
146153
Directory.CreateDirectory(output);
147154

148155
if (singleFile)

0 commit comments

Comments
 (0)