Skip to content

Conversation

@vadyvas
Copy link

@vadyvas vadyvas commented Jan 28, 2026

TBD:

  • cli pr

What issue does this pull request resolve?

Fixes false validation warnings/errors when required is combined with readOnly / writeOnly in OpenAPI schemas—especially for request/response examples where:

What changes did you make?

  • Made readOnly/writeOnly context-aware validation keywords (when OAS context is provided):
    • Added lib/vocabularies/validation/readOnly.ts
    • Added lib/vocabularies/validation/writeOnly.ts
    • Registered them in lib/vocabularies/validation/index.ts
    • Removed readOnly/writeOnly from lib/vocabularies/metadata.ts so they don’t get treated as “annotation-only” -metadata (which would block validation behavior).
  • Updated required validation to respect OAS request/response mode:
    • In lib/vocabularies/validation/required.ts, skips required-checks for:
      • readOnly: true properties in request context
      • writeOnly: true properties in response context
    • This only activates when the validator is called with an OAS context (via this.oas).
  • Added coverage tests:
    • New spec/validation/read-write.spec.ts verifies:
      • default behavior without OAS context stays unchanged
      • readOnly rejected in request / writeOnly rejected in response (with context)
      • required skipping behavior is correct per context.

Is there anything that requires more attention while reviewing?

  • Context passing is required for the new behavior: the caller must use passContext: true and call validation with a this context like { oas: { mode: 'request' | 'response', location? } }. Without it, behavior stays as before.

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.

3 participants