gen-api.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { generateApi } = require('swagger-typescript-api')
  2. const path = require('path')
  3. // const fs = require('fs')
  4. const apis = [
  5. {
  6. output: path.resolve(__dirname, '../src/api/admin'),
  7. url: 'http://localhost:8000/admin/swagger/admin/swagger.json',
  8. },
  9. ]
  10. apis?.forEach((api, index) => {
  11. setTimeout(() => {
  12. generateApi({
  13. output: api.output,
  14. templates: path.resolve(__dirname, './templates'),
  15. url: api.url,
  16. httpClientType: 'axios',
  17. modular: true,
  18. cleanOutput: false,
  19. moduleNameIndex: 2, // 0 api, 1 api htt-client data-contracts, 2 apis htt-client data-contracts
  20. moduleNameFirstTag: true, //apis htt-client data-contracts
  21. unwrapResponseData: true,
  22. generateUnionEnums: true,
  23. defaultResponseType: 'AxiosResponse',
  24. // hooks: {
  25. // onFormatTypeName: (typeName, rawTypeName, schemaType) => {
  26. // },
  27. // }
  28. })
  29. .then((r) => {
  30. // files.forEach(({ content, name }) => {
  31. // fs.writeFile(path, content);
  32. // });
  33. })
  34. .catch((e) => console.error(e))
  35. }, index * 1500)
  36. })