Comments (21)
I see that support for this was merged, but if I try to use Promise<ResultList<Resource>>
I get an error:
$ ./node_modules/.bin/tsoa swagger
There was a problem resolving type of 'T'.
There was a problem resolving type of 'ResultListResource'.
Error: No matching model found for referenced type T
with ResultList
being
interface ResultList<T> {
data: T[],
}
version: [email protected]
from tsoa.
+1
from tsoa.
That's absolutely awesome. I love it!
But still have similar issue adding extends
export interface ThingContainerWithTitle extends GenContainer<TheThing> {
title: string;
}
export interface GenContainer<T> {
id: string;
list: T[];
}
And I got
There was a problem resolving type of 'T'.
There was a problem resolving type of 'GenContainer'.
There was a problem resolving type of 'ThingContainerWithTitle'.
from tsoa.
@mrgoonie I had the exact same issue today, the problem is that the return type of getMessage()
isn't explicitly typed.
@Get()
async getMessage() {
const data: PingEntity = { message: "pong" };
let result: ResponseObject<PingEntity> = { status: 1, data };
return result;
}
Should be changed to:
@Get()
async getMessage(): Promise<ResponseObject<PingEntity>> {
const data: PingEntity = { message: "pong" };
let result: ResponseObject<PingEntity> = { status: 1, data };
return result;
}
from tsoa.
I think this can be supported and it's a great idea. I'll look into it soon.
from tsoa.
@nenadalm +1 same here
from tsoa.
Just something i came across while fiddling with the above
The following seems to work:
interface ResultList {
data: T,
}
The following doesn't, gives the above error that @nenadalm mentioned:
interface ResultList {
data: T[],
}
The following doesn't as well
interface ResultList {
data: Array,
}
from tsoa.
+1 on this! I can't make something like
export interface IListPage<T> {
pageIndex: number;
totalPages: number;
list: T[];
}
And use as result Promise<IListPage<MyCoolItem>>
from tsoa.
+1, i have the same issue
from tsoa.
@lukeautry Hello, anytning on this? Its been sitting there dormant for a while
from tsoa.
+1, same issue here. This seems a particularly important feature for code maintenance.
from tsoa.
Hello, still have a kind a similar issue :
There was a problem resolving type of 'T'.
There was a problem resolving type of 'JsonApiResourceT'.
There was a problem resolving type of 'JsonApiWrapperUserAttributes'.
Generate routes error.
Error: No matching model found for referenced type T.
at new GenerateMetadataError (/Users/thibaut/Documents/poc/jsonapi-serializer/node_modules/tsoa/dist/metadataGeneration/exceptions.js:17:28)
at getModelTypeDeclaration (/Users/thibaut/Documents/poc/jsonapi-serializer/node_modules/tsoa/dist/metadataGeneration/resolveType.js:419:15)
at getReferenceType (/Users/thibaut/Documents/poc/jsonapi-serializer/node_modules/tsoa/dist/metadataGeneration/resolveType.js:280:25)
at resolveType (/Users/thibaut/Documents/poc/jsonapi-serializer/node_modules/tsoa/dist/metadataGeneration/resolveType.js:95:25)
at /Users/thibaut/Documents/poc/jsonapi-serializer/node_modules/tsoa/dist/metadataGeneration/resolveType.js:496:23
at Array.map (<anonymous>)
at getModelProperties (/Users/thibaut/Documents/poc/jsonapi-serializer/node_modules/tsoa/dist/metadataGeneration/resolveType.js:462:14)
at getReferenceType (/Users/thibaut/Documents/poc/jsonapi-serializer/node_modules/tsoa/dist/metadataGeneration/resolveType.js:281:26)
at resolveType (/Users/thibaut/Documents/poc/jsonapi-serializer/node_modules/tsoa/dist/metadataGeneration/resolveType.js:92:25)
at resolveType (/Users/thibaut/Documents/poc/jsonapi-serializer/node_modules/tsoa/dist/metadataGeneration/resolveType.js:69:30)
I use tsoa in version 2.1.4.
Here is my controller :
@Route("users")
export class UsersController extends Controller {
@Get("{id}")
public async getUser(
@Path("id") id: number,
@Query() name?: string
): Promise<JsonApiWrapper<UserAttributes>> {
const user = await UserService.get(id);
return SerializerService.serialize(user);
}
@SuccessResponse("201", "Created")
@Post()
public async createUser(
@Body() requestBody: UserCreationRequest
): Promise<JsonApiWrapper<UserAttributes>> {
const user = await UserService.create(requestBody);
this.setStatus(201); // set return status 201
return SerializerService.serialize(user);
}
}
and my Models :
User.ts
export interface User extends UserAttributes {
apiId: number;
}
export interface UserAttributes {
email: string;
name: Name;
status?: Status;
phoneNumbers: string[];
}
export type Status = "Happy" | "Sad";
export interface Name {
first: string;
last?: string;
}
export interface UserCreationRequest {
email: string;
name: Name;
phoneNumbers: string[];
}
JsonApiWrapper.ts
export interface JsonApiWrapper<T> {
data?:
| JsonApiResource<T>
| Array<JsonApiResource<T>>
| JsonApiResourceIdentifier
| JsonApiResourceIdentifier[]
| null;
error?: JsonApiError[];
meta?: JsonApiMeta;
jsonapi?: any;
links?: JsonApiWrapperLinks;
included?: Array<JsonApiResource<T>>;
}
JsonApiError.ts
export interface JsonApiError {
id?: string;
links?: JsonApiErrorLinks;
status?: string;
code?: string;
title?: string;
detail?: string;
source?: JsonApiErrorSource;
}
export interface JsonApiErrorSource {
pointer: string;
parameter: string;
meta: JsonApiMeta;
}
JsonApiMeta.ts
export interface JsonApiMeta {
[key: string]: any;
}
JsonApiResource.ts
export interface JsonApiResource<T> {
type: string;
id?: string;
attributes?: T;
relationships?: JsonApiRelationships;
links?: JsonApiResourceLinks;
meta?: JsonApiMeta;
}
export interface JsonApiResourceIdentifier {
type: string;
id: string;
meta?: any;
}
JsonApiRelationships.ts
export interface JsonApiRelationships {
[key: string]: JsonApiRelationship;
}
export interface JsonApiRelationship {
links: JsonApiLinks;
data: JsonApiResourceIdentifier | JsonApiResourceIdentifier[] | null;
}
JsonApiLinks.ts
export interface JsonApiLinks {
self?: string | JsonApiLinkObject;
related?: string | JsonApiLinkObject;
[key: string]: string | JsonApiLinkObject;
}
export interface JsonApiLinkObject {
href: string;
meta: any;
}
export interface JsonApiResourceLinks extends JsonApiLinks {
self: string | JsonApiLinkObject;
related: string | JsonApiLinkObject;
}
export interface JsonApiErrorLinks extends JsonApiLinks {
about: string | JsonApiLinkObject;
}
export interface JsonApiWrapperLinks extends JsonApiLinks {
first?: string | JsonApiLinkObject;
last?: string | JsonApiLinkObject;
prev?: string | JsonApiLinkObject;
next?: string | JsonApiLinkObject;
}
any update on this issue ?
from tsoa.
So I tried to replace some generic parts of my interface and the following interface replacing JsonApiWrapper seems to work :
JsonApiUser.ts
export interface JsonApiUser {
data?:
| JsonApiResource<UserAttributes>
| Array<JsonApiResource<UserAttributes>>
| JsonApiResourceIdentifier
| JsonApiResourceIdentifier[]
| null;
error?: JsonApiError[];
meta?: JsonApiMeta;
jsonapi?: any;
links?: JsonApiWrapperLinks;
included?: Array<JsonApiResource<UserAttributes>>;
}
I think it's the passing on of the generic type to another generic interface that bring on the issue.
from tsoa.
Bump. Any plans to fix this?
from tsoa.
This is definitely a desirable feature but it's some work to implement it handle all of the cases.
from tsoa.
Full support for generics was added in v2.4.10.
from tsoa.
@dgreene1 I think this should be re-opened as I'm still seeing the behavior described above.
It can be replicated by replacing
tsoa/tests/fixtures/testModel.ts
Lines 360 to 363 in ac71d13
with
export interface GenericRequest<T> {
name: string;
value: T;
nested?: GenericNested<T>;
}
export interface GenericNested<T> {
foo: T;
}
and re-running the tests:
There was a problem resolving type of 'T'.
There was a problem resolving type of 'GenericNestedT'.
There was a problem resolving type of 'GenericRequestTypeAliasModel1'.
There was a problem resolving type of 'GenericRequestGenericRequestTypeAliasModel1'.
There was a problem resolving type of 'TestModel'.
from tsoa.
@ryankeener I know you already confirmed that this works, but I wanted to let you know that this fix/feature was just released in v2.5.1. Can you let us know how it worked out for you?
Side note: we're looking for companies that want to be featured in tsoa's readme: #464
from tsoa.
@fhewitt would you be so kind as to make a separate issue for that scenario since the non-extended generic scenarios seem to be resolved?
from tsoa.
Can do that! > #467
from tsoa.
Hi @WoH @dgreene1, sorry for digging this but I think this issue isn't fully resolved (or maybe I'm doing something incorrectly).
import { Get, Route } from "tsoa";
interface ResponseObject<T> {
status: number;
data: T | any;
}
interface PingEntity {
message: string;
}
@Route("ping")
export default class PingController {
@Get()
async getMessage() {
const data: PingEntity = { message: "pong" };
let result: ResponseObject<PingEntity> = { status: 1, data };
return result;
}
}
When I try to generate the swagger json it throws this error:
There was a problem resolving type of 'ResponseObject<any>'.
Generate swagger error.
Error: Debug Failure. False expression: Node must have a real position for this operation
But when I specified the type directly to ResponseObject
(instead of using generic type), it will works normally:
interface ResponseObject {
status: number;
data: PingEntity;
}
Here is the example repo: https://github.com/mrgoonie/express-swagger-typescript
Temporary workaround solution:
import { Get, Route } from "tsoa";
// no generic type
interface ResponseObject {
status: number;
data: any;
}
interface PingEntity {
message: string;
}
@Route("ping")
export default class PingController {
@Get()
async getMessage() {
const data: PingEntity = { message: "pong" };
// use type combination instead of generic type
let result: ResponseObject & { data: PingEntity } = { status: 1, data };
return result;
}
}
Cheers,
from tsoa.
Related Issues (20)
- Cannot read properties of undefined (reading 'length') with @UploadedFile HOT 1
- Build error: Property 'name' is missing HOT 7
- Can't Handle File and Non-File Field on multipart/form-data simultaneously HOT 4
- Can't Handle Optional File Field on multipart/form-data HOT 1
- Proposal/file upload configurations HOT 2
- UnknownType: IndexedAccessType error when using enum to index type object HOT 1
- The latest version 6.1.4 causes new build issues. HOT 10
- Middleware after response HOT 6
- After update 6.1.5 Types of property 'successStatus' are incompatible HOT 16
- Handling parameters that include mapped types with `Date` as a generic argument HOT 1
- ErrorHandlerMiddleware is ignore with 6.1.* HOT 11
- Populate causes error log: Debug Failure. False expression: Node must have a real position for this operation HOT 3
- ' HOT 1
- Treat null values as no value or undefined HOT 2
- jsdoc @example is used for union type but ignored for enum HOT 3
- programmatic way to generate the spec and routes HOT 12
- Custom parameters in controller
- Evaluate @Security in order of definition HOT 1
- AuthenticationMiddleware should also depend on authenticationModule being present HOT 1
- Unable to assign null to properties defined as number | null | undefined after updating to version 6.2.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tsoa.