Skip to content

Accept Python bytes for raw binary payloads#298

Open
p1c2u wants to merge 1 commit into
masterfrom
feature/binary-bytes-validation
Open

Accept Python bytes for raw binary payloads#298
p1c2u wants to merge 1 commit into
masterfrom
feature/binary-bytes-validation

Conversation

@p1c2u
Copy link
Copy Markdown
Collaborator

@p1c2u p1c2u commented Jun 4, 2026

Accept Python bytes for opaque binary payloads across OAS 3.0, 3.1, and 3.2,
implementing the binary-bytes validation design.

Binary detection now lives in one place (_binary.py) as pure, per-version
predicates, replacing the old inline format: binary branch. bytes acceptance
is confined to the type keyword wrapper; the "string" type checker is never
broadened.

Changes

  • 3.0: type: string, format: binary accepts bytes (now also enforces
    maxLength/minLength by octet count). OAS30StrictValidator still rejects.
  • 3.1/3.2 (default): canonical typeless schema (optionally a non-text
    contentMediaType, no contentEncoding) accepts bytes; type: string +
    non-text contentMediaType accepted as a documented pragmatic extension.
  • New OAS31StrictValidator / OAS32StrictValidator: preserve JSON Schema
    string typing — accept typeless raw binary but reject bytes whenever
    type: string is asserted. validator_for still resolves dialect ids to the
    default validators.
  • maxLength/minLength enforce octet length for raw bytes; enum/const
    stay active; pattern short-circuits bytes with no TypeError.
  • Broadened encoded-text exclusion (any real contentEncoding, with no-op
    identity/binary/7bit/8bit allowlist); media-type parameters stripped
    and matched case-insensitively.

Migration

In 3.1/3.2, format: binary is no longer a binary marker (under 2020-12
format is an annotation). bytes validated against a 3.1/3.2
{"type": "string", "format": "binary"} schema is now rejected — model raw
binary with contentMediaType (ideally a typeless schema).

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