Skip to content

JSON Schema references do not follow $id dereference behavior #403

Open

Description

@jonaslagoni

Describe the bug

We use the @apidevtools/json-schema-ref-parser dependency to resolve all references, however, this tool does not follow JSON Schema specification in terms of dereferencing: APIDevTools/json-schema-ref-parser#22 (comment)

Based on JSON Schema draft 7, it states that:

The "$id" keyword defines a URI for the schema, and the base URI that other URI references within the schema are resolved against. A subschema's "$id" is resolved against the base URI of its parent schema. If no parent sets an explicit base with "$id", the base URI is that of the entire document, as determined per RFC 3986 section 5 [RFC3986].

This means that given the following AsyncAPI document:

asyncapi: '2.2.0'
info:
  title: Test overriding dereferenced objects 
  version: '1.0.0'
channels:
  test:
    publish:
      message:
        $ref: '#/components/messages/myMessage'
components:
  messages:
    myMessage:
      schemaFormat: application/schema+json;version=draft-07
      name: MyMessage
      payload:
          $id: 'http://localhost.com/'
          type: object
          properties:
            sentAt:
              $ref: "/components/schemas/sentAt"

Check out the studio example (it uses this parser library for resolving the references)

The library tries to resolve the reference athttps:///components/schemas/sentAt when it should have tried to resolve it from http://localhost.com/components/schemas/sentAt

Activity

  1. added
    bug
    on Nov 10, 2021
  2. jonaslagoni commented on Nov 10, 2021

    @jonaslagoni
    MemberAuthor
  3. smoya commented on Nov 18, 2021

    @smoya
    Member

    For the record, there is a recent effort on building JSON Schema foundational tooling with kind of (TBD) official support, lead by @jviotti and @Relequestual here json-schema-org/community#113.

  4. github-actions commented on Mar 19, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

  5. github-actions commented on Sep 17, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

  6. github-actions commented on Jan 17, 2023

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

  7. jonaslagoni commented on May 17, 2023

    @jonaslagoni
    MemberAuthor

    Still a problem.

  8. dskvr commented on Jan 7, 2025

    @dskvr

    Still a problem.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugkeep-open

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions