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

Automatically validate request body using Schema.validate #2360

Merged
merged 1 commit into from
Aug 12, 2023

Conversation

williamareynolds
Copy link
Contributor

@williamareynolds williamareynolds commented Aug 3, 2023

Uses the Schema.validate method from zio-schema to validate the body
of a request based on the schema of the input type. If schema validation
fails, HttpCodecError.InvalidEntity is passed to the error channel,
indicating that the body is well-formed, but contains invalid values in
one or more fields. A wrap method is included for InvalidEntity
which simplifies the process of converting Schema.validate's
output (Chunk[ValidationError]) to InvalidEntity in a consistent
way.

/claim #2274
/split @allaryin

@williamareynolds williamareynolds force-pushed the 2274-automatic-schema-validation branch 2 times, most recently from 75027f0 to dad30e9 Compare August 4, 2023 18:24
@codecov-commenter
Copy link

codecov-commenter commented Aug 4, 2023

Codecov Report

Patch coverage: 87.50% and project coverage change: +0.01% 🎉

Comparison is base (538761f) 63.21% compared to head (75027f0) 63.22%.

❗ Current head 75027f0 differs from pull request most recent head dad30e9. Consider uploading reports for the commit dad30e9 to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2360      +/-   ##
==========================================
+ Coverage   63.21%   63.22%   +0.01%     
==========================================
  Files         135      135              
  Lines        7032     7038       +6     
  Branches     1185     1183       -2     
==========================================
+ Hits         4445     4450       +5     
- Misses       2587     2588       +1     
Files Changed Coverage Δ
...main/scala/zio/http/codec/internal/BodyCodec.scala 53.33% <83.33%> (+16.96%) ⬆️
...src/main/scala/zio/http/codec/HttpCodecError.scala 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Uses the `Schema.validate` method from `zio-schema` to validate the body
of a request based on the schema of the input type. If schema validation
fails, `HttpCodecError.InvalidEntity` is passed to the error channel,
indicating that the body is well-formed, but contains invalid values in
one or more fields.  A `wrap` method is included for `InvalidEntity`
which simplifies the process of converting `Schema.validate`'s
output (`Chunk[ValidationError]`) to `InvalidEntity` in a consistent
way.

resolves zio#2274
@williamareynolds williamareynolds force-pushed the 2274-automatic-schema-validation branch from dad30e9 to 6764704 Compare August 4, 2023 18:56
@williamareynolds williamareynolds changed the title wip: first pass schema validation Automatically validate request body using Schema.validate Aug 4, 2023
@williamareynolds williamareynolds marked this pull request as ready for review August 4, 2023 19:29
@vigoo vigoo merged commit 37fe777 into zio:main Aug 12, 2023
@williamareynolds williamareynolds deleted the 2274-automatic-schema-validation branch August 15, 2023 01:36
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.

3 participants