Skip to content

Commit 15d420e

Browse files
committed
feat(cli): add DocumentTransformer; swap types package
1 parent 9ed4228 commit 15d420e

14 files changed

+400
-250
lines changed

package-lock.json

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

packages/cli/examples/widgets.rpc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
$schema: "https://spec.openapis.org/oas/3.1/schema/2022-10-07"
2+
openapi: 3.1.0
3+
yarpc: 1.0.0
24
info:
35
title: Widgets API
46
version: 1.0.0

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"eslint-config-prettier": "^8.8.0",
5050
"just-safe-get": "^4.2.0",
5151
"lint-staged": "^13.2.2",
52+
"openapi3-ts": "^4.1.2",
5253
"prettier": "^2.8.8",
5354
"prettier-plugin-organize-imports": "^3.2.2",
5455
"ts-node": "^10.9.1",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Type } from "@sinclair/typebox";
2+
3+
const withoutSymbols = <T extends object>(obj: T): T =>
4+
JSON.parse(JSON.stringify(obj)) as T;
5+
6+
const UserID = Type.String({
7+
$id: "#/components/schemas/UserID",
8+
description: "The user's ID",
9+
});
10+
const WidgetID = Type.String({
11+
$id: "#/components/schemas/WidgetID",
12+
description: "The widget's ID",
13+
});
14+
const WidgetStatus = Type.Union(
15+
[Type.Literal("ACTIVE"), Type.Literal("INACTIVE")],
16+
{ $id: "#/components/schemas/WidgetStatus" }
17+
);
18+
19+
const Widget = Type.Object(
20+
{
21+
id: Type.Ref(WidgetID),
22+
userId: Type.Ref(UserID),
23+
status: Type.Ref(WidgetStatus),
24+
},
25+
{ $id: "#/components/schemas/Widget" }
26+
);
27+
28+
const CreateWidgetInput = Type.Pick(Widget, ["userId", "status"]);
29+
30+
const ListUserWidgetsInput = Type.Object({
31+
userId: Type.Ref(UserID),
32+
status: Type.Optional(Type.Array(Type.Ref(WidgetStatus))),
33+
limit: Type.Optional(Type.Integer()),
34+
});
35+
36+
const ListWidgetsOutput = Type.Object({
37+
items: Type.Array(Type.Ref(Widget)),
38+
pageInfo: Type.Object({
39+
hasNextPage: Type.Boolean(),
40+
lastCursor: Type.Optional(Type.String()),
41+
}),
42+
});
43+
44+
export const schemas = withoutSymbols({
45+
UserID,
46+
WidgetID,
47+
WidgetStatus,
48+
Widget,
49+
CreateWidgetInput,
50+
ListUserWidgetsInput,
51+
ListWidgetsOutput,
52+
});

0 commit comments

Comments
 (0)