gen-admin-api.js 1022 B

12345678910111213141516171819202122232425262728293031323334353637
  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: import.meta.env.VITE_API_URL + '/swagger/admin/swagger.json',
  8. },
  9. ]
  10. apis?.forEach((api) => {
  11. generateApi({
  12. output: api.output,
  13. templates: path.resolve(__dirname, './templates'),
  14. url: api.url,
  15. httpClientType: 'axios',
  16. modular: true,
  17. cleanOutput: true,
  18. moduleNameIndex: 2, // 0 api, 1 api htt-client data-contracts, 2 apis htt-client data-contracts
  19. moduleNameFirstTag: true, //apis htt-client data-contracts
  20. unwrapResponseData: true,
  21. generateUnionEnums: true,
  22. defaultResponseType: 'AxiosResponse',
  23. // hooks: {
  24. // onFormatTypeName: (typeName, rawTypeName, schemaType) => {
  25. // },
  26. // }
  27. })
  28. .then((r) => {
  29. // files.forEach(({ content, name }) => {
  30. // fs.writeFile(path, content);
  31. // });
  32. })
  33. .catch((e) => console.error(e))
  34. })