Skip to content

Add support for $schema and jsonSchemaDialect #2963

Description

@baywet

In today's implementation (2.11.0, 3.9.0), the deserialization and serialization of JSON Schemas is effectively hard-coded to 2020-12.

However, starting with OpenAPI 3.1, people can set the $schema property of any given schema to a different dialect (default being documented here.

This entails a couple of things:

  1. parsing that keyword first if it exists, or falling back on the document dialect property, or falling back to the default value for the OpenAPI version.
  2. if that value is known (like https://spec.openapis.org/oas/3.1/dialect/base using the parsing logic associated with that entry
  3. if that value is unknown, we need to load the corresponding schema, and read its schema (recursively) until we find a known value. (note be careful of the security considerations here)

Note: ideally we'd make the OpenAPISchema type generic and allow the caller to provide new registrations of schemas uris with the corresponding parsing logic and data type, but that'd introduce major breaking changes, making the cost prohibitive.

That update will most likely require introducing a JSON Schema service of some kind in charge of mapping the known schemas with their deserialization logic, and having the OpenAPISchema deserializers call into that service.

Activity

  1. iamhaseebn commented on Aug 23, 2026

    @iamhaseebn

    I would like to take this.

  2. baywet commented on Aug 24, 2026

    @baywet
    MemberAuthor

    Hi Haseeb Nazir (@iamhaseebn),

    Sure, we'll be happy to get a pull request.

    Before starting to write code, can you please suggest a design which would inform this work?

  3. iamhaseebn commented on Aug 24, 2026

    @iamhaseebn

    Thanks! I was thinking we could keep this internal in ParsingContext rather than changing the public schema types.

    When reading a schema, we'd resolve the dialect from its $schema value or inherited dialect, then fall back to the document's jsonSchemaDialect, and finally the OpenAPI version default. The service would select the matching parsing rules, while keywords we don't understand would stay in UnrecognizedKeywords so they aren't lost.

    For an unknown dialect URI, we'd reuse the existing external-loading path, cache the meta-schema, and follow its $schema chain until reaching a known dialect. This would include cycle detection and reasonable depth and size limits. If it can't be resolved, we'd report a diagnostic instead of silently treating it as JSON Schema 2020-12.

    I'd apply the same dialect selection when writing and add matching OpenAPI 3.1 and 3.2 tests. If this direction looks right, I'll work from it.

  4. baywet commented on Aug 24, 2026

    @baywet
    MemberAuthor

    I think that sounds like a great approach. I'm not sure how the mapping from a dialect to the parsing logic will happen, but maybe we can rely on the existing version services? or a similar approach.

    Anyway, please start a draft PR, and we can iterate from there.

  5. iamhaseebn commented on Aug 24, 2026

    @iamhaseebn

    Sounds good, thanks. I’ll use the existing version services as the starting point for the dialect mapping and open a draft PR so we can work through the details there.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions