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

chore: replace vendored gorilla/schema package #3152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

efectn
Copy link
Member

@efectn efectn commented Sep 30, 2024

Description

Replace internal/schema with https://github.com/gofiber/schema which is fork of gorilla/schema.

Changes introduced

  • Benchmarks: Describe any performance benchmarks and improvements related to the changes.
  • Documentation Update: Detail the updates made to the documentation and links to the changed files.
  • Changelog/What's New: Include a summary of the additions for the upcoming release notes.
  • Migration Guide: If necessary, provide a guide or steps for users to migrate their existing code to accommodate these changes.
  • API Alignment with Express: Explain how the changes align with the Express API.
  • API Longevity: Discuss the steps taken to ensure that the new or updated APIs are consistent and not prone to breaking changes.
  • Examples: Provide examples demonstrating the new features or changes in action.

Type of change

  • Enhancement (improvement to existing features and functionality)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

Commit formatting

Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md

@efectn efectn requested a review from a team as a code owner September 30, 2024 20:03
@efectn efectn requested review from gaby, sixcolors and ReneWerner87 and removed request for a team September 30, 2024 20:03
Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Warning

Rate limit exceeded

@efectn has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 679a0f0 and 7644256.

Walkthrough

The changes encompass enhancements to the Fiber framework's binding functionalities, including the introduction of default values for query parameters, headers, and cookies. The import paths for the schema package have been updated, transitioning from internal to public access. Several files related to schema processing, such as caching, encoding, and decoding, have been removed, streamlining the framework. Documentation has been expanded to include examples of the new default field capabilities, ensuring clarity for developers.

Changes

File(s) Change Summary
bind_test.go Added Default and Defaults fields to Query2 and Header2 structs; expanded tests for binding logic with default values.
binder/mapping.go, error.go, error_test.go Updated import path for the schema package from internal to public; enhanced error handling in mapping.go.
docs/api/bind.md Expanded documentation to include a new section on "Default Fields" with examples of default values.
internal/schema/* Removed multiple files related to caching, encoding, and decoding, including associated types and methods.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Fiber
    participant Schema

    Client->>Fiber: Send request with parameters
    Fiber->>Schema: Decode parameters into struct
    Schema->>Fiber: Return populated struct
    Fiber->>Client: Respond with processed data
Loading

🐇 "In the meadow where bunnies play,
New defaults have come to stay.
With headers and queries, oh what a treat,
Binding made simple, oh so neat!
Hopping along, we celebrate,
Fiber's enhancements, truly great!" 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 82.41%. Comparing base (44cd700) to head (7644256).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
binder/mapping.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3152      +/-   ##
==========================================
+ Coverage   80.09%   82.41%   +2.32%     
==========================================
  Files         117      113       -4     
  Lines        9043     8468     -575     
==========================================
- Hits         7243     6979     -264     
+ Misses       1365     1087     -278     
+ Partials      435      402      -33     
Flag Coverage Δ
unittests 82.41% <0.00%> (+2.32%) ⬆️

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

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
error_test.go (1)

Line range hint 1-85: Consider adding tests for new default tag functionality.

The PR objectives mention adding support for default tags. However, the current test file doesn't include any tests for this new functionality. To ensure comprehensive coverage and validate the new feature, consider adding tests that specifically check the behavior of default tags.

Here's a suggestion for a new test case:

func Test_DefaultTagFunctionality(t *testing.T) {
	t.Parallel()

	type TestStruct struct {
		Field string `schema:"field,default=defaultValue"`
	}

	var test TestStruct
	err := schema.NewDecoder().Decode(&test, map[string][]string{})

	require.NoError(t, err)
	require.Equal(t, "defaultValue", test.Field)
}

This test case would verify that when a field with a default tag is not provided in the input, it correctly uses the default value.

error.go (1)

Line range hint 1-94: LGTM! Consider updating documentation to reflect the new schema package.

The change in the import statement is the only modification to this file, and it doesn't affect the existing error definitions or type aliases. This suggests that the new github.com/gofiber/schema package maintains API compatibility with the previous internal package, which is excellent for backwards compatibility.

Consider updating any relevant documentation or README files to reflect the use of the new public schema package. This will help developers understand the change and its implications for the project.

binder/mapping.go (1)

Line range hint 1-238: Recommendation: Review and update documentation if necessary.

Given the switch to a new schema package, it's advisable to review the existing documentation and comments in this file. While the core functionality appears unchanged, the new package might introduce subtle differences or new features that should be reflected in the documentation.

Consider:

  1. Updating any references to the old schema package in comments.
  2. Adding notes about any new features or behavior changes introduced by the forked schema package.
  3. Ensuring that all public functions and structures are adequately documented, especially if their behavior has been affected by the package change.
docs/api/bind.md (2)

577-612: Great addition of the "Default Fields" section!

The new section provides valuable information on setting default values for struct fields using the default struct tag. The content is well-structured, and the example effectively demonstrates the usage.

Here are a few suggestions to improve the formatting and clarity:

  1. Add a blank line before the list of supported types (line 579) to improve readability.
  2. Consider using a code block for the list of supported types to make it stand out.
  3. In the example, add a comment explaining that the Products field will use the default value since it's not provided in the curl command.

Consider applying these minor formatting improvements:

 ## Default Fields

-You can set default values for fields in the struct by using the `default` struct tag. Supported types:
+You can set default values for fields in the struct by using the `default` struct tag. Supported types:
+
+```
 - bool
 - float variants (float32, float64)
 - int variants (int, int8, int16, int32, int64)
 - uint variants (uint, uint8, uint16, uint32, uint64)
 - string
 - a slice of the above types. As shown in the example above, **| should be used to separate between slice items**.
 - a pointer to one of the above types **(pointer to slice and slice of pointers are not supported)**.
+```

 ```go title="Example"
 type Person struct {
     Name     string     `query:"name,default:john"`
     Pass     string     `query:"pass"`
     Products []string   `query:"products,default:shoe|hat"`
 }

 app.Get("/", func(c fiber.Ctx) error {
     p := new(Person)
     
     if err := c.Bind().Query(p); err != nil {
         return err
     }
     
     log.Println(p.Name)        // john
     log.Println(p.Pass)        // doe
-    log.Println(p.Products)    // ["shoe,hat"]    
+    log.Println(p.Products)    // ["shoe", "hat"]  // Uses default value as it's not provided in the curl command
     
     // ...
 })
 // Run tests with the following curl command

 // curl "http://localhost:3000/?pass=doe"

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary><blockquote>

588-588: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)

---

580-580: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

---

612-612: null
Files should end with a single newline character

(MD047, single-trailing-newline)

</blockquote></details>

</details>

---

Line range hint `1-612`: **Overall document structure is good, with minor formatting improvements needed**

The new "Default Fields" section is well-integrated into the document and provides valuable information. To improve the overall readability and consistency of the document, consider the following suggestions:

1. Remove the extra blank line at 588-589.
2. Ensure consistent spacing around headers throughout the document.
3. Add a single newline character at the end of the file (line 612).


Apply these minor formatting improvements to enhance the document's consistency:

1. Remove the extra blank line between lines 588 and 589.
2. Add a single newline character at the end of the file (line 612).
3. Review the entire document to ensure consistent spacing around headers.

These changes will improve the overall readability and adhere to common Markdown formatting practices.

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary><blockquote>

588-588: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)

---

580-580: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

---

612-612: null
Files should end with a single newline character

(MD047, single-trailing-newline)

</blockquote></details>

</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**

<details>
<summary>📥 Commits</summary>

Files that changed from the base of the PR and between 44cd700ad578f9c60c9c5d2b4752fe22ef32a4e1 and 2f6a850328574999e0535c4e4aeedba46ddcb7a3.

</details>

<details>
<summary>⛔ Files ignored due to path filters (2)</summary>

* `go.mod` is excluded by `!**/*.mod`
* `go.sum` is excluded by `!**/*.sum`, `!**/*.sum`

</details>

<details>
<summary>📒 Files selected for processing (11)</summary>

* bind_test.go (2 hunks)
* binder/mapping.go (1 hunks)
* docs/api/bind.md (1 hunks)
* error.go (1 hunks)
* error_test.go (1 hunks)
* internal/schema/LICENSE (0 hunks)
* internal/schema/cache.go (0 hunks)
* internal/schema/converter.go (0 hunks)
* internal/schema/decoder.go (0 hunks)
* internal/schema/doc.go (0 hunks)
* internal/schema/encoder.go (0 hunks)

</details>

<details>
<summary>💤 Files with no reviewable changes (6)</summary>

* internal/schema/LICENSE
* internal/schema/cache.go
* internal/schema/converter.go
* internal/schema/decoder.go
* internal/schema/doc.go
* internal/schema/encoder.go

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 Markdownlint</summary><blockquote>

<details>
<summary>docs/api/bind.md</summary><blockquote>

588-588: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)

---

580-580: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

---

612-612: null
Files should end with a single newline character

(MD047, single-trailing-newline)

</blockquote></details>

</blockquote></details>

</details>

<details>
<summary>🔇 Additional comments (8)</summary><blockquote>

<details>
<summary>error_test.go (2)</summary><blockquote>

`8-8`: **Import path updated correctly.**

The import path has been updated from `github.com/gofiber/fiber/v3/internal/schema` to `github.com/gofiber/schema`. This change aligns with the PR objective of replacing the vendored gorilla/schema package with a fork.

---

Line range hint `1-85`: **Verify error types in the new schema package.**

The tests appear to be unchanged and should still be valid. However, it's crucial to ensure that all the error types used in these tests (ConversionError, UnknownKeyError, EmptyFieldError, MultiError) still exist in the new `github.com/gofiber/schema` package and maintain the same structure.

Please run the following script to verify the existence of these error types in the new package:



If all error types are found, no further changes are needed. If any error types are missing, please update the corresponding tests accordingly.

</blockquote></details>
<details>
<summary>error.go (1)</summary><blockquote>

`7-7`: **LGTM! Verify API compatibility with the new schema package.**

The import change from the internal schema package to the public `github.com/gofiber/schema` package aligns with the PR objective of replacing the vendored gorilla/schema package. This change enhances maintainability and allows for easier updates in the future.


To ensure API compatibility, please run the following script:



This script will help identify any potential compatibility issues with the new schema package.

<details>
<summary>✅ Verification successful</summary>

<!-- [monologue]
[task review_file_1/1 verify_import_change]
Review the results of the shell scripts.
[observations]
- The first script confirmed that all the schema types used in `error.go` (ConversionError, UnknownKeyError, EmptyFieldError, MultiError) are still present.
- The second script found that these schema types are also used in `error_test.go` and `binder/mapping.go`.
- No errors or missing types were reported, indicating that the new `github.com/gofiber/schema` package maintains the necessary API for these types.
[analysis]
- The presence of schema types in other parts of the codebase suggests that the import change has been consistently applied.
- Since all used types are still available, the API compatibility appears to be intact.
- No additional discrepancies or issues were found in the codebase related to the schema package.
[actions]
- Conclude that the import change is verified and does not introduce compatibility issues.
-->
 
**Verified!** The import change to `github.com/gofiber/schema` maintains all necessary types and does not affect other parts of the codebase. All schema type usages are compatible and consistent across files.


</details>

<details>
<summary>🏁 Scripts executed</summary>

The following scripts were executed for the analysis:

Script:

```shell
#!/bin/bash
# Description: Verify that all used types and functions from the schema package are still available in the new package.

