-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path02-multiple-specs.ts
37 lines (34 loc) · 1.01 KB
/
02-multiple-specs.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
import { generate } from '@devexperts/swagger-codegen-ts';
import * as path from 'path';
import { serialize as serializeOpenAPI3 } from '@devexperts/swagger-codegen-ts/dist/language/typescript/3.0';
import { OpenapiObjectCodec } from '@devexperts/swagger-codegen-ts/dist/schema/3.0/openapi-object';
import { array, either, taskEither } from 'fp-ts';
import { pipe } from 'fp-ts/function';
const cwd = path.resolve(__dirname, '../../test/specs/3.0');
const specs = ['nested/link-example.yaml', 'demo.yml'];
// Create a task for each input spec file
const tasks = pipe(
specs,
array.map(spec =>
generate({
cwd,
spec: path.resolve(cwd, spec),
out: path.resolve(__dirname, '../out'),
language: serializeOpenAPI3,
decoder: OpenapiObjectCodec,
}),
),
// Notice how the sequence operation is used to run multiple tasks in parallel
taskEither.sequenceArray,
);
tasks().then(
either.fold(
error => {
console.error(error);
process.exit(1);
},
() => {
console.log('Generated successfully');
},
),
);