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 pass request headers to HttpClient #790

Open
porunov opened this issue Feb 5, 2022 · 1 comment · May be fixed by #791
Open

Add possibility to pass request headers to HttpClient #790

porunov opened this issue Feb 5, 2022 · 1 comment · May be fixed by #791

Comments

@porunov
Copy link

porunov commented Feb 5, 2022

Right now the generated HttpClient interface looks like the next one:

export interface HttpClient {
    request<R>(requestConfig: { method: string; url: string; queryParams?: any; data?: any; copyFn?: (data: R) => R; }): RestResponse<R>;
}

The interface lacks a possibility to accept request headers which might be sometimes used to represent some incoming arguments.
For example, in Spring you would typically define the next arguments to accept headers in your controller:

@GetMapping(value = "/test")
public ResponseEntity<ResponseEntity> test(
        @RequestHeader("first-header") Integer argument1,
        @RequestHeader("second-header") String argument2) {
    return null;
}

Right now, both arguments Integer argument1 and String argument2 are ignored.

It would be great to add possibility to register header arguments as well and be able to pass them into HttpClient.

I'm not that familiar with the code base right now but I guess that we should do something like the next:

  • Add headers collection in RestMethodModel. I guess something like private final List<MethodParameterModel> headerParams; should be enough.
  • Add headers resolution logic into ModelCompiler.processRestMethod.
  • Add possibility to accept headers in HttpClient.

If combined with #788 then this may be enough for any user to register custom headers on it's own if needed.
Without #788 the below steps might be necessary as well.

Another (optional) task might be related to detecting Spring @RequestHeader automatically (without using custom logic via #788). So, I would think about steps like the next:

  • Optionally add a parameter in Settings which enables headers resolution logic (in case someone would like to omit this feature for any reason).
  • Add annotation detection logic into SpringApplicationParser.parseControllerMethod.
porunov added a commit to porunov/typescript-generator that referenced this issue Feb 6, 2022
Fixes vojtechhabarta#790

Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>
@porunov porunov linked a pull request Feb 6, 2022 that will close this issue
porunov added a commit to porunov/typescript-generator that referenced this issue Feb 6, 2022
Fixes vojtechhabarta#790

Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>
porunov added a commit to porunov/typescript-generator that referenced this issue Jun 7, 2022
Fixes vojtechhabarta#790

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

aerfus commented Dec 11, 2023

+1 for this PR.
@vojtechhabarta could you please check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants