feat: allow removing property rules from validator by ids - #171
Open
nieomylnieja wants to merge 25 commits into
Open
feat: allow removing property rules from validator by ids#171nieomylnieja wants to merge 25 commits into
nieomylnieja wants to merge 25 commits into
Conversation
- Updated `golangci-lint` from version 2.5.0 to 2.6.1 in `devbox.json` and `devbox.lock`. - Introduced a new `uuid` package for generating UUIDs. The `GenerateUUID` function creates UUIDs compliant with version 4 specifications. - Added comprehensive unit tests for the `uuid` package to ensure correctness, including format validation, uniqueness, length checks, and bit correctness. - Enhanced the `govy` package with new features: - Added `instanceID` for unique identification of `Validator` and `PropertyRules` instances. - Introduced `WithID` and `GetID` methods for `Validator` and `PropertyRules` to manage and retrieve identifiers. - Implemented `RemoveProperties` in `Validator` to allow selective removal of properties or nested validators. - Updated benchmarks in `rules` package to use `b.Loop()` for improved readability and consistency. - Added new examples and tests to demonstrate and validate the usage of `RemoveProperties` and `GetID` functionalities.
|
Test coverage changes:
|
This update introduces the ability to set custom identifiers for property rules using the `WithID` method. The feature is implemented across `PropertyRules`, `PropertyRulesForSlice`, and `PropertyRulesForMap`. These identifiers can be used for referencing specific rules, such as when removing properties from a validator. The changes include: - Implementation of the `WithID` method in `PropertyRules`, `PropertyRulesForSlice`, and `PropertyRulesForMap`. - Updates to the `GetID` method to prioritize user-supplied IDs over names and auto-generated UUIDs. - Modifications to example and test files to demonstrate and validate the new functionality. - Adjustments to the `Makefile` to ignore `node_modules` during markdown linting.
This update introduces a shift from name-based property removal to ID-based property removal in the `govy` package. The changes include: - Replacing `RemoveProperties` with `RemovePropertiesByID` in the `Validator` API. - Modifying `PropertyRules.GetID` and `Validator.GetID` to return only user-supplied IDs or auto-generated UUIDs, removing reliance on property names. - Updating examples and tests to reflect the new ID-based approach, ensuring clarity and consistency. - Simplifying the internal logic for ID retrieval by consolidating methods in the `instanceID` struct. These changes enhance the flexibility and reliability of property rule management, particularly in dynamic or complex validation scenarios.
nieomylnieja
added a commit
that referenced
this pull request
Nov 13, 2025
## Motivation Sometimes you want to create a modified validator without certain rules, the only way to achieve that currently is during the validator's definition. If you are importing a module which defines a validator, you have currently no way to change its rules in any way. That's why it would be useful to be able to remove properties' rules by name. ## Related Changes There's another PR which explores deleting properties by IDs: #171. ## Release Notes Added `govy.Validator.RemovePropertiesByName` method.
…ty-rules-by-id # Conflicts: # devbox.json # devbox.lock # pkg/govy/example_test.go # pkg/govy/rules.go # pkg/govy/rules_for_map.go # pkg/govy/rules_for_slice.go # pkg/govy/rules_test.go # pkg/govy/validation.go # pkg/govy/validator.go
Avoid mutating the enum value before bounds checking so unknown keys render their original numeric value and valid lookups use a safe zero-based index.
Ensure `ForPointer` and `Transform` create generated property IDs so `RemovePropertiesByID` can filter those rules consistently with `For`.
nieomylnieja
marked this pull request as ready for review
June 16, 2026 17:33
Demonstrate removing multiple properties by explicit and generated IDs, including the resulting validation error.
Remove auto-generated property IDs and ignore empty IDs when filtering validators.
…ty-rules-by-id # Conflicts: # pkg/govy/example_test.go # pkg/govy/rules.go # pkg/govy/validator_test.go
Replace optimized ID-removal paths with a single filtering implementation and delegate builder inheritance to public methods. Update tests and examples to cover direct property removal behavior.
…ty-rules-by-id # Conflicts: # pkg/govy/example_test.go
n9-machine-user
left a comment
Collaborator
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Govy Go Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 59342fa | Previous: 95e0216 | Ratio |
|---|---|---|---|
BenchmarkStringUUID/valid (github.com/nobl9/govy/pkg/rules) |
522.9 ns/op 10.00 validations/op 0 B/op 0 allocs/op |
251.4 ns/op 10.00 validations/op 0 B/op 0 allocs/op |
2.08 |
BenchmarkStringUUID/valid (github.com/nobl9/govy/pkg/rules) - ns/op |
522.9 ns/op |
251.4 ns/op |
2.08 |
BenchmarkStringUUIDRFC4122/valid (github.com/nobl9/govy/pkg/rules) |
403.1 ns/op 9.000 validations/op 0 B/op 0 allocs/op |
234.6 ns/op 9.000 validations/op 0 B/op 0 allocs/op |
1.72 |
BenchmarkStringUUIDRFC4122/valid (github.com/nobl9/govy/pkg/rules) - ns/op |
403.1 ns/op |
234.6 ns/op |
1.72 |
BenchmarkStringUUIDv4/valid (github.com/nobl9/govy/pkg/rules) |
194.3 ns/op 5.000 validations/op 0 B/op 0 allocs/op |
128.4 ns/op 5.000 validations/op 0 B/op 0 allocs/op |
1.51 |
BenchmarkStringUUIDv4/valid (github.com/nobl9/govy/pkg/rules) - ns/op |
194.3 ns/op |
128.4 ns/op |
1.51 |
BenchmarkStringUUIDv5/valid (github.com/nobl9/govy/pkg/rules) |
230 ns/op 5.000 validations/op 0 B/op 0 allocs/op |
132.8 ns/op 5.000 validations/op 0 B/op 0 allocs/op |
1.73 |
BenchmarkStringUUIDv5/valid (github.com/nobl9/govy/pkg/rules) - ns/op |
230 ns/op |
132.8 ns/op |
1.73 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @nieomylnieja
Traverse included validators, including nested slice and map rules, when removing properties by ID. Add coverage for recursive removal while preserving immutable validator behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Other packages can export validators. Callers need to remove selected property rules without rebuilding the validator or depending on property paths.
Summary
WithIDfor scalar, slice, and map property rules.Validator.RemovePropertiesByIDto remove matching direct property rules without traversing included validators.Related Changes
PR #172 added removal by property paths. This PR provides an alternative that does not depend on paths.
Testing
Release Notes
Property rules can now receive caller-defined IDs with
WithID. Callers can useValidator.RemovePropertiesByIDto derive a validator without matching direct property rules.