fix: improve JSON Schema conversion for number.port() and number.sign()#3107
Merged
Merged
Conversation
- Add jsonSchema conversion for number.port() rule, producing type: integer with minimum: 0 and maximum: 65535 - Replace non-standard x-constraint for number.sign() with proper JSON Schema keywords: exclusiveMinimum: 0 for positive, exclusiveMaximum: 0 for negative
Collaborator
|
Good catch, thanks! |
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.
While using Joi schemas with the Standard Schema JSON Schema output for API documentation, I noticed two gaps in the
numbertype's JSON Schema conversion:1.
number.port()— missing JSON Schema outputJoi.number().port()validates that a value is an integer between 0 and 65535, but it produced no JSON Schema constraints — just{"type": "number"}.Before:
{"type": "number"}After:
{"type": "integer", "minimum": 0, "maximum": 65535}2.
number.sign()— non-standardx-constraintJoi.number().positive()/.negative()used a non-standardx-constraintproperty instead of the standard JSON Schema keywords.Before:
{"type": "number", "x-constraint": {"sign": "positive"}}After:
{"type": "number", "exclusiveMinimum": 0}Before:
{"type": "number", "x-constraint": {"sign": "negative"}}After:
{"type": "number", "exclusiveMaximum": 0}exclusiveMinimumandexclusiveMaximumare standard JSON Schema Draft 2020-12 keywords that correctly express the same constraint.Changes
lib/types/number.js: AddedjsonSchemahandler forportrule, updatedsignrule to use standard keywordstest/json-schema.js: Added test forport()conversion, updated sign test expectationsAll tests pass: 1797 tests, 100% coverage, lint clean, types clean.