# Test: Check if all schema types used in this file are still available
rg --type go -w '(ConversionError|UnknownKeyError|EmptyFieldError|MultiError)' error.go

# Test: Check if there are any other usages of the schema package in the codebase
rg --type go 'schema\.' --glob '!error.go'

Length of output: 1118

binder/mapping.go (3)

Line range hint 1-238: Suggestion: Ensure comprehensive testing of binding functionality.

While the code remains unchanged apart from the import path, it's crucial to verify that the behavior of key functions like SetParserDecoder, decoderBuilder, and parseToStruct remains consistent with the new schema package.

Please ensure that:

  1. All existing tests pass with the new package.
  2. The binding functionality works as expected for various data types and structures.
  3. Performance characteristics remain similar or improved.

Consider adding new tests specifically targeting any new features or changes introduced by the forked schema package.


Line range hint 1-238: Summary: Import path updated successfully, further verification recommended.

The change to use the forked schema package has been implemented correctly in this file. While no other code changes were necessary, it's crucial to ensure that:

  1. The new package maintains full compatibility with the existing code.
  2. Comprehensive testing is performed to verify consistent behavior.
  3. Documentation is reviewed and updated if needed to reflect any changes introduced by the new package.

These steps will help maintain the reliability and clarity of the Fiber framework while integrating the new schema handling solution.


