Skip to content

Commit

Permalink
fix: 返回数据为 raw 时返回类型应为 any
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Apr 26, 2019
1 parent 5400074 commit 330c11e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
32 changes: 32 additions & 0 deletions __mocks__/request-promise-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,38 @@ const request = {
res_body: '{"type":"object","title":"empty object","properties":{}}',
req_body_type: 'form',
},
{
query_path: {
path: '/rawResponse',
params: [],
},
edit_uid: 0,
status: 'undone',
type: 'static',
req_body_is_json_schema: false,
res_body_is_json_schema: false,
api_opened: false,
index: 0,
tag: [],
_id: 97,
method: 'GET',
catid: 58,
title: '返回 raw',
path: '/rawResponse',
project_id: 23,
req_params: [],
res_body_type: 'raw',
uid: 11,
add_time: 1556272312,
up_time: 1556272319,
req_query: [],
req_headers: [],
req_body_form: [],
__v: 0,
markdown: '',
desc: '',
res_body: '',
},
],
},
]
Expand Down
2 changes: 1 addition & 1 deletion src/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class Generator {
}
break
default:
break
return `export type ${typeName} = any`
}

if (dataKey && jsonSchema && jsonSchema.properties && jsonSchema.properties[dataKey]) {
Expand Down
78 changes: 78 additions & 0 deletions tests/__snapshots__/Generator.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,45 @@ emptyResponseTest.requestConfig = Object.freeze({
\\"https://prod.com/\\",
\\"/emptyResponse_test\\",
undefined
>)
/**
* 接口 **返回 raw** 的 **请求类型**
*/
export interface RawResponseTestRequest {}
/**
* 接口 **返回 raw** 的 **返回类型**
*/
export type RawResponseTestResponse = any
/**
* 接口 **返回 raw** 的 **请求函数**
*/
export function rawResponseTest(requestData?: RawResponseTestRequest): Promise<RawResponseTestResponse> {
return request({
...rawResponseTest.requestConfig,
...parseRequestData(requestData)
} as any)
}
/**
* 接口 **返回 raw** 的 **请求配置**
*/
rawResponseTest.requestConfig = Object.freeze({
mockUrl: mockUrl_0_0_0,
prodUrl: prodUrl_0_0_0,
path: \\"/rawResponse_test\\",
method: Method.GET,
requestBodyType: RequestBodyType.query,
responseBodyType: ResponseBodyType.raw,
dataKey: dataKey_0_0_0
} as RequestConfig<
\\"https://foo.bar/mock/32\\",
\\"https://prod.com/\\",
\\"/rawResponse_test\\",
undefined
>)",
]
`;
Expand Down Expand Up @@ -908,6 +947,45 @@ emptyResponseTest.requestConfig = Object.freeze({
\\"/emptyResponse_test\\",
undefined
>)
/**
* 接口 **返回 raw** 的 **请求类型**
*/
export interface RawResponseTestRequest {}
/**
* 接口 **返回 raw** 的 **返回类型**
*/
export type RawResponseTestResponse = any
/**
* 接口 **返回 raw** 的 **请求函数**
*/
export function rawResponseTest(requestData?: RawResponseTestRequest): Promise<RawResponseTestResponse> {
return request({
...rawResponseTest.requestConfig,
...parseRequestData(requestData)
} as any)
}
/**
* 接口 **返回 raw** 的 **请求配置**
*/
rawResponseTest.requestConfig = Object.freeze({
mockUrl: mockUrl_0_0_0,
prodUrl: prodUrl_0_0_0,
path: \\"/rawResponse_test\\",
method: Method.GET,
requestBodyType: RequestBodyType.query,
responseBodyType: ResponseBodyType.raw,
dataKey: dataKey_0_0_0
} as RequestConfig<
\\"https://foo.bar/mock/32\\",
\\"https://prod.com/\\",
\\"/rawResponse_test\\",
undefined
>)
"
`;
Expand Down

0 comments on commit 330c11e

Please sign in to comment.