Skip to content

Commit ec2346e

Browse files
authored
feat: Openapi (swagger) ui automatically generated based on validators (#19)
* Openapi wip * feat: Openapi (swagger) ui automatically generated based on validators * Add one test * fix: Multiple bufixes * Updates and fixes * chore: Use standard version of tsd * Fix tests * Fix smoke test * Fix tests * /* istanbul ignore next */ * More tests
1 parent 1a6b2c2 commit ec2346e

35 files changed

+4503
-119
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ rollup.config.js
55
dist
66
coverage
77
__tests__/bench.js
8+
acceptance_tests

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"project": "tsconfig.eslint.json"
55
},
66
"extends": ["plugin:@typeofweb/recommended"],
7+
"rules": {
8+
"import/dynamic-import-chunkname": "off"
9+
},
710
"overrides": [
811
{
912
"files": ["__tests__/**/*.ts"],

.github/workflows/coverage.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v2
1616
with:
17-
fetch-depth: 1
17+
fetch-depth: 0
1818

1919
- name: Read .nvmrc
2020
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
@@ -48,3 +48,11 @@ jobs:
4848
4949
- name: Collect coverage
5050
run: curl -s https://codecov.io/bash | bash
51+
52+
- name: Smoke test
53+
run: |
54+
yarn link
55+
cd acceptance_tests
56+
yarn install --frozen-lockfile
57+
yarn link "@typeofweb/server"
58+
yarn build

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ coverage/
44
.clinic/
55
.vscode/snipsnap.code-snippets
66
*.log
7+
.rollup.cache
8+
!acceptance_tests/dist

.vscode/settings.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"editor.formatOnSave": true,
33
"editor.defaultFormatter": "esbenp.prettier-vscode",
44
"typescript.tsdk": "node_modules/typescript/lib",
5-
"eslint.packageManager": "yarn",
6-
"eslint.run": "onSave",
7-
"editor.codeActionsOnSave": {
8-
"source.fixAll": true
9-
}
5+
"eslint.packageManager": "yarn"
6+
// "eslint.run": "onSave",
7+
// "editor.codeActionsOnSave": {
8+
// "source.fixAll": true
9+
// }
1010
}
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`open api generator getOpenApiForRoutes should generate schema for whole app 1`] = `
4+
Object {
5+
"definitions": Object {
6+
"GetUsersByUserIdInvoicesParams": Object {
7+
"additionalProperties": false,
8+
"properties": Object {
9+
"userId": Object {
10+
"type": "string",
11+
},
12+
},
13+
"required": Array [
14+
"userId",
15+
],
16+
"type": "object",
17+
},
18+
"GetUsersByUserIdInvoicesResponse": Object {
19+
"items": Object {
20+
"additionalProperties": false,
21+
"properties": Object {
22+
"id": Object {
23+
"type": "string",
24+
},
25+
"total": Object {
26+
"type": "number",
27+
},
28+
},
29+
"required": Array [
30+
"id",
31+
"total",
32+
],
33+
"type": "object",
34+
},
35+
"type": "array",
36+
},
37+
"PostUsersByUserIdInvoicesParams": Object {
38+
"additionalProperties": false,
39+
"properties": Object {
40+
"userId": Object {
41+
"type": "string",
42+
},
43+
},
44+
"required": Array [
45+
"userId",
46+
],
47+
"type": "object",
48+
},
49+
"PostUsersByUserIdInvoicesPayload": Object {
50+
"additionalProperties": false,
51+
"properties": Object {
52+
"id": Object {
53+
"type": "string",
54+
},
55+
"item": Object {
56+
"additionalProperties": false,
57+
"properties": Object {
58+
"price": Object {
59+
"type": "number",
60+
},
61+
},
62+
"required": Array [
63+
"price",
64+
],
65+
"type": "object",
66+
},
67+
},
68+
"required": Array [
69+
"id",
70+
"item",
71+
],
72+
"type": "object",
73+
},
74+
"PostUsersByUserIdInvoicesQuery": Object {
75+
"additionalProperties": false,
76+
"properties": Object {
77+
"category": Object {
78+
"anyOf": Array [
79+
Object {
80+
"const": "html",
81+
"type": "string",
82+
},
83+
Object {
84+
"const": "css",
85+
"type": "string",
86+
},
87+
],
88+
},
89+
"isFun": Object {
90+
"type": "boolean",
91+
},
92+
"search": Object {
93+
"type": "string",
94+
},
95+
},
96+
"required": Array [
97+
"isFun",
98+
"search",
99+
"category",
100+
],
101+
"type": "object",
102+
},
103+
"PostUsersByUserIdInvoicesResponse": Object {
104+
"items": Object {
105+
"additionalProperties": false,
106+
"properties": Object {
107+
"id": Object {
108+
"type": "string",
109+
},
110+
"total": Object {
111+
"type": "number",
112+
},
113+
},
114+
"required": Array [
115+
"id",
116+
"total",
117+
],
118+
"type": "object",
119+
},
120+
"type": "array",
121+
},
122+
"PutUsersByUserIdInvoicesParams": Object {
123+
"additionalProperties": false,
124+
"properties": Object {
125+
"userId": Object {
126+
"type": "string",
127+
},
128+
},
129+
"required": Array [
130+
"userId",
131+
],
132+
"type": "object",
133+
},
134+
},
135+
"info": Object {
136+
"title": "Swagger",
137+
"version": "1.1.1",
138+
},
139+
"paths": Object {
140+
"/users/{userId}/invoices": Object {
141+
"put": Object {
142+
"operationId": "PutUsersByUserIdInvoices",
143+
"parameters": Array [
144+
Object {
145+
"in": "path",
146+
"name": "userId",
147+
"required": true,
148+
"type": "string",
149+
},
150+
],
151+
"responses": Object {
152+
"default": Object {
153+
"description": "Unknown response",
154+
},
155+
},
156+
},
157+
},
158+
},
159+
"swagger": "2.0",
160+
}
161+
`;
162+
163+
exports[`open api generator routeConfigToOpenApiPathsDefinitions should generate single schema 1`] = `
164+
Object {
165+
"definitions": Object {
166+
"PostUsersByUserIdInvoicesParams": Object {
167+
"additionalProperties": false,
168+
"properties": Object {
169+
"userId": Object {
170+
"type": "string",
171+
},
172+
},
173+
"required": Array [
174+
"userId",
175+
],
176+
"type": "object",
177+
},
178+
"PostUsersByUserIdInvoicesPayload": Object {
179+
"additionalProperties": false,
180+
"properties": Object {
181+
"id": Object {
182+
"type": "string",
183+
},
184+
"item": Object {
185+
"additionalProperties": false,
186+
"properties": Object {
187+
"price": Object {
188+
"type": "number",
189+
},
190+
},
191+
"required": Array [
192+
"price",
193+
],
194+
"type": "object",
195+
},
196+
},
197+
"required": Array [
198+
"id",
199+
"item",
200+
],
201+
"type": "object",
202+
},
203+
"PostUsersByUserIdInvoicesQuery": Object {
204+
"additionalProperties": false,
205+
"properties": Object {
206+
"category": Object {
207+
"anyOf": Array [
208+
Object {
209+
"const": "html",
210+
"type": "string",
211+
},
212+
Object {
213+
"const": "css",
214+
"type": "string",
215+
},
216+
],
217+
},
218+
"isFun": Object {
219+
"type": "boolean",
220+
},
221+
"search": Object {
222+
"type": "string",
223+
},
224+
},
225+
"required": Array [
226+
"isFun",
227+
"search",
228+
"category",
229+
],
230+
"type": "object",
231+
},
232+
"PostUsersByUserIdInvoicesResponse": Object {
233+
"items": Object {
234+
"additionalProperties": false,
235+
"properties": Object {
236+
"id": Object {
237+
"type": "string",
238+
},
239+
"total": Object {
240+
"type": "number",
241+
},
242+
},
243+
"required": Array [
244+
"id",
245+
"total",
246+
],
247+
"type": "object",
248+
},
249+
"type": "array",
250+
},
251+
},
252+
"paths": Object {
253+
"/users/{userId}/invoices": Object {
254+
"post": Object {
255+
"operationId": "PostUsersByUserIdInvoices",
256+
"parameters": Array [
257+
Object {
258+
"in": "path",
259+
"name": "userId",
260+
"required": true,
261+
"type": "string",
262+
},
263+
Object {
264+
"in": "query",
265+
"name": "isFun",
266+
"required": true,
267+
"type": "boolean",
268+
},
269+
Object {
270+
"in": "query",
271+
"name": "search",
272+
"required": true,
273+
"type": "string",
274+
},
275+
Object {
276+
"enum": Array [
277+
"html",
278+
"css",
279+
],
280+
"in": "query",
281+
"name": "category",
282+
"required": true,
283+
"type": "string",
284+
},
285+
Object {
286+
"in": "body",
287+
"name": "payload",
288+
"schema": Object {
289+
"$ref": "#/definitions/PostUsersByUserIdInvoicesPayload",
290+
},
291+
},
292+
],
293+
"responses": Object {
294+
"default": Object {
295+
"description": "PostUsersByUserIdInvoicesResponse",
296+
"schema": Object {
297+
"$ref": "#/definitions/PostUsersByUserIdInvoicesResponse",
298+
},
299+
},
300+
},
301+
},
302+
},
303+
},
304+
}
305+
`;

0 commit comments

Comments
 (0)