-
Notifications
You must be signed in to change notification settings - Fork 6k
Java target: okhttp-gson-generated classes cleaned up, OAuth supports… #6405
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
base: master
Are you sure you want to change the base?
Conversation
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/swagger-api/swagger-codegen/graphs/contributors. Let me know if you need help fixing it. |
As far as I'm concerned, the change seems good. The code is clean. But I don't know okhttp at all so others advice might be needed. |
if(!"resttemplate".equals(getLibrary())) { | ||
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java")); | ||
} | ||
|
||
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java")); | ||
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java")); | ||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java")); | ||
supportingFiles.add(new SupportingFile("auth/OAuthBearerProvider.mustache", authFolder, "OAuthBearerProvider.java")); |
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.
This file shouldn't be added for retrofit library
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.
I can't make this conditional at the moment as OAuthBearerProvider is required to meaningfully implement OAuth and thus OAuth depends on this interface now - I don't seem to have identified a way to sensibly attach myself within OAuth lifecycle to supply new Bearer - one at the first server hit, a renewed one once the previous one expires.
As this is an interface only and very crucial for our needs, can you please elaborate more on why this can't be included when retrofit library is in place? Maybe I'm overlooking some basic concept..
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.
Retrofit has its own OAuth class that doesn't depend on OAuthBearerProvider so this would be dead code.
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.
Oh, ok. That means it does not have even OAuth itself, right? So the same rules should be applicable as for OAuth class, which is in there already. Or am I missing something?
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.
Double-checked the generation procedures again and got you - multiple OAuth classes are available based on the used library, I'll change the JavaClientCodegen accordingly.
|
||
package {{invokerPackage}}; | ||
|
||
public interface ApiClientHolder { |
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.
This doesn't seem to be used anywhere. What is it for ?
Sorry, didn't see the full diff...
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.
Just to elaborate a bit more on this - the client Api's generated by swagger do not implement any interface. ApiClientHolder is what it describes - a holder of ApiClient. It acts for us both as a way to reach ApiClient within generated Api as well as a way to hold more generated Api's and organize them meaningfully (better than using plain Object).
If I think from the top of my head, the other possibility would be to introduce something like SwaggerClient or SwaggerApi which would characterize the generated Api and allow manipulations with it. It would expose ApiClient within any such Api - just like ApiClientHolder does now.
What do you think?
@rdolejsi could you explain what the ApiClientRequestDecorator brings compared to an Interceptor ? |
RequestDecorator is indeed used to intercept outgoing request builder to decorate the request (with security features, extra headers, etc.). As there are no generic interceptors (just one HttpLoggingInterceptor), I chose the name to denote the pattern it's doing - decorating. On a second thought, we might as well introduce OutgoingRequestInterceptor to suit wider needs - what do you think? |
Okhttp has a generic Interceptor interface so how about just providing an |
Looks like Interceptor is called only after the request is built, thus allows to work with quite immutable objects. The current RequestDecorator (or be it OutgoingRequestInterceptor) allows you to work with Request.Builder, thus gaining access to the request structure before the actual request is created. |
3243dfb
to
5d078b7
Compare
New code version for this PR: OAuthBearerProvider related to base OAuth only, ApiClientHolder.mustache moved to correct scope - tests no longer fail. |
… supplying BearerProvider, ApiClient supports RequestDecorator
5d078b7
to
bf99a2c
Compare
@rdolejsi can you generate the java client samples ? |
@rdolejsi I got some errors after updating Java okhttp-gson samples:
Please take a look when you've time. |
@rdolejsi may I know if you need help fixing the error? Seems like it's missing a ) or ; |
…ct-specific type adapters
…lasses for query-based calls
…n serializer options
… supplying BearerProvider, ApiClient supports RequestDecorator
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for breaking (non-backward compatible) changes.Description of the PR
(details of the change, additional tests that have been done, reference to the issue for tracking, etc)