Skip to content

refactor: json-schema feature#3110

Closed
AbdelrahmanHafez wants to merge 39 commits into
hapijs:masterfrom
AbdelrahmanHafez:json-schema-refactor
Closed

refactor: json-schema feature#3110
AbdelrahmanHafez wants to merge 39 commits into
hapijs:masterfrom
AbdelrahmanHafez:json-schema-refactor

Conversation

@AbdelrahmanHafez
Copy link
Copy Markdown

Context: stacked on top of #3109

This PR is a cleanup refactor of the Standard JSON Schema implementation. It is not meant to change behavior, the goal is to move the JSON Schema-specific code out of the core Joi files and make the feature easier to follow and maintain.

This PR:

  • extracts the generic $_jsonSchema() conversion pipeline from lib/base.js into lib/json-schema/base.js
  • moves shared JSON Schema helpers for annotations, enum/only handling, value conversion, and conditional expansion into dedicated modules under lib/json-schema/
  • moves object-specific emission, dependency handling, and when() hoisting logic out of lib/types/keys.js into lib/json-schema/object.js
  • moves the small shared helpers used by alternatives() and binary() into lib/json-schema/alternatives.js and lib/json-schema/binary.js
  • leaves the actual Joi type implementations thinner, they mostly describe the mapping now instead of carrying the helper infrastructure too

I left the JSON Schema test requirements unchanged for this refactor and ran the full suite after the move, so this should be behavior-preserving.

…d preferences

- Fix alternatives.match('all') producing anyOf instead of allOf
- Skip rule jsonSchema handlers when args contain Refs
- Handle _invalids as not: { enum: [...] }
- Exclude forbidden keys and stripped keys (output mode) from properties
- Add all object dependency handlers (with, without, and, nand, or, xor, oxor)
- Add string.alphanum pattern and string.domain pattern with options
- Add number.precision as multipleOf
- Add date.timestamp with ECMA-262 range limits
- Register id'd child schemas in $defs for Joi.link() without .shared()
- Respect preferences: allowUnknown, stripUnknown, presence, noDefaults

re hapijs#3108
@AbdelrahmanHafez
Copy link
Copy Markdown
Author

Closing this stacked refactor PR because the commits are now folded into #3109.

@AbdelrahmanHafez
Copy link
Copy Markdown
Author

Merged into #3109 to avoid complicating this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant