Skip to content

Commit

Permalink
feat(types): generate types for callbacks
Browse files Browse the repository at this point in the history
It implied a lot of refactoring. Despite this, I think I could manage to get it backward compatible.
Anyway, I'll test and patch it if not before bumping a new version. It will be a major version
though to avoid any risk.

BREAKING CHANGE: May change some types names

#39
  • Loading branch information
nfroidure committed Oct 18, 2024
1 parent 6eb1222 commit 78a27af
Show file tree
Hide file tree
Showing 6 changed files with 4,626 additions and 2,945 deletions.
103 changes: 103 additions & 0 deletions fixtures/openapi/callback_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"openapi": "3.0.0",
"info": {
"title": "Callback Example",
"version": "1.0.0"
},
"paths": {
"/streams": {
"post": {
"description": "subscribes a client to receive out-of-band data",
"parameters": [
{
"name": "callbackUrl",
"in": "query",
"required": true,
"description": "the location where data will be sent. Must be network accessible\nby the source server\n",
"schema": {
"type": "string",
"format": "uri",
"example": "https://tonys-server.com"
}
}
],
"responses": {
"201": {
"description": "subscription successfully created",
"content": {
"application/json": {
"schema": {
"description": "subscription information",
"required": ["subscriptionId"],
"properties": {
"subscriptionId": {
"description": "this unique identifier allows management of the subscription",
"type": "string",
"example": "2531329f-fb09-4ef7-887e-84e648214436"
}
}
}
}
}
}
},
"callbacks": {
"StreamValidated": {
"$ref": "#/components/callbacks/OnValidated"
},
"onData": {
"{$request.query.callbackUrl}/data": {
"post": {
"requestBody": {
"description": "subscription payload",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"timestamp": {
"type": "string",
"format": "date-time"
},
"userData": {
"type": "string"
}
}
}
}
}
},
"responses": {
"202": {
"description": "Your server implementation should return this HTTP status code\nif the data was received successfully\n"
},
"204": {
"description": "Your server should return this HTTP status code if no longer interested\nin further updates\n"
}
}
}
}
}
}
}
}
},
"components": {
"callbacks": {
"OnValidatedClone": {
"$ref": "#/components/callbacks/OnValidated"
},
"OnValidated": {
"{$request.query.queryUrl}": {
"put": {
"responses": {
"201": {
"description": "Ok, validated!"
}
}
}
}
}
}
}
}
51 changes: 51 additions & 0 deletions fixtures/openapi/parameters_aliasing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"openapi": "3.1.0",
"info": {
"version": "1.0.0",
"title": "Parameters"
},
"paths": {
"/delay": {
"parameters": [
{
"$ref": "#/components/parameters/durationUnit"
}
],
"get": {
"operationId": "getDelay",
"parameters": [
{
"$ref": "#/components/parameters/durationTime"
}
],
"responses": {
"204": {
"description": "Delay expired"
}
}
}
}
},
"components": {
"parameters": {
"durationUnit": {
"in": "query",
"name": "unit",
"required": true,
"schema": {
"type": "string",
"enum": ["s", "m", "h"]
}
},
"durationTime": {
"in": "query",
"name": "duration",
"required": true,
"description": "Duration in milliseconds",
"schema": {
"type": "number"
}
}
}
}
}
6 changes: 5 additions & 1 deletion fixtures/openapi/whook_example_components.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"tags": ["example"],
"parameters": [
{
"$ref": "#/components/parameters/duration"
"$ref": "#/components/parameters/durationClone"
}
],
"responses": {
Expand Down Expand Up @@ -243,6 +243,9 @@
}
},
"requestBodies": {
"EchoBodyClone": {
"$ref": "#/components/requestBodies/EchoBody"
},
"EchoBody": {
"description": "The input sentence",
"required": true,
Expand Down Expand Up @@ -287,6 +290,7 @@
}
},
"parameters": {
"durationClone": { "$ref": "#/components/parameters/duration" },
"duration": {
"in": "query",
"name": "duration",
Expand Down
Loading

0 comments on commit 78a27af

Please sign in to comment.