@fxri/swagger2api 1.1.10 → 1.1.12

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
@@ -119,7 +119,7 @@ request.getUsers().then((res) => console.log(res))
119
119
 
120
120
  ```typescript
121
121
  declare module "." {
122
- interface AxiosResponseRaw<T = any> {
122
+ interface AxiosResponse<T = any> {
123
123
  /** 状态代码 */
124
124
  code: number
125
125
  /** 提示信息 */
@@ -135,8 +135,8 @@ declare module "." {
135
135
  ```typescript
136
136
  // 响应拦截
137
137
  client.instance.interceptors.response.use(
138
- (response) => ({ code: 0, data: null, message: "", raw: response }),
139
- (error) => ({ code: -1, data: null, message: error.message, raw: error })
138
+ (response) => ({ code: 0, message: "", data: null, raw: response }),
139
+ (error) => ({ code: -1, message: error.message, data: null, raw: error })
140
140
  )
141
141
  ```
142
142
 
@@ -2,16 +2,16 @@
2
2
  const { apiConfig, generateResponses, config } = it;
3
3
  %>
4
4
 
5
- import type { AxiosInstance, AxiosRequestConfig, HeadersDefaults, ResponseType, AxiosResponse } from "axios";
5
+ import type { AxiosInstance, AxiosRequestConfig, HeadersDefaults, ResponseType, AxiosResponse as AxiosResponseRaw } from "axios";
6
6
  import axios from "axios";
7
7
 
8
8
  export type QueryParamsType = Record<string | number, any>;
9
9
 
10
10
  <% if (config.param?.extractResponseRaw) { %>
11
11
  /** 提取响应 */
12
- export interface AxiosResponseRaw<T = any> {
12
+ export interface AxiosResponse<T = any> {
13
13
  /** 原始数据 */
14
- raw: AxiosResponse<T>;
14
+ raw: AxiosResponseRaw<T>;
15
15
  }
16
16
 
17
17
  <% } %>
@@ -117,8 +117,6 @@ export class HttpClient<SecurityDataType = unknown> {
117
117
  ...params
118
118
  <% if (config.unwrapResponseData) { %>
119
119
  }: FullRequestParams): Promise<T> => {
120
- <% } else if (config.param?.extractResponseRaw) { %>
121
- }: FullRequestParams): Promise<AxiosResponseRaw<T>> => {
122
120
  <% } else { %>
123
121
  }: FullRequestParams): Promise<AxiosResponse<T>> => {
124
122
  <% } %>
@@ -13,7 +13,7 @@ const pathParamsNames = _.map(pathParams, "name");
13
13
  // 提取参数
14
14
  if (config.param?.extractRequestQuery && query && query.type) {
15
15
  const queryExtract = config.param?.extractRequestQuery?.split(",")
16
- query.type = query.type.replace(new RegExp(`[\\s\\S\\n]+ (${queryExtract.join("|")}): ([a-z]+),[\\s\\S\\n]+`, "i"), "$2")
16
+ query.type = query.type.replace(new RegExp(`[\\s\\S\\n]+ ['"]?(${queryExtract.join("|")})['"]?: ([a-z]+),[\\s\\S\\n]+`, "i"), "$2")
17
17
  }
18
18
 
19
19
  const isFetchTemplate = config.httpClientType === HTTP_CLIENT.FETCH;
@@ -77,7 +77,7 @@ const describeReturnType = () => {
77
77
 
78
78
  switch(config.httpClientType) {
79
79
  case HTTP_CLIENT.AXIOS: {
80
- return config.param?.extractResponseRaw ? `Promise<AxiosResponseRaw<${type}>>` : `Promise<AxiosResponse<${type}>>`
80
+ return `Promise<AxiosResponse<${type}>>`
81
81
  }
82
82
  default: {
83
83
  return `Promise<HttpResponse<${type}, ${errorType}>`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fxri/swagger2api",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "基于 swagger-typescript-api,将 Swagger 文档自动转为 TypeScript 格式的 API 文件。",
5
5
  "license": "MIT",
6
6
  "author": {