-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tsoa not generating when given an OR operator in response #352
Comments
Any updates? Is there a maintainer for this repo? I've also tried giving another interface
The issue is actually in swagger, which turns this into However this is dealt with here |
@oreporan we're actively working on fixing this. There's a new issue number (#393) that we're using to track this so I'm going to close this issue. And there's already a PR out with a proposal #400. Please note that union types can not be represented in Swagger 2.0, but they can be in OpenAPI 3.0. So once PR #400 merges, you'll need change |
@oreporan I'm happy to report that the we added our first draft of unions and intersections in v2.4.11. Please consider upgrading to it and let us know how it works for you. :) Please note: you must have config.swagger.specVersion set to 3 for this to work since I'm not 100% confident that we handled the |
Hi everyone , I've got that problem. TSOA (v. {
"swagger": {
"basePath": "/api/v1",
"entryFile": "./src/main.ts",
"noImplicitAdditionalProperties": "silently-remove-extras",
"specVersion": 3,
"outputDirectory": ".",
"controllerPathGlobs": ["./src/controllers/**/*.ts"]
},
"routes": {
"authenticationModule": "./src/utils/authentication.ts",
"basePath": "/api/v1",
"entryFile": "./src/main.ts",
"routesDir": "./src/server",
"middleware": "express"
}
}
Part of controller where caused exception @Route("/jobs")
@Tags('Jobs')
export class JobsController extends Controller {
@Get('/{id}')
@Security("jwt")
public async getJob(@Path('id') jobId: string): Promise<Job | null> { // here
return getJobById(jobId);
}
} |
Just a reminder: The workaround is to make it a union with undefined. But yes, #479 tracks the feature enhancement to allow a union with null. |
I have exactly this problem, but with
|
This error still persists as explained by others above. |
I have the same error |
I'll bump this thread because I have the same issue with: @Get("{folderId}")
public async getFolderById(@Path() folderId: string): Promise<Folder | undefined> {
return await this.folderService?.getFolderById(folderId);
}; In this case I'm using TypeORM, and most of its functions return either an entity or |
So what's the JSON Schema for |
What I ended up doing was something like: @Get("{folderId}")
public async getFolderById(@Path() folderId: string): Promise<Folder | null> {
const result = await this.folderService?.getFolderById(folderId);
return result === undefined ? null : result;
} This prevents the I'm guessing it's just a matter of |
It does not mean the same thing. E: I've elaborated in the past, maybe someone can link the comment. The TL;DR ist: you can easily translate an optional property on an object to JSON Schema but not undefined the keyword, because it may not be valid. Trying to return undefined and selling it as JSON is a pretty good example of that. But that's enough of a devolution, stick to the relevant issues for the UndefinedKeyword errors. |
When I create a controller that returns
The swagger generated code returns
I understand that type aliases are not allowed in the response, but what is the correct syntax to allow returning null?
The text was updated successfully, but these errors were encountered: