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

Provide a way to set an example headers for each registration b… #2100

Merged

Conversation

@heowc
Copy link
Contributor

heowc commented Sep 20, 2019

Motivation:

A user cannot specify an example header when adding a service using ~ServiceRegistrationBean.

Modifications:

  • Add ExampleHeaders for {Annotated,Thrift}ServiceRegistrationBean
  • Add GrpcExampleHeaders for GrpcServiceRegistrationBean
  • Make the GrpcExampleHeaders are added to DocService
  • Make the ExampleHeaders are added to DocService
  • Fix test code

Result:

  • User friendliness.
@heowc heowc marked this pull request as ready for review Sep 22, 2019
@heowc heowc requested review from ikhoon, minwoox and trustin as code owners Sep 22, 2019
@heowc heowc changed the title [WIP] Provide a way to set an example headers for each registration bean Provide a way to set an example headers for each registration bean Sep 22, 2019
@ikhoon ikhoon added the new-feature label Sep 22, 2019
@ikhoon ikhoon added this to the 0.93.0 milestone Sep 22, 2019
Fix code
- Fix for loop to `forEach`
- Rename `exampleHttpHeaders` to `exampleHeaders`
@codecov

This comment has been minimized.

Copy link

codecov bot commented Sep 23, 2019

Codecov Report

Merging #2100 into master will decrease coverage by 0.26%.
The diff coverage is 59.86%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2100      +/-   ##
============================================
- Coverage     73.78%   73.52%   -0.27%     
- Complexity     9492     9532      +40     
============================================
  Files           833      837       +4     
  Lines         36537    36800     +263     
  Branches       4524     4532       +8     
============================================
+ Hits          26958    27056      +98     
- Misses         7256     7405     +149     
- Partials       2323     2339      +16
Impacted Files Coverage Δ Complexity Δ
...rp/armeria/spring/HttpServiceRegistrationBean.java 21.05% <0%> (-58.95%) 3 <0> (ø)
.../armeria/spring/ThriftServiceRegistrationBean.java 58.33% <33.33%> (-41.67%) 5 <2> (-2)
...rp/armeria/spring/GrpcServiceRegistrationBean.java 40% <37.5%> (-22.5%) 4 <3> (+1)
...meria/spring/AnnotatedServiceRegistrationBean.java 71.42% <42.85%> (-10.06%) 12 <3> (ø)
...rmeria/spring/AbstractServiceRegistrationBean.java 56.25% <42.85%> (-36.61%) 13 <5> (+4)
...com/linecorp/armeria/spring/GrpcExampleHeader.java 64.7% <64.7%> (ø) 7 <7> (?)
...ava/com/linecorp/armeria/spring/ExampleHeader.java 71.42% <71.42%> (ø) 7 <7> (?)
...eria/internal/spring/ArmeriaConfigurationUtil.java 75.43% <92.15%> (+1.89%) 53 <8> (+6) ⬆️
...ecorp/armeria/client/ResponseTimeoutException.java 80% <0%> (-20%) 3% <0%> (ø)
...linecorp/armeria/client/WriteTimeoutException.java 80% <0%> (-20%) 3% <0%> (ø)
... and 28 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3959fc3...915b0a5. Read the comment docs.

Fix code
- Add setExample{Request,Header}()
- Add addExample{Request,Header}()
- Fix javadoc
- Remove methods(getExample{Request,Header}()) of
HttpServiceRegistrationBean
@minwoox

This comment has been minimized.

Copy link
Member

minwoox commented Sep 25, 2019

As I said here, people might want to set an example headers for only a specific method. For example:

class MyAnnotatedService {
    @Post("/a")
    public String a(@Header String myHeader) {
        ...
    }
    @Get("/b")
    public String b() {
        ...
    }
}

In this case, if a user wants to set an example headers only for the method a, he/she must use DocServiceBuilder. He cannot do it using this beans.
Could you address this issue as well?

@minwoox minwoox modified the milestones: 0.93.0, 0.94.0 Sep 25, 2019
…ader-for-x-registration-bean

Fix merge
@heowc

This comment has been minimized.

Copy link
Contributor Author

heowc commented Sep 25, 2019

As I said here, people might want to set an example headers for only a specific method. For example:

