api.ejs 1.0 KB

12345678910111213141516171819202122232425262728
  1. <%
  2. const { utils, route, config, modelTypes } = it;
  3. const { _, pascalCase, require } = utils;
  4. const apiClassName = pascalCase(route.moduleName);
  5. const routes = route.routes;
  6. const dataContracts = _.map(modelTypes, "name");
  7. %>
  8. <% if (config.httpClientType === config.constants.HTTP_CLIENT.AXIOS) { %> import { AxiosRequestConfig, AxiosResponse } from "axios"; <% } %>
  9. import { HttpClient, RequestParams, ContentType, HttpResponse } from "./<%~ config.fileNames.httpClient %>";
  10. <% if (dataContracts.length) { %>
  11. import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
  12. <% } %>
  13. export class <%= apiClassName %>Api<SecurityDataType = unknown><% if (!config.singleHttpClient) { %> extends HttpClient<SecurityDataType> <% } %> {
  14. <% if(config.singleHttpClient) { %>
  15. http: HttpClient<SecurityDataType>;
  16. constructor (http: HttpClient<SecurityDataType>) {
  17. this.http = http;
  18. }
  19. <% } %>
  20. <% routes.forEach((route) => { %>
  21. <%~ includeFile('./procedure-call.ejs', { ...it, route }) %>
  22. <% }) %>
  23. }