12-12: LGTM: Import path updated as per PR objective.

The import path has been successfully updated to use the forked schema package. This change aligns with the PR objective of replacing the vendored gorilla/schema package.

To ensure compatibility, please run the following script to check for any potential issues:

This will help identify any potential incompatibilities or necessary adjustments in the usage of the schema package throughout the binder directory.

✅ Verification successful

Verified: All schema package usages are compatible with the new import.

The schema package import has been successfully updated, and all usages within binder/mapping.go are compatible with the new forked version. No additional changes are required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all schema package usages are compatible with the new import

# Test: Search for all usages of the schema package
rg --type go -n 'schema\.' binder/

Length of output: 225

bind_test.go (2)

64-65: LGTM: Added default values for query parameters

The new fields Default and Defaults with default tag values correctly implement default values for query parameters in the Query2 struct.


81-82: Tests validate default query parameter defaults

The test cases correctly verify that default values are assigned when the query parameters default and defaults are not provided.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (7)
docs/api/bind.md (3)

577-612: Great addition of the "Default Fields" section!

The new section on default fields is a valuable addition to the documentation. It clearly explains how to use the default struct tag and provides a comprehensive list of supported types. The example effectively demonstrates the usage of default values in practice.

However, there's a minor formatting issue:

Remove the extra blank line between lines 588 and 589 to adhere to Markdown best practices.

 - a pointer to one of the above types **(pointer to slice and slice of pointers are not supported)**.

