-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: new test option to set the issue path for issues generated from that test #87
Conversation
…ons and methods to reference page
WalkthroughThis update revises both documentation and internal code to align Zog with idiomatic Golang. Several API methods have been renamed (e.g., from Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant S as Schema
participant T as TestFunc
participant E as Error Handler
U->>S: Provide input for validation
S->>T: Execute custom test (TestFunc)
T-->>S: Return validation result
alt Validation fails
S->>E: Invoke IssueFromTest (using IssuePath)
E-->>S: Return error with detailed IssuePath
else Validation succeeds
S->>U: Return validated data
end
Possibly related PRs
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Deploying zog with
|
Latest commit: |
edd1d0b
|
Status: | ✅ Deploy successful! |
Preview URL: | https://88924554.zog-3a0.pages.dev |
Branch Preview URL: | https://feat-test-issue-path.zog-3a0.pages.dev |
There was a problem hiding this 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
🧹 Nitpick comments (6)
utilsOptions_test.go (1)
56-79
: Consider adding edge cases to the test.While the test covers the basic functionality well, consider adding these edge cases:
- Empty string for issue path
- Special characters in the issue path
- Nested struct scenarios
func TestIssuePath(t *testing.T) { + t.Run("empty_path", func(t *testing.T) { + var out User + schema := Struct(Schema{ + "name": String().Min(5, IssuePath(""), Message("foo msg")), + }) + err := schema.Parse(map[string]any{"name": "1234"}, &out) + assert.Equal(t, "name", err["name"][0].Path()) + }) + + t.Run("special_chars", func(t *testing.T) { + var out User + schema := Struct(Schema{ + "name": String().Min(5, IssuePath("foo/bar@123"), Message("foo msg")), + }) + err := schema.Parse(map[string]any{"name": "1234"}, &out) + assert.Equal(t, "foo/bar@123", err["foo/bar@123"][0].Path()) + }) + + t.Run("nested_struct", func(t *testing.T) { + type Address struct { + Street string + } + type User struct { + Name string + Address Address + } + var out User + schema := Struct(Schema{ + "address": Struct(Schema{ + "street": String().Min(5, IssuePath("user.address.street")), + }), + }) + err := schema.Parse(map[string]any{ + "address": map[string]any{"street": "123"}, + }, &out) + assert.Equal(t, "user.address.street", err["user.address.street"][0].Path()) + })docs/docs/custom-tests.md (2)
13-14
: Improve readability of the introduction.Consider rephrasing for better clarity and grammar:
-All schemas contain the `TestFunc()` method which can be used to create a simple custom test in a similar way to Zod's `refine` method. The `TestFunc()` method takes a `ValidateFunc` as an argument. This is a function that takes the data as input and returns a boolean indicating if it is valid or not. If you return `false` from the function Zog will create a [ZogIssue](/errors). For example: +All schemas contain the `TestFunc()` method, which can be used to create a simple custom test similarly to Zod's `refine` method. The `TestFunc()` method takes a `ValidateFunc` as an argument. This is a function that takes the data as input and returns a boolean indicating whether it is valid. If you return `false` from the function, Zog will create a [ZogIssue](/errors). For example:🧰 Tools
🪛 LanguageTool
[style] ~14-~14: Consider replacing this phrase with the adverb “similarly” to avoid wordiness.
Context: ... be used to create a simple custom test in a similar way to Zod'srefine
method. The `TestFunc...(IN_A_X_MANNER)
[style] ~14-~14: In contexts where ‘if’ is followed by ‘or’, using ‘whether’ may be more appropriate (and formal).
Context: ... input and returns a boolean indicating if it is valid or not. If you return `fals...(IF_WHETHER)
[uncategorized] ~14-~14: A comma might be missing here.
Context: ... or not. If you returnfalse
from the function Zog will create a ZogIssue. ...(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
22-23
: Improve readability of the pro tip.Add missing comma and improve readability:
-> **Pro tip** -> It is very likely that you may want to set custom messages or paths, you can do that like with any other tests with `TestOptions`. For more on this checkout the [Anatomy of a Schema](/core-concepts/anatomy-of-schema#test-options) page. +> **Pro tip** +> It is very likely that you may want to set custom messages or paths. You can do that like any other tests with `TestOptions`. For more on this, check out the [Anatomy of a Schema](/core-concepts/anatomy-of-schema#test-options) page.🧰 Tools
🪛 LanguageTool
[uncategorized] ~23-~23: Possible missing comma found.
Context: ...r tests withTestOptions
. For more on this checkout the [Anatomy of a Schema](/cor...(AI_HYDRA_LEO_MISSING_COMMA)
docs/docs/core-concepts/1-anatomy-of-schema.md (1)
59-59
: Improve readability.Add missing comma:
-> A test is what zod calls a "validator". It is a struct that represents an individual validation. For example for the String schema `z.String()` the method `Min(3)` generates a test that checks if the string is at least 3 characters long. You can view all the default tests that come with each [schema type here.](/zog-schemas) +> A test is what zod calls a "validator". It is a struct that represents an individual validation. For example, for the String schema `z.String()`, the method `Min(3)` generates a test that checks if the string is at least 3 characters long. You can view all the default tests that come with each [schema type here.](/zog-schemas)🧰 Tools
🪛 LanguageTool
[typographical] ~59-~59: After the expression ‘for example’ a comma is usually used.
Context: ...epresents an individual validation. For example for the String schemaz.String()
the ...(COMMA_FOR_EXAMPLE)
docs/docs/zog-schemas.md (2)
33-34
: Improve readability.Add missing comma:
-These are options that can be passed to any test. For more on this checkout the [Anatomy of a Schema](/core-concepts/anatomy-of-schema#test-options) page. +These are options that can be passed to any test. For more on this, check out the [Anatomy of a Schema](/core-concepts/anatomy-of-schema#test-options) page.🧰 Tools
🪛 LanguageTool
[uncategorized] ~33-~33: Possible missing comma found.
Context: ... can be passed to any test. For more on this checkout the [Anatomy of a Schema](/cor...(AI_HYDRA_LEO_MISSING_COMMA)
53-54
: Improve readability.Rephrase for better clarity:
-These are options that can be passed to schema.Parse() & schema.Validate(). They configure the execution behaviour of the validation. +These are options that can be passed to the `Parse()` and `Validate()` methods. They configure the execution behavior of the validation.🧰 Tools
🪛 LanguageTool
[grammar] ~53-~53: The word ‘schema’ is not correct in this context. Use one of the suggestions or replace it with an appropriate verb.
Context: ...s These are options that can be passed to schema.Parse() & schema.Validate(). They confi...(VB_TO_NN_DT)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (15)
docs/docs/changes-from-zod.md
(1 hunks)docs/docs/configuration.md
(1 hunks)docs/docs/context.mdx
(1 hunks)docs/docs/core-concepts/1-anatomy-of-schema.md
(1 hunks)docs/docs/core-design-decisions.md
(1 hunks)docs/docs/custom-tests.md
(1 hunks)docs/docs/errors.md
(1 hunks)docs/docs/examples-of-use/_category_.json
(1 hunks)docs/docs/faq.md
(1 hunks)docs/docs/packages/_category_.json
(1 hunks)docs/docs/zog-schemas.md
(3 hunks)internals/contexts.go
(1 hunks)internals/tests.go
(1 hunks)utilsOptions.go
(1 hunks)utilsOptions_test.go
(2 hunks)
✅ Files skipped from review due to trivial changes (7)
- docs/docs/packages/category.json
- docs/docs/examples-of-use/category.json
- docs/docs/configuration.md
- docs/docs/context.mdx
- docs/docs/faq.md
- docs/docs/core-design-decisions.md
- docs/docs/errors.md
🧰 Additional context used
🪛 LanguageTool
docs/docs/custom-tests.md
[style] ~14-~14: Consider replacing this phrase with the adverb “similarly” to avoid wordiness.
Context: ... be used to create a simple custom test in a similar way to Zod's refine
method. The `TestFunc...
(IN_A_X_MANNER)
[style] ~14-~14: In contexts where ‘if’ is followed by ‘or’, using ‘whether’ may be more appropriate (and formal).
Context: ... input and returns a boolean indicating if it is valid or not. If you return `fals...
(IF_WHETHER)
[uncategorized] ~14-~14: A comma might be missing here.
Context: ... or not. If you return false
from the function Zog will create a ZogIssue. ...
(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
[uncategorized] ~23-~23: Possible missing comma found.
Context: ...r tests with TestOptions
. For more on this checkout the [Anatomy of a Schema](/cor...
(AI_HYDRA_LEO_MISSING_COMMA)
docs/docs/core-concepts/1-anatomy-of-schema.md
[typographical] ~59-~59: After the expression ‘for example’ a comma is usually used.
Context: ...epresents an individual validation. For example for the String schema z.String()
the ...
(COMMA_FOR_EXAMPLE)
docs/docs/zog-schemas.md
[uncategorized] ~33-~33: Possible missing comma found.
Context: ... can be passed to any test. For more on this checkout the [Anatomy of a Schema](/cor...
(AI_HYDRA_LEO_MISSING_COMMA)
[grammar] ~53-~53: The word ‘schema’ is not correct in this context. Use one of the suggestions or replace it with an appropriate verb.
Context: ...s These are options that can be passed to schema.Parse() & schema.Validate(). They confi...
(VB_TO_NN_DT)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Cloudflare Pages
🔇 Additional comments (6)
utilsOptions_test.go (1)
40-54
: LGTM!The test function thoroughly verifies the
IssueCode
feature by testing both Parse and Validate scenarios, ensuring that the issue code is correctly set and default messages are preserved.utilsOptions.go (1)
38-53
: LGTM!The
IssuePath
function is well-documented with clear usage examples and a warning about potential type safety issues.internals/contexts.go (1)
124-126
: LGTM!The modification to
IssueFromTest
correctly sets the custom issue path when provided.internals/tests.go (1)
16-16
: LGTM!The
IssuePath
field is appropriately added to theTest
struct.docs/docs/changes-from-zod.md (1)
1-19
: LGTM!The documentation clearly explains the differences between Zog and Zod, including the rationale for method name changes and design decisions.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~10-~10: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... adhere to the Zod API whenever possible but there are significant differences becau...(COMMA_COMPOUND_SENTENCE_2)
[uncategorized] ~13-~13: Possible missing comma found.
Context: ...thod name would be confusing for Golang devs I changed it - Some other changes: - ...(AI_HYDRA_LEO_MISSING_COMMA)
[uncategorized] ~14-~14: Possible missing preposition found.
Context: ...onfusing for Golang devs I changed it - Some other changes: - The refine method fo...(AI_HYDRA_LEO_MISSING_TO)
docs/docs/core-concepts/1-anatomy-of-schema.md (1)
65-69
: LGTM!The code examples effectively demonstrate the usage of test options, including the new
IssuePath
functionality.
Summary by CodeRabbit
Documentation
New Features