Skip to content

Commit

Permalink
feat(src/utils): 修改当 yapi 下发的字段名称中含有空格时出现的字段多余空格问题 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilic committed May 12, 2020
1 parent 71ff882 commit 23e3e35
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ export function propDefinitionsToJsonSchema(propDefinitions: PropDefinitions): J
required: propDefinitions.reduce<string[]>(
(res, prop) => {
if (prop.required) {
res.push(prop.name)
res.push(prop.name.trim())
}
return res
},
[],
),
properties: propDefinitions.reduce<Exclude<JSONSchema4['properties'], undefined>>(
(res, prop) => {
res[prop.name] = {
res[prop.name.trim()] = {
type: prop.type,
description: prop.comment,
...(prop.type === 'file' as any ? {tsType: FileData.name} : {}),
Expand Down
15 changes: 14 additions & 1 deletion tests/__mocks__/request-promise-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ const mockData: Record<string, any> = {
path: '/getMethod',
project_id: 27,
res_body_type: 'json',
req_body_form: [],
req_body_form: [{
required: '0',
_id: '5cbdd1c293bc6574a2de33dd',
name: ' trim ',
example: '2',
desc: '测试 trim 的值',
}],
req_params: [],
req_headers: [],
req_query: [
Expand All @@ -88,6 +94,13 @@ const mockData: Record<string, any> = {
example: '2',
desc: 'Y 值',
},
{
required: '0',
_id: '5cbdd1c293bc6574a2de33dc',
name: ' trim ',
example: '2',
desc: '测试 trim 的值',
},
],
markdown: '',
desc: '',
Expand Down
40 changes: 40 additions & 0 deletions tests/__snapshots__/Generator.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export interface GetMethodTestTestTestTestRequest {
* Y 值
*/
y?: string
/**
* 测试 trim 的值
*/
trim?: string
}
/**
Expand Down Expand Up @@ -414,6 +418,10 @@ export interface GetMethodTestTestTestTestRequest {
* Y 值
*/
y?: string;
/**
* 测试 trim 的值
*/
trim?: string;
}
/**
Expand Down Expand Up @@ -884,6 +892,10 @@ export interface GetMethodTestTestTestRequest {
* Y 值
*/
y?: string
/**
* 测试 trim 的值
*/
trim?: string
}
/**
Expand Down Expand Up @@ -2087,6 +2099,10 @@ export interface GetMethodTestTestTestRequest {
* Y 值
*/
y?: string;
/**
* 测试 trim 的值
*/
trim?: string;
}
/**
Expand Down Expand Up @@ -3244,6 +3260,10 @@ export interface GetMethodTestRequest {
* Y 值
*/
y?: string
/**
* 测试 trim 的值
*/
trim?: string
}
/**
Expand Down Expand Up @@ -4229,6 +4249,10 @@ export interface GetMethodTestRequest {
* Y 值
*/
y?: string;
/**
* 测试 trim 的值
*/
trim?: string;
}
/**
Expand Down Expand Up @@ -5243,6 +5267,10 @@ export interface GetMethodTestTestRequest {
* Y 值
*/
y?: string
/**
* 测试 trim 的值
*/
trim?: string
}
/**
Expand Down Expand Up @@ -6306,6 +6334,10 @@ export interface GetMethodTestTestRequest {
* Y 值
*/
y?: string;
/**
* 测试 trim 的值
*/
trim?: string;
}
/**
Expand Down Expand Up @@ -7840,6 +7872,10 @@ export interface GetMethodTestTestTestTestTestRequest {
* Y 值
*/
y?: string
/**
* 测试 trim 的值
*/
trim?: string
}
/**
Expand Down Expand Up @@ -9084,6 +9120,10 @@ export interface GetMethodTestTestTestTestTestRequest {
* Y 值
*/
y?: string;
/**
* 测试 trim 的值
*/
trim?: string;
}
/**
Expand Down
4 changes: 4 additions & 0 deletions tests/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ export interface GetMethodRequest {
* Y 值
*/
y?: string
/**
* 测试 trim 的值
*/
trim?: string
}
/**
Expand Down

0 comments on commit 23e3e35

Please sign in to comment.