Repository navigation
test: add comprehensive schema validation unit tests - #125
Merged
Merged
Conversation
Add a suite of new unit tests for OpenAPI schema validation covering const/default interactions, enum uniqueness and conflicts, numeric constraints, exclusive bounds, fraction multipleOf behavior, and schema "dollarSchema" URI validation. Key additions: - TestSchemaConstWithMatchingDefaultInteger and TestSchemaConstWithNonMatchingDefaultError to validate const vs default value handling. - TestSchemaEnumDuplicateValueError and TestSchemaConstWithEnumConflict to ensure enums reject duplicate values and incompatible const+enum usage. - TestSchemaFractionalMultipleOfAllowed to allow fractional multipleOf (e.g., 0.01) with numeric ranges. - TestSchemaInvalidMaximumLessThanMinimumError and TestSchemaExclusiveMaximumLessThanExclusiveMinimumError to enforce min/max ordering for inclusive and exclusive bounds. - TestSchemaDollarSchemaAbsoluteURIOk and TestSchemaDollarSchemaNonAbsoluteURIError to require dollarSchema be an absolute URI. - Begin adding TestSchema_MaxContainsWithoutContains_Error (incomplete in diff) to cover contains/maxContains relationships. These tests increase coverage of schema validation rules and prevent regressions by asserting both valid schemas pass and invalid schemas produce descriptive errors.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive unit tests for OpenAPI schema validation to ensure proper handling of schema constraints and prevent regressions. The tests cover validation rules for const/default value interactions, enum constraints, numeric bounds, and URI validation.
Key changes:
- Tests for const/default value validation and enum uniqueness/conflicts
- Validation of numeric constraints including min/max bounds and fractional multipleOf
- URI validation for the dollarSchema field and contains/maxContains relationships
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| schema_test.go | Adds 11 new unit tests covering schema validation scenarios for const/default, enum, numeric constraints, and URI validation |
| schema.go | Updates schema validation logic to support new test cases, including type changes from int to float64 for numeric fields and enhanced validation rules |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Add a suite of new unit tests for OpenAPI schema validation covering
const/default interactions, enum uniqueness and conflicts, numeric
constraints, exclusive bounds, fraction multipleOf behavior, and schema
"dollarSchema" URI validation.
Key additions:
TestSchemaConstWithNonMatchingDefaultError to validate const vs default
value handling.
ensure enums reject duplicate values and incompatible const+enum usage.
(e.g., 0.01) with numeric ranges.
TestSchemaExclusiveMaximumLessThanExclusiveMinimumError to enforce min/max
ordering for inclusive and exclusive bounds.
TestSchemaDollarSchemaNonAbsoluteURIError to require dollarSchema be an
absolute URI.
diff) to cover contains/maxContains relationships.
These tests increase coverage of schema validation rules and prevent
regressions by asserting both valid schemas pass and invalid schemas
produce descriptive errors.