-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-api.js
More file actions
34 lines (27 loc) · 900 Bytes
/
generate-api.js
File metadata and controls
34 lines (27 loc) · 900 Bytes
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
require('dotenv').config()
const fs = require('fs')
const path = require('path')
const axios = require('axios')
const yaml = require('js-yaml')
const { generateApi } = require('swagger-typescript-api')
if (!process.env.OPEN_API_SCHEMA_URL) {
throw new Error('OPEN_API_SCHEMA_URL env variable not defined')
}
const prettier = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '.prettierrc'))
)
// eslint-disable-next-line no-console
console.log('Api schema: fetching...')
axios.get(process.env.OPEN_API_SCHEMA_URL).then((res) => {
const schema = yaml.load(res.data)
// eslint-disable-next-line no-console
console.log('Api schema: successful fetched!')
generateApi({
name: '__generated-api.ts',
output: path.resolve(__dirname, 'services'),
spec: schema,
httpClientType: 'axios',
unwrapResponseData: true,
prettier,
})
})