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

refactor(core-api): dot-separated-query hapi plugin #3965

Merged
merged 3 commits into from
Aug 17, 2020

Conversation

rainydio
Copy link
Contributor

Summary

Hapi plugin that folds dot-separated query keys into object. Query such as /wallets?balance.from=100&balance.to=200 enters validation and controller as single property request.query.balance instead of two separate properties request.query["balance.from"] and request.query["balance.to"]. Without it many schema has to be written twice (GET and POST).

It's enabled by default and there is no option to disable it.


I tried Joi.tailor and other techniques in attempts to avoid creating this plugin. It changes the way hapi is passing query object into controller which might be confusing in itself, but folding dot-separated parameters is also kind-of intuitive. The way query object is changed also limits what kind of query can be passed. Sending /wallets?balance=100&balance.from=100&balance.to=200 will override balance=100 parameter with object made out of other two. This is an edge case and it's unlikely to cause any real problems.

Checklist

  • Tests
  • Ready to be merged

@ghost ghost added Complexity: Low labels Aug 17, 2020
@rainydio rainydio changed the title Implement dot-query plugin refactor(core-api): dot-query plugin Aug 17, 2020
@rainydio rainydio changed the title refactor(core-api): dot-query plugin refactor(core-api): dot-separated-query plugin Aug 17, 2020
@rainydio rainydio changed the title refactor(core-api): dot-separated-query plugin refactor(core-api): dot-separated-query hapi plugin Aug 17, 2020
@codecov
Copy link

codecov bot commented Aug 17, 2020

Codecov Report

Merging #3965 into develop will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3965      +/-   ##
===========================================
+ Coverage    97.53%   97.57%   +0.03%     
===========================================
  Files          629      630       +1     
  Lines        14540    14548       +8     
  Branches      1729     1729              
===========================================
+ Hits         14182    14195      +13     
+ Misses         167      165       -2     
+ Partials       191      188       -3     
Flag Coverage Δ
#functional 6.81% <0.00%> (-0.01%) ⬇️
#integration 9.90% <100.00%> (?)
#unit 95.73% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ckages/core-api/src/plugins/dot-separated-query.ts 100.00% <100.00%> (ø)
packages/core-test-framework/src/utils/api.ts 97.34% <0.00%> (+0.88%) ⬆️
packages/core-test-framework/src/app/sandbox.ts 100.00% <0.00%> (+2.56%) ⬆️
packages/core-api/src/controllers/transactions.ts 100.00% <0.00%> (+3.40%) ⬆️

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 3565ef5...90288d2. Read the comment docs.

@rainydio rainydio marked this pull request as ready for review August 17, 2020 12:50
@air1one air1one merged commit d680391 into develop Aug 17, 2020
@ghost ghost deleted the refactor/core-api/dot-query-plugin branch August 17, 2020 14:42
@ghost ghost removed the Status: Needs Review label Aug 17, 2020
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 this pull request may close these issues.

None yet

2 participants