-
 ```go title="Example"
🧰 Tools
🪛 Markdownlint

588-588: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


580-580: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


612-612: null
Files should end with a single newline character

(MD047, single-trailing-newline)

🪛 GitHub Check: markdownlint

[failure] 580-580: Lists should be surrounded by blank lines
docs/api/bind.md:580 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- bool"] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md032.md


[failure] 588-588: Multiple consecutive blank lines
docs/api/bind.md:588 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md012.md


[failure] 612-612: Files should end with a single newline character
docs/api/bind.md:612:3 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md047.md


579-580: Improve list formatting

To enhance readability and adhere to Markdown best practices, add a blank line before the list of supported types.

 You can set default values for fields in the struct by using the `default` struct tag. Supported types:
+
 - bool
 - float variants (float32, float64)
 - int variants (int, int8, int16, int32, int64)
🧰 Tools
🪛 Markdownlint

580-580: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

🪛 GitHub Check: markdownlint

[failure] 580-580: Lists should be surrounded by blank lines
docs/api/bind.md:580 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- bool"] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md032.md


612-612: Add newline at end of file

To comply with file formatting standards, add a single newline character at the end of the file.

 // curl "http://localhost:3000/?pass=doe"

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary><blockquote>

612-612: null
Files should end with a single newline character

(MD047, single-trailing-newline)

</blockquote></details>
<details>
<summary>🪛 GitHub Check: markdownlint</summary><blockquote>

[failure] 612-612: Files should end with a single newline character
docs/api/bind.md:612:3 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md047.md

</blockquote></details>

</details>

</blockquote></details>
<details>
<summary>bind_test.go (4)</summary><blockquote>

`81-82`: **Approve: New assertions validate default value functionality.**

The added assertions effectively verify the correct handling of default values for the new `Default` and `Defaults` fields. This ensures the proper functioning of the default tag support.



Consider adding an additional test case where query parameters are provided to ensure they override the default values correctly.

---

`655-660`: **Approve: Added result validation to benchmark function.**

The new assertions ensure the correctness of the binding process during benchmarking, which is valuable for maintaining the integrity of the benchmark.



Consider moving these assertions to a separate test function to keep the benchmark focused solely on performance measurement. This separation would maintain the purity of the benchmark while still ensuring correctness in a dedicated test.

---

`662-687`: **Approve: New benchmark for query binding with default values.**

This new benchmark function effectively tests the performance of query binding with default values, which is a valuable addition given the new default tag support. It complements the existing benchmark and ensures that the new functionality performs well.



Consider adding a comment explaining the purpose of this specific benchmark to improve code documentation. Also, as suggested for the previous benchmark, consider moving the assertions to a separate test function to keep the benchmark focused on performance measurement.

---

Line range hint `1-687`: **Summary: Comprehensive implementation of default value support for query binding.**

The changes in this file effectively implement and test the new support for default values in query binding. The additions include:
1. New fields in the Query2 struct for default values.
2. Updated test cases to verify the default value functionality.
3. A new benchmark to measure the performance of query binding with default values.

These changes align well with the PR objectives and provide good coverage for the new feature. The implementation is thorough and maintains consistency with the existing code style and structure.



As the codebase grows, consider creating separate files for different types of tests (e.g., unit tests, benchmarks) to improve organization and maintainability. This could make it easier to manage and run specific types of tests independently.

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**

<details>
<summary>📥 Commits</summary>

Files that changed from the base of the PR and between 2f6a850328574999e0535c4e4aeedba46ddcb7a3 and 54778a270790f1f348391e34b18314feb81caa46.

</details>

<details>
<summary>⛔ Files ignored due to path filters (2)</summary>

* `go.mod` is excluded by `!**/*.mod`
* `go.sum` is excluded by `!**/*.sum`, `!**/*.sum`

</details>

<details>
<summary>📒 Files selected for processing (11)</summary>

* bind_test.go (3 hunks)
* binder/mapping.go (1 hunks)
* docs/api/bind.md (1 hunks)
* error.go (1 hunks)
* error_test.go (1 hunks)
* internal/schema/LICENSE (0 hunks)
* internal/schema/cache.go (0 hunks)
* internal/schema/converter.go (0 hunks)
* internal/schema/decoder.go (0 hunks)
* internal/schema/doc.go (0 hunks)
* internal/schema/encoder.go (0 hunks)

</details>

<details>
<summary>💤 Files with no reviewable changes (6)</summary>

* internal/schema/LICENSE
* internal/schema/cache.go
* internal/schema/converter.go
* internal/schema/decoder.go
* internal/schema/doc.go
* internal/schema/encoder.go

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (3)</summary>

* binder/mapping.go
* error.go
* error_test.go

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 Markdownlint</summary><blockquote>

<details>
<summary>docs/api/bind.md</summary><blockquote>

588-588: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)

---

580-580: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

---

612-612: null
Files should end with a single newline character

(MD047, single-trailing-newline)

</blockquote></details>

</blockquote></details>
<details>
<summary>🪛 GitHub Check: markdownlint</summary><blockquote>

<details>
<summary>docs/api/bind.md</summary><blockquote>

[failure] 580-580: Lists should be surrounded by blank lines
docs/api/bind.md:580 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- bool"] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md032.md

---

[failure] 588-588: Multiple consecutive blank lines
docs/api/bind.md:588 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md012.md

---

[failure] 612-612: Files should end with a single newline character
docs/api/bind.md:612:3 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md047.md

</blockquote></details>

</blockquote></details>

</details>

<details>
<summary>🔇 Additional comments (1)</summary><blockquote>

<details>
<summary>bind_test.go (1)</summary><blockquote>

`64-65`: **Approve: New default value fields enhance query parameter handling.**

The addition of `Default` and `Defaults` fields with their respective query tags and default values improves the struct's capability to handle default query parameters. This change aligns well with the PR objective of adding support for default tags.

</blockquote></details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 7644256 Previous: 2eba89a Ratio
Benchmark_Compress_Levels/Zstd_LevelBestCompression - B/op 1 B/op 0 B/op +∞
BenchmarkAppendMsgitem - MB/s 3209.78 MB/s 1871.83 MB/s 1.71

This comment was automatically generated by workflow using github-action-benchmark.

@gaby
Copy link
Member

gaby commented Oct 1, 2024

@efectn Did you add the changes we had here to gofiber/schema?

@efectn
Copy link
Member Author

efectn commented Oct 2, 2024

@efectn Did you add the changes we had here to gofiber/schema?

Yes i've added

@ReneWerner87
Copy link
Member

@efectn can you check the failed and open tasks
thx for the effort 🚀

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
error.go (1)

Line range hint 45-53: Approve new type aliases and suggest documentation.

The introduction of type aliases for ConversionError, UnknownKeyError, EmptyFieldError, and MultiError from the schema package is consistent with the move to a public schema package. This change makes these error types publicly accessible, which can be beneficial for users of the Fiber framework.

To improve the usability of these new public types, consider adding godoc comments for each type alias. This will help users understand the purpose and usage of each error type. For example:

// ConversionError represents an error that occurred during type conversion.
type ConversionError = schema.ConversionError

// UnknownKeyError represents an error when an unknown key is encountered.
type UnknownKeyError = schema.UnknownKeyError

// EmptyFieldError represents an error when a required field is empty.
type EmptyFieldError = schema.EmptyFieldError

// MultiError represents multiple errors that occurred during schema processing.
type MultiError = schema.MultiError
binder/mapping.go (1)

Line range hint 70-76: LGTM: Pre-configuration of decoder pool

The initialization of decoderPoolMap with default ParserConfig values is a good practice. It ensures consistent behavior across the application.

Consider adding a comment explaining the rationale behind setting IgnoreUnknownKeys and ZeroEmpty to true by default. This will help future maintainers understand the design decision.

docs/api/bind.md (2)

577-613: Great addition of the "Default Fields" section!

The new section on default fields is a valuable addition to the documentation. It clearly explains how to use the default struct tag to set default values for struct fields. The list of supported types and the example provided are helpful for users to understand and implement this feature.

There's a minor formatting issue with consecutive blank lines between lines 589-590. Consider removing one of these blank lines to maintain consistent formatting throughout the document.

🧰 Tools
🪛 Markdownlint

589-589: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)

🪛 GitHub Check: markdownlint

[failure] 589-589: Multiple consecutive blank lines
docs/api/bind.md:589 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md012.md


590-613: Excellent example demonstrating default values!

The provided example effectively illustrates how to use default values with the default struct tag. It covers both string and slice of strings, which is helpful for users to understand the usage for different types.

There's a minor inconsistency in the log output for p.Products. The current output shows:

log.Println(p.Products)    // ["shoe,hat"]

However, based on the default value set in the struct tag (default:shoe|hat), it should be:

log.Println(p.Products)    // ["shoe", "hat"]

Please update this line to accurately reflect the expected output when using the | separator for slice default values.

bind_test.go (1)

58-62: Consider improving the field naming for clarity

The fields Default and Defaults might be confusing due to their names matching the tag option default. Consider renaming the fields to more descriptive names that convey their purpose.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 54778a2 and 679a0f0.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (11)
  • bind_test.go (3 hunks)
  • binder/mapping.go (2 hunks)
  • docs/api/bind.md (1 hunks)
  • error.go (1 hunks)
  • error_test.go (1 hunks)
  • internal/schema/LICENSE (0 hunks)
  • internal/schema/cache.go (0 hunks)
  • internal/schema/converter.go (0 hunks)
  • internal/schema/decoder.go (0 hunks)
  • internal/schema/doc.go (0 hunks)
  • internal/schema/encoder.go (0 hunks)
💤 Files with no reviewable changes (6)
  • internal/schema/LICENSE
  • internal/schema/cache.go
  • internal/schema/converter.go
  • internal/schema/decoder.go
  • internal/schema/doc.go
  • internal/schema/encoder.go
🧰 Additional context used
🪛 Markdownlint
docs/api/bind.md

589-589: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)

🪛 GitHub Check: markdownlint
docs/api/bind.md

[failure] 589-589: Multiple consecutive blank lines
docs/api/bind.md:589 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md012.md

🔇 Additional comments (9)
error_test.go (2)

Line range hint 11-77: LGTM: Test functions remain valid with the new import.

The test functions continue to verify the correct error types from the newly imported package. This implicitly confirms that the external github.com/gofiber/schema package maintains the same error interfaces as the previous internal package.

The unchanged nature of these tests is a positive indicator of backward compatibility with the new package.


8-8: LGTM: Import path updated as per PR objective.

The change from the internal schema package to the external github.com/gofiber/schema aligns with the PR's goal of replacing the vendored gorilla/schema package.

To ensure compatibility, please run the following script to verify that all required types are present in the new package:

This script will help confirm that the new package maintains the same API for the error types used in the tests.

error.go (2)

Line range hint 1-87: Overall assessment: Changes align with PR objectives and improve API.

The modifications to error.go are consistent with the PR objectives of replacing the vendored gorilla/schema package. The changes improve the public API of the Fiber framework by exposing schema-related error types. No issues were found in the unchanged parts of the file.


7-7: Approve import change and verify consistency.

The import path change from github.com/gofiber/fiber/v3/internal/schema to github.com/gofiber/schema aligns with the PR objective of replacing the vendored gorilla/schema package. This change moves the schema package from an internal implementation to a public one.

To ensure consistency, please run the following script to verify that this import change has been applied across the entire codebase:

✅ Verification successful

Import change verified successfully.

All instances of the old import path github.com/gofiber/fiber/v3/internal/schema have been removed, and the new import path github.com/gofiber/schema is used consistently across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the schema import change across the codebase

# Test 1: Check for any remaining instances of the old import
echo "Checking for any remaining instances of the old import:"
rg --type go "github.com/gofiber/fiber/v3/internal/schema"

# Test 2: Verify the new import is used consistently
echo "Verifying the new import is used consistently:"
rg --type go "github.com/gofiber/schema"

Length of output: 451

binder/mapping.go (3)

98-102: LGTM: Improved error handling

The enhancement in error handling is a good improvement. Wrapping the error with additional context using fmt.Errorf provides more informative error messages, which will aid in debugging and troubleshooting.


5-5: LGTM: Added necessary import

The addition of the fmt package to the import list is correct and necessary for the new error handling implementation in the parseToStruct function.


13-13: Verify compatibility with the new schema package.

The import path has been updated from an internal package to an external one. This change aligns with the PR objective of replacing the vendored gorilla/schema package.

Please run the following script to ensure that the new package provides the same functionality as the old one:

If any discrepancies are found, please update the code accordingly to ensure full compatibility.

docs/api/bind.md (1)

Line range hint 1-613: Excellent addition to the bind documentation!

The new "Default Fields" section is a valuable enhancement to the bind documentation. It seamlessly integrates with the existing content and provides clear, concise information on using default values with struct tags. This addition will be particularly helpful for users looking to implement default values in their Fiber applications.

The example provided effectively demonstrates the usage of default values for both simple types and slices, which covers a good range of use cases. The inclusion of a curl command for testing is a nice touch that aids in practical understanding.

Overall, this update maintains the high quality of the existing documentation while introducing a useful new feature explanation.

🧰 Tools
🪛 Markdownlint

589-589: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)

🪛 GitHub Check: markdownlint

[failure] 589-589: Multiple consecutive blank lines
docs/api/bind.md:589 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md012.md

bind_test.go (1)

81-82: LGTM!

The test cases correctly ensure default values are assigned as expected.

bind_test.go Outdated Show resolved Hide resolved
@efectn
Copy link
Member Author

efectn commented Oct 7, 2024

@efectn can you check the failed and open tasks thx for the effort 🚀

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants