typescript-rest-swagger
typescript-rest-swagger copied to clipboard
Faild to generate swagger with 'type' fields
For next example:
export type TypeExmaple = number[] | number[][];
export class Test {
field: TypeExmaple;
}
Swagger generation:
@Path('/test')
@Accept('application/json')
@Produces('application/json')
export class TestSwagger {
@POST
submit(_test: Test): void {
}
}
Is failing with next error:
Error generate parameter method: 'TestSwagger.submit' argument: _test TypeError: Cannot read property 'text' of undefined
If used without type:
export class Test {
field: number[] | number[][];
}
Compilation succeed.
Is it a way to generate swagger file with type?
version used: "0.0.22"
I have the similar problem if I use custum types:
@Path('/linker/investors')
@GET
async getLinkerInvestors(): Promise<(User | VCGroup)[]> {
return this.adminService.getLinkerInvestors()
}
It return an error
.nvm/versions/node/v9.3.0/lib/node_modules/typescript-rest-swagger/dist/metadata/resolveType.js:37 throw new Error("Unknown type: " + ts.SyntaxKind[typeNode.kind]);
If you look at resolveType, it seems like many types are manually supported in order to boil down to actual primitives.
I'm not very familiar with the typescript API, and didn't get far in trying to add support here. Also just a nice-to-have for my project, so will probably just shelve for now -- I'm just leaving return type off my service method signatures so typescript-rest-swagger doesn't pick them up. The only problem there is without a return type it automatically sets up a default empty 204 response.
I think a good workaround would be to have an option of whether to try and parse return type from the method signature. Then we could still type our service methods however we need to, and could use @Response for docs.
Proposed API
enableReturnAnalysis | boolean | Turn off to skip automatic response generation from method return analysis. Defaults to true.