class MyAnnotatedService {
    @Post("/a")
    public String a(@Header String myHeader) {
        ...
    }
    @Get("/b")
    public String b() {
        ...
    }
}

In this case, if a user wants to set an example headers only for the method a, he/she must use DocServiceBuilder. He cannot do it using this beans.
Could you address this issue as well?

I'll analyze a little more to solve this. :)

@heowc

This comment has been minimized.

Copy link
Contributor Author

heowc commented Sep 25, 2019

@minwoox, Please advise about my opinion.

I think {Annotated,Grpc,Thrift}Headers is needed to solve the above. For example,

public final class GrpcExampleHeaders {

    // for only a specific method 
    public static GrpcExampleHeaders of(@NotNull String serviceType,
                                        @NotNull String methodName,
                                        @NotNull HttpHeaders exampleHeaders) {
        return new GrpcExampleHeaders(serviceType, methodName, exampleHeaders);
    }
    // for all method
    public static GrpcExampleHeaders of(@NotNull String serviceType,
                                        @NotNull HttpHeaders exampleHeaders) {
        return new GrpcExampleHeaders(serviceType, "", exampleHeaders);
    }

    private final String serviceType;
    private final String methodName;
    private final HttpHeaders exampleHeaders;

    // constructor, getter ...
}

And each registration beans has to additional methods(for only a specific method).

@minwoox

This comment has been minimized.

Copy link
Member

minwoox commented Sep 26, 2019

I think {Annotated,Grpc,Thrift}Headers is needed to solve the above.

So do I. 😄 One thing that we have to consider here is, unlike example requests, the types of the example headers for three services are same which is HttpHeaders. To reduce duplicate code, I think we can introduce ExampleHeader for Annotated and Thrift services and GrpcExampleHeader for the gRPC service. /cc @trustin @ikhoon

@trustin

This comment has been minimized.

Copy link
Member

trustin commented Sep 26, 2019

@minwoox wrote:

To reduce duplicate code, I think we can introduce ExampleHeader for Annotated and Thrift services and GrpcExampleHeader for the gRPC service.

Sounds good to me.

Copy link
Member

trustin left a comment

Looks good to me once the comments from @minwoox and @ikhoon are addressed.

@heowc

This comment has been minimized.

Copy link
Contributor Author

heowc commented Sep 27, 2019

Thanks you for good opinion.
I will write the code and send you a request re-review. :)

heowc added 4 commits Sep 27, 2019
Fix code
- Add `ExampleHeaders`
- Rename `GrpcExampleHeader`
- Fix `*RegistrationBean`
- Add method to set header to specific method
- Fix test code
- Fix build.gradle
@heowc heowc requested review from trustin and ikhoon Sep 29, 2019
@trustin
trustin approved these changes Oct 1, 2019
Copy link
Member

trustin left a comment

👍

@minwoox
minwoox approved these changes Oct 2, 2019
Copy link
Member

minwoox left a comment

Thanks, @heowc! 👍

@ikhoon
ikhoon approved these changes Oct 2, 2019
Copy link
Contributor

ikhoon left a comment

LGTM, thanks!

@trustin trustin changed the title Provide a way to set an example headers for each registration bean Provide a way to set an example headers for each registration b… Oct 2, 2019
@trustin trustin merged commit e39ea9f into line:master Oct 2, 2019
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
Travis CI - Pull Request Build Passed
Details
license/cla Contributor License Agreement is signed.
Details
@trustin

This comment has been minimized.

Copy link
Member

trustin commented Oct 2, 2019

Thanks, @heowc!

@heowc heowc deleted the heowc:provide-example-header-for-x-registration-bean branch Oct 2, 2019
eugene70 pushed a commit to eugene70/armeria that referenced this pull request Oct 16, 2019
…e#2100)

Motivation:

A user cannot specify an example header when adding a service using `~ServiceRegistrationBean`.

Modifications:

- Add `ExampleHeaders` for `{Annotated,Thrift}ServiceRegistrationBean`
- Add `GrpcExampleHeaders` for `GrpcServiceRegistrationBean`
- Make the `GrpcExampleHeaders` are added to `DocService`
- Make the `ExampleHeaders` are added to `DocService`
- Fix test code

Result:

- User friendliness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.