I would like to be able to set controller return type from useCase it is running inside:
@Route('data')
@Tags('Data')
export class DataController extends Controller {
@Get('tax-offices')
@Security('jwt')
public async getTaxOffices(@Request() request: AppRequest,
@Header('company-id')companyId: string): ReturnType<GetTaxOfficesUseCase['run']> {
const ctx: Context = getContextFromRequest(request);
const res = await getTaxOfficesUseCase.run({ ctx });
this.setStatus(201);
return res;
}
}
Now it is impossible, when using [email protected]
Generate routes error.
Error: Unknown type: IndexedAccessType.
at new GenerateMetadataError (/packages/web-server/node_modules/tsoa/dist/metadataGeneration/exceptions.js:20:28)
at TypeResolver.getAnyTypeName (/packages/web-server/node_modules/tsoa/dist/metadataGeneration/typeResolver.js:290:19)
at /packages/web-server/node_modules/tsoa/dist/metadataGeneration/typeResolver.js:275:72
at Array.map ()
at TypeResolver.getTypeName (/packages/web-server/node_modules/tsoa/dist/metadataGeneration/typeResolver.js:275:40)
at TypeResolver.getReferenceType (/packages/web-server/node_modules/tsoa/dist/metadataGeneration/typeResolver.js:223:40)
at TypeResolver.resolve (/packages/web-server/node_modules/tsoa/dist/metadataGeneration/typeResolver.js:99:34)
at MethodGenerator.Generate (/packages/web-server/node_modules/tsoa/dist/metadataGeneration/methodGenerator.js:32:76)
at /packages/web-server/node_modules/tsoa/dist/metadataGeneration/controllerGenerator.js:40:58
at Array.map ()
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
Also running into this issue.
2.3.7 works though
@jaredkotoff can you add code to show how you’re reproducing the issue? We need as much information as possible to be able to fix this and/or enhance it. It’s not clear if this ever properly produced good Swagger schemas or if it just silently did nothing. So what Swagger Schema output did you get in v2.3.7?
@gitowiec / @Circle6 can you also add what Swagger Schema you were getting in v2.3.7 and then tell us what you want to have produced?
@dgreene1
I simplified the code
export interface Location {
key: {
addressFull: FullStateTest["addressFull"];
}
}
export interface FullStateTest {
addressFull: string;
}
and our controller is trying to return type Location
@Route("api/v1/locations")
export class LocationControllerV1 extends Controller {
@Get("search")
public async search(): Promise<Location> {
return await GetLocations();
}
}
output swagger.json
{
"basePath": "/",
"consumes": [
"application/json"
],
"definitions": {
"Location": {
"properties": {
"key": {
"type": "object"
}
},
"required": [
"key"
],
"type": "object"
}
},
"info": {
"title": "API v1",
"version": "1.0.0",
"license": {
"name": "ISC"
}
},
"paths": {
"/api/v1/locations/search": {
"get": {
"operationId": "Search",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Ok",
"schema": {
"$ref": "#/definitions/Location"
}
}
},
"security": [],
"parameters": []
}
}
},
"produces": [
"application/json"
],
"swagger": "2.0",
"securityDefinitions": {},
"host": "/v1",
}
@jaredkotoff we still need to know this:
So what Swagger Schema output did you get in v2.3.7?
@dgreene1 i updated my previous comment.
note that the key property was needed in Location otherwise i wasn't able to get a swagger scheme output in 2.3.7
Since the Schema for Location was set to Object in the generated output for v2.3.7 that leads me to believe that tsoa never supported IndexedAccessType. Additionally, I can’t find any evidence in the code that we ever had logic to handle or to test for this functionality. So this is definitely a new feature and not a bug.
I’ve marked this as an “enhancement” and “help wanted” so that contributors will be made aware that we’re open to PRs for this feature.
That being said, there are plenty of workarounds for this that too numerous to list. For instance, inverting the reference, not using a reference, etc.
And for clarity, the Schema that tsoa used to produce was always wrong:
"definitions": {
"Location": {
"properties": {
"key": {
"type": "object"
}
},
"required": [
"key"
],
"type": "object"
}
},
If someone submits a PR, it should produce this schema:
"definitions": {
"Location": {
"properties": {
"key": {
“type”: “object”,
“properties: {
“addressFull” : { “type”: “string”},
“required”: [“addressFull”]
}
},
"required": [
"key"
],
"type": "object"
}
},
Most helpful comment
And for clarity, the Schema that tsoa used to produce was always wrong:
If someone submits a PR, it should produce this schema: