swaggie 1.8.8 → 1.9.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -179,7 +179,7 @@ import Axios, { AxiosPromise } from 'axios';
179
179
 
180
180
  const axios = Axios.create({
181
181
  baseURL: '/api',
182
- paramsSerializer: (params) =>
182
+ paramsSerializer: (params: any) =>
183
183
  encodeParams(params, null, {
184
184
  allowDots: true,
185
185
  arrayFormat: 'repeat',
@@ -11,6 +11,7 @@ var _swagger = require('../swagger');
11
11
  var _utils = require('../utils/utils');
12
12
  var _templateEngine = require('../utils/templateEngine');
13
13
  var _createBarrel = require('./createBarrel');
14
+ var _header = require('./header');
14
15
 
15
16
 
16
17
  var _jsDocs = require('./jsDocs');
@@ -25,7 +26,7 @@ var _jsDocs = require('./jsDocs');
25
26
  const operations = _swagger.getOperations.call(void 0, spec);
26
27
  const groups = _utils.groupOperationsByGroupName.call(void 0, operations);
27
28
  const servicePrefix = options.servicePrefix;
28
- let result = _templateEngine.renderFile.call(void 0, 'baseClient.ejs', {
29
+ let result = _header.FILE_HEADER + _templateEngine.renderFile.call(void 0, 'baseClient.ejs', {
29
30
  servicePrefix,
30
31
  baseUrl: options.baseUrl,
31
32
  ...options.queryParamsSerialization,
@@ -12,4 +12,5 @@
12
12
  '// </auto-generated>\n' +
13
13
  '//----------------------\n' +
14
14
  '// ReSharper disable InconsistentNaming\n' +
15
- '// deno-lint-ignore-file\n\n'; exports.FILE_HEADER = FILE_HEADER;
15
+ '// deno-lint-ignore-file\n' +
16
+ '// biome-ignore-all lint: auto-generated code\n\n'; exports.FILE_HEADER = FILE_HEADER;
@@ -4,45 +4,45 @@
4
4
  const BUNDLED_TEMPLATES = {
5
5
  "axios": {
6
6
  "barrel.ejs": "\n/**\n * Serializes a params object into a query string that is compatible with different REST APIs.\n * Implementation from: https://github.com/suhaotian/xior/blob/main/src/utils.ts\n * Kudos to @suhaotian for the original implementation\n */\nfunction encodeParams<T = any>(\n params: T,\n parentKey: string | null = null,\n options?: {\n allowDots?: boolean;\n serializeDate?: (value: Date) => string;\n arrayFormat?: 'indices' | 'repeat' | 'brackets';\n }\n): string {\n if (params === undefined || params === null) return '';\n const encodedParams: string[] = [];\n const paramsIsArray = Array.isArray(params);\n const { arrayFormat, allowDots, serializeDate } = options || {};\n\n const getKey = (key: string) => {\n if (allowDots && !paramsIsArray) return `.${key}`;\n if (paramsIsArray) {\n if (arrayFormat === 'brackets') {\n return '[]';\n }\n if (arrayFormat === 'repeat') {\n return '';\n }\n }\n return `[${key}]`;\n };\n\n for (const key in params) {\n if (Object.prototype.hasOwnProperty.call(params, key)) {\n let value = (params as any)[key];\n if (value !== undefined) {\n const encodedKey = parentKey ? `${parentKey}${getKey(key)}` : (key as string);\n\n // biome-ignore lint/suspicious/noGlobalIsNan: <explanation>\n if (!isNaN(value) && value instanceof Date) {\n value = serializeDate ? serializeDate(value) : value.toISOString();\n }\n if (typeof value === 'object') {\n // If the value is an object or array, recursively encode its contents\n const result = encodeParams(value, encodedKey, options);\n if (result !== '') encodedParams.push(result);\n } else {\n // Otherwise, encode the key-value pair\n encodedParams.push(`${encodeURIComponent(encodedKey)}=${encodeURIComponent(value)}`);\n }\n }\n }\n }\n\n return encodedParams.join('&');\n}\n\n",
7
- "baseClient.ejs": "/* tslint:disable */\n/* eslint-disable */\n//----------------------\n// <auto-generated>\n// Generated using Swaggie (https://github.com/yhnavein/swaggie)\n// Please avoid doing any manual changes in this file\n// </auto-generated>\n//----------------------\n// ReSharper disable InconsistentNaming\n// deno-lint-ignore-file\n\nimport Axios, { type AxiosPromise, type AxiosRequestConfig } from \"axios\";\n\nexport const axios = Axios.create({\n baseURL: '<%= it.baseUrl || '' %>',\n paramsSerializer: (params: any) =>\n encodeParams(params, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n});\n\n",
7
+ "baseClient.ejs": "import Axios, { type AxiosPromise, type AxiosRequestConfig } from \"axios\";\n\nexport const axios = Axios.create({\n baseURL: '<%= it.baseUrl || '' %>',\n paramsSerializer: (params: any) =>\n encodeParams(params, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n});\n\n",
8
8
  "client.ejs": "export const <%= it.camelCaseName %>Client = {\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n<% }); %>\n};\n\n",
9
9
  "operation.ejs": "<%~ it.jsDocs %>\n\n <%= it.name %>(<% it.parameters.forEach((parameter) => { %>\n<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\n$config?: AxiosRequestConfig\n ): AxiosPromise<<%~ it.returnType %>> {\n const url = `<%= it.url %>`;\n\n return axios.request<<%~ it.returnType %>>({\n url: url,\n method: '<%= it.method %>',\n<% if(it.body) { %>\n<% if(it.body.contentType === 'urlencoded') { %>\n data: new URLSearchParams(<%= it.body.name %> as any),\n<% } else { %>\n data: <%= it.body.name %>,\n<% } %>\n<% } %>\n<% if(it.query && it.query.length > 0) { %>\n params: {\n <% it.query.forEach((parameter) => { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>\n },\n<% } %>\n<% if(it.headers && it.headers.length > 0) { %>\n headers: {\n <% it.headers.forEach((parameter) => { %>\n <% if (parameter.value) { %>\n '<%= parameter.originalName %>': '<%= parameter.value %>',\n <% } else { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% } %>\n <% }); %>\n},\n<% } %>\n ...$config,\n });\n },\n"
10
10
  },
11
11
  "fetch": {
12
12
  "barrel.ejs": "\n/**\n * Serializes a params object into a query string that is compatible with different REST APIs.\n * Implementation from: https://github.com/suhaotian/xior/blob/main/src/utils.ts\n * Kudos to @suhaotian for the original implementation\n */\nfunction encodeParams<T = any>(\n params: T,\n parentKey: string | null = null,\n options?: {\n allowDots?: boolean;\n serializeDate?: (value: Date) => string;\n arrayFormat?: 'indices' | 'repeat' | 'brackets';\n }\n): string {\n if (params === undefined || params === null) return '';\n const encodedParams: string[] = [];\n const paramsIsArray = Array.isArray(params);\n const { arrayFormat, allowDots, serializeDate } = options || {};\n\n const getKey = (key: string) => {\n if (allowDots && !paramsIsArray) return `.${key}`;\n if (paramsIsArray) {\n if (arrayFormat === 'brackets') {\n return '[]';\n }\n if (arrayFormat === 'repeat') {\n return '';\n }\n }\n return `[${key}]`;\n };\n\n for (const key in params) {\n if (Object.prototype.hasOwnProperty.call(params, key)) {\n let value = (params as any)[key];\n if (value !== undefined) {\n const encodedKey = parentKey ? `${parentKey}${getKey(key)}` : (key as string);\n\n // biome-ignore lint/suspicious/noGlobalIsNan: <explanation>\n if (!isNaN(value) && value instanceof Date) {\n value = serializeDate ? serializeDate(value) : value.toISOString();\n }\n if (typeof value === 'object') {\n // If the value is an object or array, recursively encode its contents\n const result = encodeParams(value, encodedKey, options);\n if (result !== '') encodedParams.push(result);\n } else {\n // Otherwise, encode the key-value pair\n encodedParams.push(`${encodeURIComponent(encodedKey)}=${encodeURIComponent(value)}`);\n }\n }\n }\n }\n\n return encodedParams.join('&');\n}\n\n",
13
- "baseClient.ejs": "/* tslint:disable */\n/* eslint-disable */\n//----------------------\n// <auto-generated>\n// Generated using Swaggie (https://github.com/yhnavein/swaggie)\n// Please avoid doing any manual changes in this file\n// </auto-generated>\n//----------------------\n// ReSharper disable InconsistentNaming\n// deno-lint-ignore-file\n\nexport const defaults = {\n baseUrl: '<%= it.baseUrl || '' %>',\n paramsSerializer: (params: any) =>\n encodeParams(params, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n};\n\n",
13
+ "baseClient.ejs": "export const defaults = {\n baseUrl: '<%= it.baseUrl || '' %>',\n paramsSerializer: (params: any) =>\n encodeParams(params, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n};\n\n",
14
14
  "client.ejs": "export const <%= it.camelCaseName %>Client = {\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n<% }); %>\n};\n",
15
15
  "operation.ejs": "<%~ it.jsDocs %>\n\n <%= it.name %>(<% it.parameters.forEach((parameter) => { %>\n<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\n$config?: RequestInit\n ): Promise<<%~ it.returnType %>> {\n const url = `${defaults.baseUrl}<%= it.url %>?<%\n if(it.query && it.query.length > 0) { %>${defaults.paramsSerializer({<%\n it.query.forEach((parameter) => { %>\n'<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>})}<% } %>`;\n\n<% if(it.headers && it.headers.length > 0) { %>\n const { headers: $configHeaders, ...$configRest } = $config ?? {};\n const headers = new Headers({\n<% it.headers.forEach((parameter) => { %>\n<% if (parameter.value) { %>\n '<%= parameter.originalName %>': '<%= parameter.value %>',\n<% } else { %>\n '<%= parameter.originalName %>': <%= parameter.name %> ?? '',\n<% } %>\n<% }); %>\n });\n if ($configHeaders) {\n new Headers($configHeaders).forEach((value, key) => headers.set(key, value));\n }\n\n return fetch(url, {\n method: '<%= it.method %>',\n<% if(it.body) { %>\n<% if(it.body.contentType === 'json') { %>\n body: JSON.stringify(<%= it.body.name %>),\n<% } else if(it.body.contentType === 'urlencoded') { %>\n body: new URLSearchParams(<%= it.body.name %> as any),\n<% } else { %>\n body: <%= it.body.name %>,\n<% } %>\n<% } %>\n headers,\n ...$configRest,\n })\n<% } else { %>\n return fetch(url, {\n method: '<%= it.method %>',\n<% if(it.body) { %>\n<% if(it.body.contentType === 'json') { %>\n body: JSON.stringify(<%= it.body.name %>),\n<% } else if(it.body.contentType === 'urlencoded') { %>\n body: new URLSearchParams(<%= it.body.name %> as any),\n<% } else { %>\n body: <%= it.body.name %>,\n<% } %>\n<% } %>\n ...$config,\n })\n<% } %>\n<% if(it.responseContentType === 'binary') { %>\n .then((response) => response.blob() as Promise<<%~ it.returnType %>>);\n<% } else if(it.responseContentType === 'text') { %>\n .then((response) => response.text() as Promise<<%~ it.returnType %>>);\n<% } else { %>\n .then((response) => response.json() as Promise<<%~ it.returnType %>>);\n<% } %>\n },\n"
16
16
  },
17
17
  "ng1": {
18
18
  "barrel.ejs": "export class ApiServices {\n public static bootstrap(moduleName: string, baseUrl: string) {\n angular\n .module(moduleName)\n .constant('Api<%= it.servicePrefix -%>BaseUrl', baseUrl)\n<% it.clients.forEach((client) => { %>\n .service('<%= client.fileName %>Service', <%= client.fileName %>Service)\n<% }); %>;\n }\n}\n\nfunction serializeQueryParam(obj: any, property: string): string {\n if (obj === null || obj === undefined || obj === '') {\n return '';\n } else if (obj instanceof Date) {\n return property + '=' + encodeURIComponent(obj.toJSON());\n } else if (Array.isArray(obj)) {\n return Object.values(obj)\n .map(value => `${property}[]=${value}`)\n .join('&');\n } else if (typeof obj !== 'object') {\n return property + '=' + encodeURIComponent(obj);\n } else if (typeof obj === 'object') {\n return Object.keys(obj)\n .filter(key => !!serializeQueryParam(obj[key], property + '.' + key))\n .reduce(\n (a: any, b) =>\n a.push(serializeQueryParam(obj[b], property + '.' + b)) && a,\n []\n )\n .join('&');\n } else {\n return '';\n }\n}\n",
19
- "baseClient.ejs": "/* tslint:disable */\n/* eslint-disable */\n//----------------------\n// <auto-generated>\n// Generated using Swaggie (https://github.com/yhnavein/swaggie)\n// Please avoid doing any manual changes in this file\n// </auto-generated>\n//----------------------\n// ReSharper disable InconsistentNaming\n// deno-lint-ignore-file\n\nimport type { IHttpService, IRequestShortcutConfig, IPromise } from 'angular';\n\nabstract class BaseService {\n constructor(protected readonly $http: IHttpService, public baseUrl: string) { }\n\n protected $get<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<T> {\n return this.$http.get(this.baseUrl + url, config).then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $getAll<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<T[]> {\n return this.$http.get(this.baseUrl + url, config).then((response: any) => {\n return this.processMany<T>(response);\n });\n }\n\n protected $delete<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .delete(this.baseUrl + url, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $head<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http.head(this.baseUrl + url, config).then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $jsonp<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .jsonp(this.baseUrl + url, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $post<T>(\n url: string,\n data: any,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .post(this.baseUrl + url, data, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $put<T>(\n url: string,\n data: any,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .put(this.baseUrl + url, data, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $patch<T>(\n url: string,\n data: any,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .patch(this.baseUrl + url, data, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected processSingle<T>(response: any): T {\n var data = response.data;\n var status = response.status;\n\n if (status >= 200 && status <= 299) {\n return data;\n } else {\n throw 'error_no_callback_for_the_received_http_status';\n }\n }\n\n protected processMany<T>(response: any): T[] {\n var data = response.data;\n var status = response.status;\n\n if (status >= 200 && status <= 299) {\n return data;\n } else {\n throw 'error_no_callback_for_the_received_http_status';\n }\n }\n}\n\n",
19
+ "baseClient.ejs": "import type { IHttpService, IRequestShortcutConfig, IPromise } from 'angular';\n\nabstract class BaseService {\n constructor(protected readonly $http: IHttpService, public baseUrl: string) { }\n\n protected $get<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<T> {\n return this.$http.get(this.baseUrl + url, config).then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $getAll<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<T[]> {\n return this.$http.get(this.baseUrl + url, config).then((response: any) => {\n return this.processMany<T>(response);\n });\n }\n\n protected $delete<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .delete(this.baseUrl + url, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $head<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http.head(this.baseUrl + url, config).then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $jsonp<T>(\n url: string,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .jsonp(this.baseUrl + url, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $post<T>(\n url: string,\n data: any,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .post(this.baseUrl + url, data, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $put<T>(\n url: string,\n data: any,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .put(this.baseUrl + url, data, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected $patch<T>(\n url: string,\n data: any,\n config?: IRequestShortcutConfig\n ): IPromise<any> {\n return this.$http\n .patch(this.baseUrl + url, data, config)\n .then((response: any) => {\n return this.processSingle<T>(response);\n });\n }\n\n protected processSingle<T>(response: any): T {\n var data = response.data;\n var status = response.status;\n\n if (status >= 200 && status <= 299) {\n return data;\n } else {\n throw 'error_no_callback_for_the_received_http_status';\n }\n }\n\n protected processMany<T>(response: any): T[] {\n var data = response.data;\n var status = response.status;\n\n if (status >= 200 && status <= 299) {\n return data;\n } else {\n throw 'error_no_callback_for_the_received_http_status';\n }\n }\n}\n\n",
20
20
  "client.ejs": "export class <%= it.clientName -%>Service extends BaseService {\n /* @ngInject */\n constructor($http: IHttpService, Api<%= it.servicePrefix -%>BaseUrl: string) {\n super($http, Api<%= it.servicePrefix -%>BaseUrl);\n }\n\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n<% }); %>\n}\n\n",
21
21
  "operation.ejs": "<%~ it.jsDocs %>\n\n <%= it.name %>(<% it.parameters.forEach((parameter) => { %>\n<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\n config?: IRequestShortcutConfig\n ): IPromise<<%~ it.returnType %>> {\n let url = `<%= it.url %>?`;\n<% if(it.query && it.query.length > 0) { %>\n <% it.query.forEach((parameter) => { %>\n if (<%= parameter.name %> !== undefined) {\n <% if(!!parameter.original && parameter.original.type === 'array') { %>\n <%= parameter.name %>.forEach(item => { url += serializeQueryParam(item, '<%= parameter.originalName %>') + \"&\"; });\n <% } else {%>\n url += serializeQueryParam(<%= parameter.name %>, '<%= parameter.originalName %>') + \"&\";\n <% } %>\n }\n <% }); %>\n<% } %>\n\n return this.$<%= it.method.toLowerCase() %>(\n url,\n<% if(['POST', 'PUT', 'PATCH'].includes(it.method)) { %>\n <% if(it.body) { %>\n <%= it.body.contentType === 'urlencoded' ? 'new URLSearchParams(' + it.body.name + ' as any)' : it.body.name %>,\n <% } else { %>\n null,\n <% } %>\n<% } %>\n config\n );\n }\n"
22
22
  },
23
23
  "ng2": {
24
24
  "barrel.ejs": "\n/**\n * Serializes a params object into a query string that is compatible with different REST APIs.\n * Implementation from: https://github.com/suhaotian/xior/blob/main/src/utils.ts\n * Kudos to @suhaotian for the original implementation\n */\nfunction encodeParams<T = any>(\n params: T,\n parentKey: string | null = null,\n options?: {\n allowDots?: boolean;\n serializeDate?: (value: Date) => string;\n arrayFormat?: 'indices' | 'repeat' | 'brackets';\n }\n): string {\n if (params === undefined || params === null) return '';\n const encodedParams: string[] = [];\n const paramsIsArray = Array.isArray(params);\n const { arrayFormat, allowDots, serializeDate } = options || {};\n\n const getKey = (key: string) => {\n if (allowDots && !paramsIsArray) return `.${key}`;\n if (paramsIsArray) {\n if (arrayFormat === 'brackets') {\n return '[]';\n }\n if (arrayFormat === 'repeat') {\n return '';\n }\n }\n return `[${key}]`;\n };\n\n for (const key in params) {\n if (Object.prototype.hasOwnProperty.call(params, key)) {\n let value = (params as any)[key];\n if (value !== undefined) {\n const encodedKey = parentKey ? `${parentKey}${getKey(key)}` : (key as string);\n\n // biome-ignore lint/suspicious/noGlobalIsNan: <explanation>\n if (!isNaN(value) && value instanceof Date) {\n value = serializeDate ? serializeDate(value) : value.toISOString();\n }\n if (typeof value === 'object') {\n // If the value is an object or array, recursively encode its contents\n const result = encodeParams(value, encodedKey, options);\n if (result !== '') encodedParams.push(result);\n } else {\n // Otherwise, encode the key-value pair\n encodedParams.push(`${encodeURIComponent(encodedKey)}=${encodeURIComponent(value)}`);\n }\n }\n }\n }\n\n return encodedParams.join('&');\n}\n\n",
25
- "baseClient.ejs": "/* tslint:disable */\n/* eslint-disable */\n//----------------------\n// <auto-generated>\n// Generated using Swaggie (https://github.com/yhnavein/swaggie)\n// Please avoid doing any manual changes in this file\n// </auto-generated>\n//----------------------\n// ReSharper disable InconsistentNaming\n// deno-lint-ignore-file\n\nimport type { Observable } from \"rxjs\";\nimport { Injectable, Inject, Optional, InjectionToken } from \"@angular/core\";\nimport { HttpClient } from \"@angular/common/http\";\n\nexport const <%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL = new InjectionToken<string>(\"<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL\");\n\nabstract class BaseService {\n private httpClient: HttpClient;\n private baseUrl: string;\n\n constructor(\n @Inject(HttpClient) httpClient: HttpClient,\n @Optional() @Inject(<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL) baseUrl?: string\n ) {\n this.httpClient = httpClient;\n this.baseUrl = baseUrl ? baseUrl : '';\n }\n\n protected $get<T>(url: string, options?: any): Observable<T> {\n return this.httpClient\n .get<T>(this.baseUrl + url, options)\n .pipe((response: any) => response);\n }\n\n protected $getAll<T>(url: string, options?: any): Observable<T[]> {\n return this.httpClient\n .get<T[]>(this.baseUrl + url, options)\n .pipe((response: any) => response);\n }\n\n protected $delete<T>(url: string, options?: any): Observable<T> {\n return this.httpClient\n .delete(this.baseUrl + url, options)\n .pipe((response: any) => response);\n }\n\n protected $post(url: string, data: any, options?: any): Observable<any> {\n return this.httpClient\n .post(this.baseUrl + url, data, options)\n .pipe((response: any) => response);\n }\n\n protected $patch<T>(url: string, data: any, options?: any): Observable<T> {\n return this.httpClient\n .patch(this.baseUrl + url, data, options)\n .pipe((response: any) => response);\n }\n\n protected $put(url: string, data: any, options?: any): Observable<any> {\n return this.httpClient\n .put(this.baseUrl + url, data, options)\n .pipe((response: any) => response);\n }\n}\n\nfunction paramsSerializer(params: any) {\n return encodeParams(params, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n });\n}\n\n",
26
- "client.ejs": "@Injectable({\n providedIn: 'root'\n})\nexport class <%= it.clientName -%>Service extends BaseService {\n constructor(\n @Inject(HttpClient) httpClient: HttpClient,\n @Optional() @Inject(<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL) baseUrl?: string\n ) {\n super(httpClient, baseUrl);\n }\n\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n<% }); %>\n}\n\n",
27
- "operation.ejs": "<%~ it.jsDocs %>\n\n <%= it.name %>(\n <% it.parameters.forEach((parameter) => { %>\n<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\nconfig?: any\n ): Observable<<%~ it.returnType %>> {\n const url = `<%= it.url %>?<%\n if(it.query && it.query.length > 0) { %>${paramsSerializer({<%\n it.query.forEach((parameter) => { %>\n'<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>})}<% } %>`;\n\n return this.$<%= it.method.toLowerCase() %>(\n url,\n<% if(['POST', 'PUT', 'PATCH'].includes(it.method)) { %>\n<% if(it.body) { %>\n <%= it.body.contentType === 'urlencoded' ? 'new URLSearchParams(' + it.body.name + ' as any)' : it.body.name %>,\n<% } else { %>\n null,\n<% } %>\n<% } %>\n config\n );\n }\n"
25
+ "baseClient.ejs": "import type { Observable } from \"rxjs\";\nimport { Injectable, InjectionToken, inject } from \"@angular/core\";\nimport { HttpClient } from \"@angular/common/http\";\n\nexport const <%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL = new InjectionToken<string>(\"<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL\");\n\nfunction paramsSerializer(params: any) {\n return encodeParams(params, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n });\n}\n\n",
26
+ "client.ejs": "@Injectable({\n providedIn: 'root'\n})\nexport class <%= it.clientName.charAt(0).toUpperCase() + it.clientName.slice(1) -%>Service {\n private http = inject(HttpClient);\n private baseUrl = inject(<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL, { optional: true }) ?? '';\n\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n<% }); %>\n}\n\n",
27
+ "operation.ejs": "<%~ it.jsDocs %>\n\n <%= it.name %>(\n <% it.parameters.forEach((parameter) => { %>\n<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\nconfig?: any\n ): Observable<<%~ it.returnType %>> {\n<% if(it.query && it.query.length > 0) { -%>\n const params = paramsSerializer({<%\n it.query.forEach((parameter) => { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>});\n const url = `<%= it.url %>${params ? '?' + params : ''}`;\n<% } else { -%>\n const url = `<%= it.url %>`;\n<% } -%>\n<% if(it.method === 'GET') { %>\n return this.http.get<<%~ it.returnType %>>(this.baseUrl + url, config);\n<% } else if(it.method === 'DELETE') { %>\n return this.http.delete<<%~ it.returnType %>>(this.baseUrl + url, config);\n<% } else if(['POST', 'PUT', 'PATCH'].includes(it.method)) {\n const bodyArg = it.body\n ? (it.body.contentType === 'urlencoded' ? 'new URLSearchParams(' + it.body.name + ' as any)' : it.body.name)\n : 'null';\n%>\n return this.http.<%= it.method.toLowerCase() %><%~ '<' + it.returnType + '>' %>(this.baseUrl + url, <%~ bodyArg %>, config);\n<% } %>\n }\n"
28
28
  },
29
29
  "swr-axios": {
30
30
  "barrel.ejs": "\n/**\n * Serializes a params object into a query string that is compatible with different REST APIs.\n * Implementation from: https://github.com/suhaotian/xior/blob/main/src/utils.ts\n * Kudos to @suhaotian for the original implementation\n */\nfunction encodeParams<T = any>(\n params: T,\n parentKey: string | null = null,\n options?: {\n allowDots?: boolean;\n serializeDate?: (value: Date) => string;\n arrayFormat?: 'indices' | 'repeat' | 'brackets';\n }\n): string {\n if (params === undefined || params === null) return '';\n const encodedParams: string[] = [];\n const paramsIsArray = Array.isArray(params);\n const { arrayFormat, allowDots, serializeDate } = options || {};\n\n const getKey = (key: string) => {\n if (allowDots && !paramsIsArray) return `.${key}`;\n if (paramsIsArray) {\n if (arrayFormat === 'brackets') {\n return '[]';\n }\n if (arrayFormat === 'repeat') {\n return '';\n }\n }\n return `[${key}]`;\n };\n\n for (const key in params) {\n if (Object.prototype.hasOwnProperty.call(params, key)) {\n let value = (params as any)[key];\n if (value !== undefined) {\n const encodedKey = parentKey ? `${parentKey}${getKey(key)}` : (key as string);\n\n // biome-ignore lint/suspicious/noGlobalIsNan: <explanation>\n if (!isNaN(value) && value instanceof Date) {\n value = serializeDate ? serializeDate(value) : value.toISOString();\n }\n if (typeof value === 'object') {\n // If the value is an object or array, recursively encode its contents\n const result = encodeParams(value, encodedKey, options);\n if (result !== '') encodedParams.push(result);\n } else {\n // Otherwise, encode the key-value pair\n encodedParams.push(`${encodeURIComponent(encodedKey)}=${encodeURIComponent(value)}`);\n }\n }\n }\n }\n\n return encodedParams.join('&');\n}\n\n",
31
- "baseClient.ejs": "/* tslint:disable */\n/* eslint-disable */\n//----------------------\n// <auto-generated>\n// Generated using Swaggie (https://github.com/yhnavein/swaggie)\n// Please avoid doing any manual changes in this file\n// </auto-generated>\n//----------------------\n// ReSharper disable InconsistentNaming\n// deno-lint-ignore-file\n\nimport Axios, { type AxiosPromise, type AxiosRequestConfig } from \"axios\";\nimport useSWR, { type SWRConfiguration, type Key } from 'swr';\n\nexport const axios = Axios.create({\n baseURL: '<%= it.baseUrl || '' -%>',\n paramsSerializer: (params: any) =>\n encodeParams(params, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n});\n\ninterface SwrConfig extends SWRConfiguration {\n /* Custom key for SWR. You don't have to worry about this as by default it's the URL. You can use standard SWR Key here if you need more flexibility. */\n key?: Key;\n\n /* Configuration for axios fetcher */\n axios?: AxiosRequestConfig;\n}\n",
32
- "client.ejs": "export const <%= it.camelCaseName -%>Client = {\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n <% }); %>\n};\n\n<% var getOperations = it.operations.filter((o) => o.method === 'GET');\nif(getOperations.length > 0) { %>\n <% getOperations.forEach((operation) => {\n var opName = operation.name;\n if(opName.toLowerCase().startsWith(\"get\")) {\n opName = opName.substring(3);\n }\n opName[0] = opName[0].toUpperCase();\n var customName = \"use\" + it.clientName + opName;\n var swrOperation = Object.assign({ swrOpName: customName }, operation); %>\n<%~ include('swrOperation.ejs', swrOperation); %>\n\n <% }); %>\n<% } %>\n",
31
+ "baseClient.ejs": "import Axios, { type AxiosPromise, type AxiosRequestConfig } from \"axios\";\nimport useSWR, { type SWRConfiguration, type Key } from 'swr';\n\nexport const axios = Axios.create({\n baseURL: '<%= it.baseUrl || '' -%>',\n paramsSerializer: (params: any) =>\n encodeParams(params, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n});\n\ninterface SwrConfig extends SWRConfiguration {\n /* Custom key for SWR. You don't have to worry about this as by default it's the URL. You can use standard SWR Key here if you need more flexibility. */\n key?: Key;\n\n /* Configuration for axios fetcher */\n axios?: AxiosRequestConfig;\n}\n\n",
32
+ "client.ejs": "export const <%= it.camelCaseName -%>Client = {\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n <% }); %>\n};\n\n<% var getOperations = it.operations.filter((o) => o.method === 'GET');\nif(getOperations.length > 0) { %>\n <% getOperations.forEach((operation) => {\n var opName = operation.name;\n if(opName.toLowerCase().startsWith(\"get\")) {\n opName = opName.substring(3);\n }\n opName = opName.charAt(0).toUpperCase() + opName.slice(1);\n var clientName = it.clientName.charAt(0).toUpperCase() + it.clientName.slice(1);\n var customName = \"use\" + clientName + opName;\n var swrOperation = Object.assign({ swrOpName: customName }, operation); %>\n<%~ include('swrOperation.ejs', swrOperation); %>\n\n <% }); %>\n<% } %>\n",
33
33
  "operation.ejs": "<%~ it.jsDocs %>\n\n <%= it.name %>(<% it.parameters.forEach((parameter) => { %>\n<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\n $config?: AxiosRequestConfig\n ): AxiosPromise<<%~ it.returnType %>> {\n const url = `<%= it.url %>`;\n\n return axios.request<<%~ it.returnType %>>({\n url: url,\n method: '<%= it.method %>',\n<% if(it.body) { %>\n<% if(it.body.contentType === 'urlencoded') { %>\n data: new URLSearchParams(<%= it.body.name %> as any),\n<% } else { %>\n data: <%= it.body.name %>,\n<% } %>\n<% } %>\n<% if(it.query && it.query.length > 0) { %>\n params: {\n <% it.query.forEach((parameter) => { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>\n },\n<% } %>\n<% if(it.headers && it.headers.length > 0) { %>\n headers: {\n <% it.headers.forEach((parameter) => { %>\n <% if (parameter.value) { %>\n '<%= parameter.originalName %>': '<%= parameter.value %>',\n <% } else { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% } %>\n <% }); %>\n},\n<% } %>\n ...$config,\n });\n },\n",
34
- "swrOperation.ejs": "<%~ it.jsDocs %>\n\nexport function <%= it.swrOpName %>(<% it.parameters.forEach((parameter) => { %>\n <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\n $config?: SwrConfig\n ) {\n const url = `<%= it.url %>`;\n const { axios: $axiosConf, key, ...config } = $config || {};\n\n const cacheUrl = `${url}?<%\n if(it.query && it.query.length > 0) { %>${encodeParams({<%\n it.query.forEach((parameter) => { %>\n'<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>})}<% } %>`;\n\nconst { data, error, mutate } = useSWR<<%~ it.returnType %>>(\n key ?? cacheUrl,\n () => axios.request({\n url: url,\n method: '<%= it.method %>',\n<% if(it.query && it.query.length > 0) { %>\n params: {\n <% it.query.forEach((parameter) => { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>\n},\n<% } %>\n<% if(it.headers && it.headers.length > 0) { %>\n headers: {\n <% it.headers.forEach((parameter) => { %>\n <% if (parameter.value) { %>\n '<%= parameter.originalName %>': '<%= parameter.value %>',\n <% } else { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% } %>\n <% }); %>\n },\n<% } %>\n ...$axiosConf})\n .then((resp) => resp.data),\n config);\n\n return {\n data,\n isLoading: !error && !data,\n error: error,\n mutate,\n };\n}\n"
34
+ "swrOperation.ejs": "<%~ it.jsDocs %>\n\nexport function <%= it.swrOpName %>(<% it.parameters.forEach((parameter) => { %>\n <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\n $config?: SwrConfig\n ) {\n const url = `<%= it.url %>`;\n const { axios: $axiosConf, key, ...config } = $config || {};\n\n<% if(it.query && it.query.length > 0) { %>\n const cacheKey = encodeParams({<%\n it.query.forEach((parameter) => { %>\n'<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>});\n const cacheUrl = cacheKey ? `${url}?${cacheKey}` : url;\n<% } else { %>\n const cacheUrl = url;\n<% } %>\n\nconst { data, error, isLoading, mutate } = useSWR<<%~ it.returnType %>>(\n key ?? cacheUrl,\n () => axios.request({\n url: url,\n method: '<%= it.method %>',\n<% if(it.query && it.query.length > 0) { %>\n params: {\n <% it.query.forEach((parameter) => { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>\n},\n<% } %>\n<% if(it.headers && it.headers.length > 0) { %>\n headers: {\n <% it.headers.forEach((parameter) => { %>\n <% if (parameter.value) { %>\n '<%= parameter.originalName %>': '<%= parameter.value %>',\n <% } else { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% } %>\n <% }); %>\n },\n<% } %>\n ...$axiosConf})\n .then((resp) => resp.data),\n config);\n\n return {\n data,\n isLoading,\n error,\n mutate,\n };\n}\n"
35
35
  },
36
36
  "tsq-xior": {
37
37
  "barrel.ejs": "",
38
- "baseClient.ejs": "/* tslint:disable */\n/* eslint-disable */\n//----------------------\n// <auto-generated>\n// Generated using Swaggie (https://github.com/yhnavein/swaggie)\n// Please avoid doing any manual changes in this file\n// </auto-generated>\n//----------------------\n// ReSharper disable InconsistentNaming\n// deno-lint-ignore-file\n\nimport xior, { type XiorResponse, type XiorRequestConfig, encodeParams } from \"xior\";\nimport { QueryClient, type UseQueryOptions, useQuery } from '@tanstack/react-query';\n\nexport const queryClient = new QueryClient();\n\nexport const http = xior.create({\n baseURL: '<%= it.baseUrl || '' %>',\n paramsSerializer: (params) =>\n encodeParams(params, true, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n});\n\n",
39
- "client.ejs": "export const <%= it.camelCaseName %>Client = {\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n<% }); %>\n};\n\n\n<% var getOperations = it.operations.filter((o) => o.method === 'GET');\nif(getOperations.length > 0) { %>\n <% getOperations.forEach((operation) => {\n var opName = operation.name;\n if(opName.toLowerCase().startsWith(\"get\")) {\n opName = opName.substring(3);\n }\n opName[0] = opName[0].toUpperCase();\n var customName = \"use\" + it.clientName + opName;\n var queryOperation = Object.assign({ rqOpName: customName, opKey: it.clientName + opName, clientName: it.camelCaseName }, operation); %>\n<%~ include('queryOperation.ejs', queryOperation); %>\n\n <% }); %>\n<% } %>\n",
38
+ "baseClient.ejs": "import xior, { type XiorResponse, type XiorRequestConfig, encodeParams } from \"xior\";\nimport { type UseQueryOptions, useQuery } from '@tanstack/react-query';\n\nexport const http = xior.create({\n baseURL: '<%= it.baseUrl || '' %>',\n paramsSerializer: (params: any) =>\n encodeParams(params, true, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n});\n\n",
39
+ "client.ejs": "export const <%= it.camelCaseName %>Client = {\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n<% }); %>\n};\n\n\n<% var getOperations = it.operations.filter((o) => o.method === 'GET');\nif(getOperations.length > 0) { %>\n <% getOperations.forEach((operation) => {\n var opName = operation.name;\n if(opName.toLowerCase().startsWith(\"get\")) {\n opName = opName.substring(3);\n }\n opName = opName.charAt(0).toUpperCase() + opName.slice(1);\n var clientName = it.clientName.charAt(0).toUpperCase() + it.clientName.slice(1);\n var customName = \"use\" + clientName + opName;\n var queryOperation = Object.assign({ rqOpName: customName, opKey: it.clientName + opName, clientName: it.camelCaseName }, operation); %>\n<%~ include('queryOperation.ejs', queryOperation); %>\n\n <% }); %>\n<% } %>\n",
40
40
  "operation.ejs": "<%~ it.jsDocs %>\n\n <%= it.name %>(<% it.parameters.forEach((parameter) => { %>\n<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\n$config?: XiorRequestConfig\n ): Promise<XiorResponse<<%~ it.returnType %>>> {\n const url = `<%= it.url %>`;\n\n return http.request<<%~ it.returnType %>>({\n url: url,\n method: '<%= it.method %>',\n<% if(it.body) { %>\n<% if(it.body.contentType === 'urlencoded') { %>\n data: new URLSearchParams(<%= it.body.name %> as any),\n<% } else { %>\n data: <%= it.body.name %>,\n<% } %>\n<% } %>\n<% if(it.query && it.query.length > 0) { %>\n params: {\n <% it.query.forEach((parameter) => { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>\n },\n<% } %>\n<% if(it.headers && it.headers.length > 0) { %>\n headers: {\n <% it.headers.forEach((parameter) => { %>\n <% if (parameter.value) { %>\n '<%= parameter.originalName %>': '<%= parameter.value %>',\n <% } else { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% } %>\n <% }); %>\n},\n<% } %>\n ...$config,\n });\n },\n",
41
41
  "queryOperation.ejs": "<%\nif (it.jsDocs) {\n const additionalParams = ` * @param $config (optional) Additional configuration for TanStack Query\n * @param $httpConfig (optional) Additional configuration for xior request (actually executes the request)`;\n\n // Replace the closing */ with newline + additional params + closing */\n const modifiedDocs = it.jsDocs.replace(/(\\s*)\\*\\/\\s*$/, `\\n${additionalParams}\\n */`);\n-%>\n<%~ modifiedDocs %>\n<% } else { -%>\n<%~ it.jsDocs %>\n<% } %>\n\nexport function <%= it.rqOpName %><TData = <%~ it.returnType %>, TError = Error>(<% it.parameters.forEach((parameter) => { %>\n <%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\n$config?: Omit<\n UseQueryOptions<<%~ it.returnType %>, TError, TData>,\n 'queryKey' | 'queryFn'\n>,\n $httpConfig?: XiorRequestConfig\n ) {\n return useQuery<<%~ it.returnType %>, TError, TData>({\n queryKey: ['<%= it.clientName %>', '<%= it.opKey %>', <% it.parameters.forEach((parameter) => { %><%= parameter.name %>, <% }); %>],\n queryFn: () => <%= it.clientName %>Client.<%= it.name %>(<% it.parameters.forEach((parameter) => { %>\n<%= parameter.name %>, <% }); %>$httpConfig).then(res => res.data),\n ...$config\n });\n}\n<%= it.rqOpName %>.queryKeys = ['<%= it.clientName %>', '<%= it.opKey %>'];\n"
42
42
  },
43
43
  "xior": {
44
44
  "barrel.ejs": "",
45
- "baseClient.ejs": "/* tslint:disable */\n/* eslint-disable */\n//----------------------\n// <auto-generated>\n// Generated using Swaggie (https://github.com/yhnavein/swaggie)\n// Please avoid doing any manual changes in this file\n// </auto-generated>\n//----------------------\n// ReSharper disable InconsistentNaming\n// deno-lint-ignore-file\n\nimport xior, { type XiorResponse, type XiorRequestConfig, encodeParams } from \"xior\";\n\nexport const http = xior.create({\n baseURL: '<%= it.baseUrl || '' %>',\n paramsSerializer: (params) =>\n encodeParams(params, true, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n});\n\n",
45
+ "baseClient.ejs": "import xior, { type XiorResponse, type XiorRequestConfig, encodeParams } from \"xior\";\n\nexport const http = xior.create({\n baseURL: '<%= it.baseUrl || '' %>',\n paramsSerializer: (params: any) =>\n encodeParams(params, true, null, {\n allowDots: <%= it.allowDots %>,\n arrayFormat: '<%= it.arrayFormat %>',\n }),\n});\n\n",
46
46
  "client.ejs": "export const <%= it.camelCaseName %>Client = {\n <% it.operations.forEach((operation) => { %>\n<%~ include('operation.ejs', operation); %>\n\n<% }); %>\n};\n\n",
47
47
  "operation.ejs": "<%~ it.jsDocs %>\n\n <%= it.name %>(<% it.parameters.forEach((parameter) => { %>\n<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,\n <% }); %>\n$config?: XiorRequestConfig\n ): Promise<XiorResponse<<%~ it.returnType %>>> {\n const url = `<%= it.url %>`;\n\n return http.request<<%~ it.returnType %>>({\n url: url,\n method: '<%= it.method %>',\n<% if(it.body) { %>\n<% if(it.body.contentType === 'urlencoded') { %>\n data: new URLSearchParams(<%= it.body.name %> as any),\n<% } else { %>\n data: <%= it.body.name %>,\n<% } %>\n<% } %>\n<% if(it.query && it.query.length > 0) { %>\n params: {\n <% it.query.forEach((parameter) => { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% }); %>\n },\n<% } %>\n<% if(it.headers && it.headers.length > 0) { %>\n headers: {\n <% it.headers.forEach((parameter) => { %>\n <% if (parameter.value) { %>\n '<%= parameter.originalName %>': '<%= parameter.value %>',\n <% } else { %>\n '<%= parameter.originalName %>': <%= parameter.name %>,\n <% } %>\n <% }); %>\n},\n<% } %>\n ...$config,\n });\n },\n"
48
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "1.8.8",
3
+ "version": "1.9.0-alpha.1",
4
4
  "description": "Generate a fully typed TypeScript API client from your OpenAPI 3 spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",
@@ -1,14 +1,3 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- //----------------------
4
- // <auto-generated>
5
- // Generated using Swaggie (https://github.com/yhnavein/swaggie)
6
- // Please avoid doing any manual changes in this file
7
- // </auto-generated>
8
- //----------------------
9
- // ReSharper disable InconsistentNaming
10
- // deno-lint-ignore-file
11
-
12
1
  import Axios, { type AxiosPromise, type AxiosRequestConfig } from "axios";
13
2
 
14
3
  export const axios = Axios.create({
@@ -1,14 +1,3 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- //----------------------
4
- // <auto-generated>
5
- // Generated using Swaggie (https://github.com/yhnavein/swaggie)
6
- // Please avoid doing any manual changes in this file
7
- // </auto-generated>
8
- //----------------------
9
- // ReSharper disable InconsistentNaming
10
- // deno-lint-ignore-file
11
-
12
1
  export const defaults = {
13
2
  baseUrl: '<%= it.baseUrl || '' %>',
14
3
  paramsSerializer: (params: any) =>
@@ -1,14 +1,3 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- //----------------------
4
- // <auto-generated>
5
- // Generated using Swaggie (https://github.com/yhnavein/swaggie)
6
- // Please avoid doing any manual changes in this file
7
- // </auto-generated>
8
- //----------------------
9
- // ReSharper disable InconsistentNaming
10
- // deno-lint-ignore-file
11
-
12
1
  import type { IHttpService, IRequestShortcutConfig, IPromise } from 'angular';
13
2
 
14
3
  abstract class BaseService {
@@ -1,69 +1,9 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- //----------------------
4
- // <auto-generated>
5
- // Generated using Swaggie (https://github.com/yhnavein/swaggie)
6
- // Please avoid doing any manual changes in this file
7
- // </auto-generated>
8
- //----------------------
9
- // ReSharper disable InconsistentNaming
10
- // deno-lint-ignore-file
11
-
12
1
  import type { Observable } from "rxjs";
13
- import { Injectable, Inject, Optional, InjectionToken } from "@angular/core";
2
+ import { Injectable, InjectionToken, inject } from "@angular/core";
14
3
  import { HttpClient } from "@angular/common/http";
15
4
 
16
5
  export const <%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL = new InjectionToken<string>("<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL");
17
6
 
18
- abstract class BaseService {
19
- private httpClient: HttpClient;
20
- private baseUrl: string;
21
-
22
- constructor(
23
- @Inject(HttpClient) httpClient: HttpClient,
24
- @Optional() @Inject(<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL) baseUrl?: string
25
- ) {
26
- this.httpClient = httpClient;
27
- this.baseUrl = baseUrl ? baseUrl : '';
28
- }
29
-
30
- protected $get<T>(url: string, options?: any): Observable<T> {
31
- return this.httpClient
32
- .get<T>(this.baseUrl + url, options)
33
- .pipe((response: any) => response);
34
- }
35
-
36
- protected $getAll<T>(url: string, options?: any): Observable<T[]> {
37
- return this.httpClient
38
- .get<T[]>(this.baseUrl + url, options)
39
- .pipe((response: any) => response);
40
- }
41
-
42
- protected $delete<T>(url: string, options?: any): Observable<T> {
43
- return this.httpClient
44
- .delete(this.baseUrl + url, options)
45
- .pipe((response: any) => response);
46
- }
47
-
48
- protected $post(url: string, data: any, options?: any): Observable<any> {
49
- return this.httpClient
50
- .post(this.baseUrl + url, data, options)
51
- .pipe((response: any) => response);
52
- }
53
-
54
- protected $patch<T>(url: string, data: any, options?: any): Observable<T> {
55
- return this.httpClient
56
- .patch(this.baseUrl + url, data, options)
57
- .pipe((response: any) => response);
58
- }
59
-
60
- protected $put(url: string, data: any, options?: any): Observable<any> {
61
- return this.httpClient
62
- .put(this.baseUrl + url, data, options)
63
- .pipe((response: any) => response);
64
- }
65
- }
66
-
67
7
  function paramsSerializer(params: any) {
68
8
  return encodeParams(params, null, {
69
9
  allowDots: <%= it.allowDots %>,
@@ -1,13 +1,9 @@
1
1
  @Injectable({
2
2
  providedIn: 'root'
3
3
  })
4
- export class <%= it.clientName -%>Service extends BaseService {
5
- constructor(
6
- @Inject(HttpClient) httpClient: HttpClient,
7
- @Optional() @Inject(<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL) baseUrl?: string
8
- ) {
9
- super(httpClient, baseUrl);
10
- }
4
+ export class <%= it.clientName.charAt(0).toUpperCase() + it.clientName.slice(1) -%>Service {
5
+ private http = inject(HttpClient);
6
+ private baseUrl = inject(<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL, { optional: true }) ?? '';
11
7
 
12
8
  <% it.operations.forEach((operation) => { %>
13
9
  <%~ include('operation.ejs', operation); %>
@@ -6,21 +6,24 @@
6
6
  <% }); %>
7
7
  config?: any
8
8
  ): Observable<<%~ it.returnType %>> {
9
- const url = `<%= it.url %>?<%
10
- if(it.query && it.query.length > 0) { %>${paramsSerializer({<%
9
+ <% if(it.query && it.query.length > 0) { -%>
10
+ const params = paramsSerializer({<%
11
11
  it.query.forEach((parameter) => { %>
12
- '<%= parameter.originalName %>': <%= parameter.name %>,
13
- <% }); %>})}<% } %>`;
14
-
15
- return this.$<%= it.method.toLowerCase() %>(
16
- url,
17
- <% if(['POST', 'PUT', 'PATCH'].includes(it.method)) { %>
18
- <% if(it.body) { %>
19
- <%= it.body.contentType === 'urlencoded' ? 'new URLSearchParams(' + it.body.name + ' as any)' : it.body.name %>,
20
- <% } else { %>
21
- null,
22
- <% } %>
12
+ '<%= parameter.originalName %>': <%= parameter.name %>,
13
+ <% }); %>});
14
+ const url = `<%= it.url %>${params ? '?' + params : ''}`;
15
+ <% } else { -%>
16
+ const url = `<%= it.url %>`;
17
+ <% } -%>
18
+ <% if(it.method === 'GET') { %>
19
+ return this.http.get<<%~ it.returnType %>>(this.baseUrl + url, config);
20
+ <% } else if(it.method === 'DELETE') { %>
21
+ return this.http.delete<<%~ it.returnType %>>(this.baseUrl + url, config);
22
+ <% } else if(['POST', 'PUT', 'PATCH'].includes(it.method)) {
23
+ const bodyArg = it.body
24
+ ? (it.body.contentType === 'urlencoded' ? 'new URLSearchParams(' + it.body.name + ' as any)' : it.body.name)
25
+ : 'null';
26
+ %>
27
+ return this.http.<%= it.method.toLowerCase() %><%~ '<' + it.returnType + '>' %>(this.baseUrl + url, <%~ bodyArg %>, config);
23
28
  <% } %>
24
- config
25
- );
26
29
  }
@@ -1,14 +1,3 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- //----------------------
4
- // <auto-generated>
5
- // Generated using Swaggie (https://github.com/yhnavein/swaggie)
6
- // Please avoid doing any manual changes in this file
7
- // </auto-generated>
8
- //----------------------
9
- // ReSharper disable InconsistentNaming
10
- // deno-lint-ignore-file
11
-
12
1
  import Axios, { type AxiosPromise, type AxiosRequestConfig } from "axios";
13
2
  import useSWR, { type SWRConfiguration, type Key } from 'swr';
14
3
 
@@ -28,3 +17,4 @@ interface SwrConfig extends SWRConfiguration {
28
17
  /* Configuration for axios fetcher */
29
18
  axios?: AxiosRequestConfig;
30
19
  }
20
+
@@ -12,8 +12,9 @@ if(getOperations.length > 0) { %>
12
12
  if(opName.toLowerCase().startsWith("get")) {
13
13
  opName = opName.substring(3);
14
14
  }
15
- opName[0] = opName[0].toUpperCase();
16
- var customName = "use" + it.clientName + opName;
15
+ opName = opName.charAt(0).toUpperCase() + opName.slice(1);
16
+ var clientName = it.clientName.charAt(0).toUpperCase() + it.clientName.slice(1);
17
+ var customName = "use" + clientName + opName;
17
18
  var swrOperation = Object.assign({ swrOpName: customName }, operation); %>
18
19
  <%~ include('swrOperation.ejs', swrOperation); %>
19
20
 
@@ -8,13 +8,17 @@ export function <%= it.swrOpName %>(<% it.parameters.forEach((parameter) => { %>
8
8
  const url = `<%= it.url %>`;
9
9
  const { axios: $axiosConf, key, ...config } = $config || {};
10
10
 
11
- const cacheUrl = `${url}?<%
12
- if(it.query && it.query.length > 0) { %>${encodeParams({<%
11
+ <% if(it.query && it.query.length > 0) { %>
12
+ const cacheKey = encodeParams({<%
13
13
  it.query.forEach((parameter) => { %>
14
14
  '<%= parameter.originalName %>': <%= parameter.name %>,
15
- <% }); %>})}<% } %>`;
15
+ <% }); %>});
16
+ const cacheUrl = cacheKey ? `${url}?${cacheKey}` : url;
17
+ <% } else { %>
18
+ const cacheUrl = url;
19
+ <% } %>
16
20
 
17
- const { data, error, mutate } = useSWR<<%~ it.returnType %>>(
21
+ const { data, error, isLoading, mutate } = useSWR<<%~ it.returnType %>>(
18
22
  key ?? cacheUrl,
19
23
  () => axios.request({
20
24
  url: url,
@@ -43,8 +47,8 @@ const { data, error, mutate } = useSWR<<%~ it.returnType %>>(
43
47
 
44
48
  return {
45
49
  data,
46
- isLoading: !error && !data,
47
- error: error,
50
+ isLoading,
51
+ error,
48
52
  mutate,
49
53
  };
50
54
  }
@@ -1,22 +1,9 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- //----------------------
4
- // <auto-generated>
5
- // Generated using Swaggie (https://github.com/yhnavein/swaggie)
6
- // Please avoid doing any manual changes in this file
7
- // </auto-generated>
8
- //----------------------
9
- // ReSharper disable InconsistentNaming
10
- // deno-lint-ignore-file
11
-
12
1
  import xior, { type XiorResponse, type XiorRequestConfig, encodeParams } from "xior";
13
- import { QueryClient, type UseQueryOptions, useQuery } from '@tanstack/react-query';
14
-
15
- export const queryClient = new QueryClient();
2
+ import { type UseQueryOptions, useQuery } from '@tanstack/react-query';
16
3
 
17
4
  export const http = xior.create({
18
5
  baseURL: '<%= it.baseUrl || '' %>',
19
- paramsSerializer: (params) =>
6
+ paramsSerializer: (params: any) =>
20
7
  encodeParams(params, true, null, {
21
8
  allowDots: <%= it.allowDots %>,
22
9
  arrayFormat: '<%= it.arrayFormat %>',
@@ -13,8 +13,9 @@ if(getOperations.length > 0) { %>
13
13
  if(opName.toLowerCase().startsWith("get")) {
14
14
  opName = opName.substring(3);
15
15
  }
16
- opName[0] = opName[0].toUpperCase();
17
- var customName = "use" + it.clientName + opName;
16
+ opName = opName.charAt(0).toUpperCase() + opName.slice(1);
17
+ var clientName = it.clientName.charAt(0).toUpperCase() + it.clientName.slice(1);
18
+ var customName = "use" + clientName + opName;
18
19
  var queryOperation = Object.assign({ rqOpName: customName, opKey: it.clientName + opName, clientName: it.camelCaseName }, operation); %>
19
20
  <%~ include('queryOperation.ejs', queryOperation); %>
20
21
 
@@ -1,19 +1,8 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- //----------------------
4
- // <auto-generated>
5
- // Generated using Swaggie (https://github.com/yhnavein/swaggie)
6
- // Please avoid doing any manual changes in this file
7
- // </auto-generated>
8
- //----------------------
9
- // ReSharper disable InconsistentNaming
10
- // deno-lint-ignore-file
11
-
12
1
  import xior, { type XiorResponse, type XiorRequestConfig, encodeParams } from "xior";
13
2
 
14
3
  export const http = xior.create({
15
4
  baseURL: '<%= it.baseUrl || '' %>',
16
- paramsSerializer: (params) =>
5
+ paramsSerializer: (params: any) =>
17
6
  encodeParams(params, true, null, {
18
7
  allowDots: <%= it.allowDots %>,
19
8
  arrayFormat: '<%= it.arrayFormat %>',