-
Notifications
You must be signed in to change notification settings - Fork 475
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
Add new Queries decorator to include all query parameters in one sing… #1309
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello there daniseijo 👋
Thank you and congrats 🎉 for opening your first PR on this project.✨
We will review the following PR soon! 👀
Looks great! Validation: Seems to make sense, I'll have to check what happens if we combine with Spec: No immediate questions, we can add that as another query parameter I presume. In general I think the easiest way to deal with the combination of several Query and Queries mixes is to not allow it. Otherwise this may blow up in complexity. There's an issue similar to this which proposed |
Hi! Thanks for the quick response, I would love a bit of help with the swagger part. I have created a method to spread the properties of the Queries object to show its internal query parameters on the swagger document. However, I'm not sure if this is the best approach. Could you check it out and also help me with the next steps to get this up and ready? PD.: I will try to add more negative test cases to check all the variations but I think I will not have time to advance until next week. |
Do we have any updates here? I really like this solution 😂 |
Hi, I implemented a solution for the swagger part but I am not sure if there is a cleaner way. If it is ok, maybe @WoH could help me with the next steps and have it merge. |
Thanks for the ping, I'll try to find time over the weekend to leave suggestions if needed |
Can you rebase this PR? CI on master should work again |
@@ -458,6 +467,15 @@ export class SpecGenerator3 extends SpecGenerator { | |||
return mediaType; | |||
} | |||
|
|||
private buildQueriesParameter(source: Tsoa.Parameter): Swagger.Parameter3[] { | |||
if (source.type.dataType === 'refAlias' && source.type.type.dataType === 'nestedObjectLiteral') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'refObject' should probably work here.
We should not only check 1 level deep on the alias, I've written similar code which checks deeep for isVoidType I think
If we can't handle, I'd rather throw than return an array I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this, I think is better to fail if there is a nested object, to be coherent with the @Query
decorator failing if we pass it a refObject
. @WoH What do you think?
@@ -173,12 +173,22 @@ export class SpecGenerator2 extends SpecGenerator { | |||
pathMethod.security = method.security; | |||
} | |||
|
|||
const queriesParams: Tsoa.Parameter[] = method.parameters.filter(p => p.in === 'queries'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see spec3
I think I've mentioned this, but we really don´t want both |
This PR 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 |
This is a good feature, please don't close this PR |
Any update on this PR? |
Just to be clear, this was not a no from my side. Just throw an Error of both Decorators are parsed in the same method |
Sorry, my intention is to fix the changes but I left my work where I worked with tsoa. Since then I have had no time to continue with this. I will try to take some time to read and solve the issues on the PR as soon as possible. Sorry again for the delay. |
Hi, I already made the changes to the code and added some more tests. @WoH, I wrote a response to one of your comments. Check it out and, if you think that behavior does not make sense, tell me and I will change it. In any case, I think the failing tests in some environments are not my fault anymore and they are more of a problem with a timeout. Whenever you can, check the PR again and let me know if I am missing something. |
Awesome! Can't wait for this to be published! |
@WoH Any chance you could push a new release with this then we can test it? :) Thanks for the work @daniseijo |
I wanted to write something like this, but since it's here it would be very much appreciate if we can speed this up :) Thanks for the hard work @daniseijo |
it's available! |
@daniseijo Thank you so much for implementing this. The lack of this almost stopped our adoption of tsoa cold. |
Is there any idea of when 5.0.0 will come out of RC and released? |
This PR adds a new
@Queries
decorator that accepts an object and wraps all the query parameters into it. This is something very useful for example if the request has a lot of filter parameters that we want to handle. It has been requested several times for example in this issue.I have tried to keep this new decorator behavior as similar as the Body and the BodyProps decorators were implemented.
Use example:
All Submissions:
If this is a new feature submission:
Potential Problems With The Approach
I have not tested yet if it would be a problem to have both the Queries and the Query decorator in one single function. It would be nice to add some test cases testing this.
Test plan
For what I wanted, the code is working as expected. I have tried to keep this new decorator as similar as you have implemented the Body and the BodyProps decorators. I still want to add more tests to check the doc generation but wanted to check if this approach was the correct one before continuing.