Skip to content
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 possibility to use custom annotations to detect query parameters #747

Open
porunov opened this issue Nov 10, 2021 · 2 comments · May be fixed by #750
Open

Add possibility to use custom annotations to detect query parameters #747

porunov opened this issue Nov 10, 2021 · 2 comments · May be fixed by #750

Comments

@porunov
Copy link

porunov commented Nov 10, 2021

In spring it's possible to use HandlerMethodArgumentResolver which can help to create custom data binders for Spring controllers (https://www.baeldung.com/spring-mvc-custom-data-binder#1-custom-argument-resolver).
For example, it's possible to create some methods which look like:

@RequestMapping(value = "/hello/{id}/world", method = RequestMethod.GET)
public ResponseEntity<GetResponse> getMethod(@PathVariable String id, 
                                             @MyCustomQueryParameter Set<String> customQueryParameter,
                                             @MyCustomQueryParameter Integer customHeaderParameter) {
    return null;
}

in HandlerMethodArgumentResolver it's possible to describe logic of how exactly those method parameters are going to be bound.
It would be great if we could somehow specify such method parameters and be able to generate them in typescript.

porunov added a commit to porunov/typescript-generator that referenced this issue Nov 21, 2021
…meters

Adds possibility to detect Spring request parameters using custom annotations
Adds possibility to detect Spring request body using custom annotations

Fixes vojtechhabarta#747

Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>
@vojtechhabarta
Copy link
Owner

Hello, the problem with custom resolvers is that they can do pretty much anything. They can for example get request parameter with any name (different from Java parameter name), convert strings to lists, or even get header instead of request parameter. So I don't think it is in general possible to produce TypeScript description when we don't know what the resolver is doing.

porunov added a commit to porunov/typescript-generator that referenced this issue Feb 3, 2022
…meters

Adds possibility to detect Spring request parameters using custom annotations
Adds possibility to detect Spring request body using custom annotations

Fixes vojtechhabarta#747

Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>
@porunov
Copy link
Author

porunov commented Feb 5, 2022

Hello, the problem with custom resolvers is that they can do pretty much anything. They can for example get request parameter with any name (different from Java parameter name), convert strings to lists, or even get header instead of request parameter. So I don't think it is in general possible to produce TypeScript description when we don't know what the resolver is doing.

I agree with you that using custom argument resolver is more challenging but at least having a possibility to declare such parameters in typescript helps to resolve the issue partially.
I made a PR #750 which might resolve this issue (at least from what I described initially). The PR doesn't solve the issue with custom names.
That said, I have another PR #788 which could be more effective in such situations. With this PR it will be possible to use a little bit of Reflection before the typescript method is generated and solve this issue and other similar issues when we need to have different query parameters.
For example, with #788 it will be possible to check if a specific method has any arguments annotated with @MyCustomQueryParameter and if so add such query parameters to the final method (or maybe the entity body or path variables, depending on the logic).
Let me know what you think about it

porunov added a commit to porunov/typescript-generator that referenced this issue Jun 7, 2022
…meters

Adds possibility to detect Spring request parameters using custom annotations
Adds possibility to detect Spring request body using custom annotations

Fixes vojtechhabarta#747

Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants