Created
July 8, 2022 20:33
-
-
Save ragokan/065309ccbe5336edcd0ce8882122ff0b to your computer and use it in GitHub Desktop.
Swagger NestJS Generator With Better Names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { generateApi } = require("swagger-typescript-api"); | |
const path = require("path"); | |
const fs = require("fs"); | |
const output = path.resolve(process.cwd(), "./src/services"); | |
generateApi({ | |
url: "http://localhost:8000/api-json", | |
output, | |
generateClient: true, | |
generateRouteTypes: true, | |
name: "api.ts", | |
httpClientType: "axios", | |
extractRequestBody: true, | |
extractRequestParams: true, | |
moduleNameIndex: 0, | |
patch: true, | |
}).then((v) => { | |
const file = path.resolve(output, "./api.ts"); | |
let data = fs.readFileSync(file).toString(); | |
data = data.replace(/Controller[\w]*/g, (v) => { | |
const replaced = v.replace("Controller", ""); | |
return "Controller" + replaced[0].toLowerCase() + replaced.substring(1); | |
}); | |
data = data.replace(/[\w]*Controller/g, ""); | |
fs.writeFileSync(file, data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment