Skip to content

Commit

Permalink
handle implicit types
Browse files Browse the repository at this point in the history
  • Loading branch information
kt81 committed Sep 27, 2018
1 parent 649a066 commit bbc9072
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/baseInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export interface IRequestMethod {
description: string
schema: {
'$ref': string,
'type': string,
'type'?: string,
'items'?: IParameterItems,
}
}
}
Expand Down
21 changes: 17 additions & 4 deletions src/requestCodeGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,31 @@ export function requestCodeGen(paths: IPaths, options: ISwaggerOptions): string
pathReplace = parsedParameters.requestPathReplace
}

// 确定响应的类型
// It does not allow the schema defined directly, but only the primitive type is allowed.
let responseType: string;

if (!v.responses['200'] || !v.responses['200'].schema) {
responseType = 'any';
} else if (v.responses['200'].schema.$ref) {
responseType = refClassName(v.responses['200'].schema.$ref)
} else {
responseType = v.responses[200].schema.type;
if (responseType == 'object' || responseType == 'array') {
// Direct defining is not supported.
let checkType = v.responses[200].schema.type;
if (!checkType) {
// implicit types
if (v.responses[200].schema.items) {
responseType = 'array';
} else { // if (v.responses[200].schema.properties) // actual check
responseType = 'object';
}
} else {
responseType = checkType; // string? -> string
}
if (responseType == 'object') {
responseType = 'any';
} else if (responseType == 'array') {
responseType = 'any[]';
}
// else ... JSON primitive types (string, boolean, number)
}

// 模版
Expand Down

0 comments on commit bbc9072

Please sign in to comment.