-
Notifications
You must be signed in to change notification settings - Fork 1
/
types-as-schema.config.ts
59 lines (57 loc) · 1.68 KB
/
types-as-schema.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Configuration, generateTypescriptOfFunctionParameter, generateTypescriptOfType } from "./dist/core"
const config: Configuration = {
files: ['demo/cases.ts', 'demo/case2.ts'],
jsonSchemaOutputDirectory: 'demo/',
debugOutputPath: 'demo/debug.json',
protobufOutputPath: 'demo/cases.proto',
swagger: {
outputPath: 'demo/cases.swagger.json',
base: {
"info": {
"title": "Sample API",
"description": "API description in Markdown.",
"version": "1.0.0"
},
"host": "api.example.com",
"basePath": "/v1",
"schemes": [
"https"
]
},
},
plugins: [
(typeDeclarations) => {
const result = []
for (const declaration of typeDeclarations) {
if (declaration.kind === 'function') {
const parameters = [
`functionName: '${declaration.name}'`,
...declaration.parameters.map((m) => generateTypescriptOfFunctionParameter(m, (t) => {
if (declaration.typeParameters && t.kind === 'reference') {
const typeParameter = declaration.typeParameters.find((p) => p.name === t.referenceName)
if (typeParameter?.constraint) {
return generateTypescriptOfType(typeParameter.constraint)
}
}
return
})),
]
result.push(` (${parameters.join(', ')}): string`)
}
}
const content = `type TestType = {
${result.join('\n')}
}
`
return [
{
path: 'demo/custom.ts',
content,
},
]
},
],
typescriptOutputPath: 'demo/typescript.ts',
markdownOutputPath: 'demo/cases.md',
}
export default config