Goal
Add support for JSON Schema conditional and dependency keywords:
dependentRequired
dependentSchemas
if
then
else
These keywords let schemas express cross-property requirements, such as requiring billing details when a credit card field is present, or requiring state/country fields depending on a condition.
Proposed DSL
Inline property dependencies for simple dependentRequired output:
number :credit_card, required: false, requires: %i[billing_address cvv]
Block-based dependencies when additional validation is needed:
dependent :credit_card do
requires :billing_address
validates :billing_address, type: :string, min_length: 1
end
Conditional if / then / else output through a Ruby-friendly DSL:
given domestic: true do
requires :state
otherwise do
requires :country
end
end
Acceptance criteria
- Works at root schema output.
- Works in nested inline schemas.
- Works in reusable schemas under
$defs.
- Inline
requires: emits dependentRequired.
dependent with validations emits dependentSchemas.
given emits if / then / optional else.
- Behavior tests cover
then, else, dependentRequired, and dependentSchemas.
- Generated schemas validate against Draft 2020-12 after the final output contract is decided.
Related work
PR #31 is expected to implement this issue.
Goal
Add support for JSON Schema conditional and dependency keywords:
dependentRequireddependentSchemasifthenelseThese keywords let schemas express cross-property requirements, such as requiring billing details when a credit card field is present, or requiring state/country fields depending on a condition.
Proposed DSL
Inline property dependencies for simple
dependentRequiredoutput:Block-based dependencies when additional validation is needed:
Conditional
if/then/elseoutput through a Ruby-friendly DSL:Acceptance criteria
$defs.requires:emitsdependentRequired.dependentwith validations emitsdependentSchemas.givenemitsif/then/ optionalelse.then,else,dependentRequired, anddependentSchemas.Related work
PR #31 is expected to implement this issue.