Skip to content

Commit cd547e2

Browse files
committed
v1.2.0 🚀 - Add more route metadata support
1 parent 48f9da1 commit cd547e2

File tree

8 files changed

+108
-9
lines changed

8 files changed

+108
-9
lines changed

__tests__/Rest_test.res

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,3 +1332,72 @@ asyncTest("Sends response without a data", async t => {
13321332
let client = Rest.client(~baseUrl="http://localhost:3000", ~fetcher=args => app->inject(args))
13331333
t->Assert.deepEqual(await client.call(getHeight, ()), ())
13341334
})
1335+
1336+
asyncTest("Graphql example https://x.com/ChShersh/status/1880968521200603364", async t => {
1337+
let _issuesQuery = Rest.route(() => {
1338+
path: "",
1339+
method: Post,
1340+
variables: s => {
1341+
let _ = s.header("Authorization", S.literal(`bearer ${%raw(`process.env.GITHUB_TOKEN`)}`))
1342+
let _ = s.header("User-Agent", S.literal("chshersh/github-tui"))
1343+
s.field(
1344+
"query",
1345+
S.string->S.transform(
1346+
_ => {
1347+
serializer: data =>
1348+
`query {
1349+
repository(owner: "${data["owner"]}", name: "${data["repo"]}") {
1350+
issues(first: 2, states: [OPEN], orderBy: {field: CREATED_AT, direction: DESC}) {
1351+
nodes {
1352+
number
1353+
title
1354+
author {
1355+
login
1356+
}
1357+
}
1358+
}
1359+
}
1360+
}`,
1361+
},
1362+
),
1363+
)
1364+
},
1365+
responses: [
1366+
s =>
1367+
s.data(
1368+
S.object(
1369+
s =>
1370+
s.nested("data").nested("repository").nested("issues").fieldOr(
1371+
"nodes",
1372+
S.array(
1373+
S.object(
1374+
s =>
1375+
{
1376+
"number": s.field("number", S.int),
1377+
"title": s.field("title", S.string),
1378+
"author": s.nested("author").field("login", S.string),
1379+
},
1380+
),
1381+
),
1382+
[],
1383+
),
1384+
),
1385+
),
1386+
],
1387+
})
1388+
// let _issues = await Rest.fetch(
1389+
// _issuesQuery,
1390+
// "https://api.github.com/graphql",
1391+
// {
1392+
// "owner": "ChShersh",
1393+
// "repo": "status",
1394+
// },
1395+
// )
1396+
1397+
t->Assert.pass
1398+
1399+
// let app = Fastify.make()
1400+
// app->Fastify.route(getHeight, async () => ())
1401+
// let client = Rest.client(~baseUrl="http://localhost:3000", ~fetcher=args => app->inject(args))
1402+
// t->Assert.deepEqual(await client.call(getHeight, ()), ())
1403+
})

__tests__/Swagger_test.res

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ asyncTest("Route with all meta info and deprecated", async t => {
280280
description: "This is a description",
281281
summary: "This is a summary",
282282
deprecated: true,
283+
tags: ["Foo", "Bar"],
284+
externalDocs: {
285+
description: "External docs",
286+
url: "https://example.com",
287+
},
288+
operationId: "getNoop",
283289
path: "/",
284290
method: Post,
285291
variables: _ => (),
@@ -304,6 +310,12 @@ asyncTest("Route with all meta info and deprecated", async t => {
304310
"deprecated": true,
305311
"summary": "This is a summary",
306312
"description": "This is a description",
313+
"tags": ["Foo", "Bar"],
314+
"externalDocs": {
315+
"description": "External docs",
316+
"url": "https://example.com",
317+
},
318+
"operationId": "getNoop",
307319
"responses": {
308320
"default": {
309321
"description": "Default Response",

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rescript-rest",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "😴 ReScript RPC-like client, contract, and server implementation for a pure REST API",
55
"keywords": [
66
"rest",
@@ -35,7 +35,7 @@
3535
]
3636
},
3737
"dependencies": {
38-
"rescript-json-schema": "^7.0.0",
38+
"rescript-json-schema": "^7.1.0",
3939
"rescript-openapi": "^0.4.0"
4040
},
4141
"devDependencies": {

src/Fastify.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ type routeSchema = {
175175
summary?: string,
176176
deprecated?: bool,
177177
response?: dict<routeResponse>,
178+
operationId?: string,
179+
tags?: array<string>,
180+
externalDocs?: OpenAPI.externalDocumentation,
178181
}
179182

180183
type routeOptions = {
@@ -238,6 +241,9 @@ let route = (app: t, restRoute: Rest.route<'request, 'response>, fn) => {
238241
description: ?definition.description,
239242
summary: ?definition.summary,
240243
deprecated: ?definition.deprecated,
244+
tags: ?definition.tags,
245+
operationId: ?definition.operationId,
246+
externalDocs: ?definition.externalDocs,
241247
response: routeSchemaResponses,
242248
}
243249
let routeOptions = {

src/Fastify.res.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Rest.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ type definition<'variables, 'response> = {
242242
summary?: string,
243243
description?: string,
244244
deprecated?: bool,
245+
operationId?: string,
246+
tags?: array<string>,
247+
externalDocs?: OpenAPI.externalDocumentation,
245248
}
246249

247250
type routeParams<'variables, 'response> = {

src/Rest.resi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ type definition<'variables, 'response> = {
134134
summary?: string,
135135
description?: string,
136136
deprecated?: bool,
137+
operationId?: string,
138+
tags?: array<string>,
139+
externalDocs?: OpenAPI.externalDocumentation,
137140
}
138141

139142
type route<'variables, 'response>

0 commit comments

Comments
 (0)