-
Notifications
You must be signed in to change notification settings - Fork 504
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
Swagger not showing intersection model properly #391
Comments
@avizcaino there are a couple of things currently going on here.
Workaround: Until we add support for aggregate types (#393), please consider creating your input type tool look as follows: export interface IIQCommentRecord {
id: string;
comment: string;
}
export interface DomainCommand{
aggregateId: string;
}
export interface ICommandDictionary {
[key: string] : IIQCommentRecord
}
export interface AddCommentCommand {
command: DomainCommand,
commentsForCommand: ICommandDictionary,
} This will create swagger models that look like:
I think those models will be much more helpful. I'm closing this issue so we can track the larger feature in #393. |
@avizcaino 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. :) |
Hi! I'm trying this new version but I'm encountering new errors that did not occur previously...
It looks like it is caused by a generic type in an interface
But this was working before... has something changed in the last release? |
@avizcaino yes, we added the ability to calculate swagger docs from intersection and aggregate types. Can you please copy here (1) your controller file and (2) the file that contains your interfaces? I will try to fix the error, but I am fairly confident that the error is due to you using an interface that lives in node_modules. It’s regrettable that the error is only manifesting after we introduced the new feature that allows unions and intersections, but tsoa has never been able to use interfaces in node_modules (that’s why the error links to a document I wrote that explains this in detail). I believe you weren’t seeing this previously due to the fact that unions were essentially ignored before. Now that they’re not being ignored... you get the true tsoa reaction which is to point out “hey we couldn’t find this interface.” So please confirm to me that the interface you’re passing in as the type parameter to IIQEventBase is in an interface living in node modules. If so, the workaround is described in the link that the error threw. |
@dgreene1 I can explain what happened (since I introduced the relevant code): This happens because tsoa doesn't really pass down the type arguments as parameters, but substitutes |
@WoH is there a way to preserve the original interface name for |
Yes, there is. Whenever there is a I think I have an approach to solve this issue, which would hopefully fix generic interfaces with an arbitrary amount of type parameters and handle propagating the arguments down the type resolver "right" in terms of correctness, but that'll take some time to do. I am very sorry @avizcaino for exposing you to this. |
@dgreene1 I have the code, no tests no nothing, but I'd like to open a draft PR so we can spec this together, are you ok with that? |
Yes please. Thank you for looking into it @WoH. |
@avizcaino 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 |
Hi! I'm sorry to say that we still have the same problem... @dgreene1, as you requested, here is the controller and interface (summarized):
Not sure what we are doing wrong... This works on 2.4.7. @WoH don't worry, we still can fix to previous versions in the meantime. Thanks to you for your work and ultra-fast answer! |
I think it might be the WoH has something to test below. |
We do not check the heritage clauses for type arguments, that's the issue here. Duplicate of #467. Edit. Can you try this? : export interface IPatientIQ {
events?: IIQSingleEvent<Event>[];
}
export interface IIQSingleEvent<T = any> extends IIQEventBase<T> {
timestamp: Date;
}
export interface IIQEventBase<T = any> {
value: T | string;
}
export const enum Event {
Dummy = 'DM'
} |
yep, that solution works, although I would like to maintain the original solution since the model is likely to grow in future iterations. |
File a PR for #467 and you can 😉 We get the properties here: However, you need a new context that only applies during resolution of the inherited properties. In this context, you should use the type arguments or forward from the context: I.e. let a: ThingContainerWithTitle<string, string>;
interface ThingContainerWithTitle<T, U> extends GenericContainer<number, U> {
// T is string here
t: T;
title: string;
}
interface GenericContainer<T, U> {
// U is string
id: U;
// T is number here
list: T[];
} |
I'm not sure if this issue is related |
I have the following model:
Where key can be any key since we are working with a quite dynamic interface.
Build works great but the model shown in Swagger UI is the following:
Is there any way to show this intersecction properly? I would expect both
aggregateId
and the dictionary to show on the model.The text was updated successfully, but these errors were encountered: