line / centraldogma

Highly-available version-controlled service configuration repository based on Git, ZooKeeper and HTTP/2
https://line.github.io/centraldogma/
Apache License 2.0
604 stars 118 forks source link

Add @ConsumseJson to contents API. #999

Closed chickenchickenlove closed 3 months ago

chickenchickenlove commented 3 months ago

Motivation:

Modifications:

FYI

  1. If @RequestConverter is declared on method signatures, Armeria will add an object Resolver. (link)
  2. Then, when Armeria receives a request from client, Armeria will try to resolve the request. (link)
  3. ChangesRequestConverter tries to parse body from request. Actually, ChangeRequestConverter delegates to JacksonRequestConvertFunction.
  4. JacksonRequestConverter validates contents type. (here)
  5. If there is no content-type or content-type is not application/json, JacksonRequestConverter will call RequestConverterFunction.fallthrough().

With this flow, client will receive response : {"exception":"java.lang.IllegalArgumentException","message":"No suitable request converter found for a @RequestObject 'CommitMessageDto'"}.

If @ConsumsJson is delcared to each method having ChangesRequestConverter.class on their method signature, Armeria will not try to resolve request without header Content-Type: application/json.

Result:

CLAassistant commented 3 months ago

CLA assistant check
All committers have signed the CLA.

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 70.88%. Comparing base (c960313) to head (38bd2b1). Report is 135 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #999 +/- ## ============================================ + Coverage 65.61% 70.88% +5.27% - Complexity 3319 3933 +614 ============================================ Files 355 388 +33 Lines 13865 15661 +1796 Branches 1498 1704 +206 ============================================ + Hits 9098 11102 +2004 + Misses 3916 3580 -336 - Partials 851 979 +128 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ikhoon commented 3 months ago

It looks good.

Client will receive 415 response.

Would you add a test that verifies the status? It is a simple test but will be helpful to detect regressions in the future.

chickenchickenlove commented 3 months ago

@ikhoon nim, i make a new commit to apply your comments.

I discovered something in the process. When the Content-Type is not configured for each client, the default Content-Type may differ.

the values may differ! dogma.client don't configure Content-Type. thus value is null. curl configure application/x-form-urlencoded as default. thus value is application/x-form/urlencoded. aiohttp.ClientSession() in python configure text/plain as default. thus value is text/plain.

Since the Dogma client defaults to a null Content-Type, it always will receive 400 response. Therefore, to properly test this, I used parameterized tests to vary the Content-Type.