Skip to content

Dereference behavior does not follow AsyncAPI reference object and JSON Schema draft 7 behavior #404

@jonaslagoni

Description

@jonaslagoni

Describe the bug

We use the @apidevtools/json-schema-ref-parser dependency to resolve all references, however, this has a faulty implementation.

AsyncAPI 2.2.0 defines a reference as:

The Reference Object is defined by JSON Reference and follows the same structure, behavior and rules. ... . This object cannot be extended with additional properties and any properties added SHALL be ignored.

JSON Schema draft 7 defines the reference behavior as:

An object schema with a "$ref" property MUST be interpreted as a "$ref" reference. ... . All other properties in a "$ref" object MUST be ignored.

Meaning the two overlap in their behavior (lucky for us).

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'
        name: 'MyOtherMessageName' # Should not be valid
components:
  messages:
    myMessage:
      name: 'MyMessage'
      payload:
        type: object
        properties:
          sentAt:
            $ref: "#/components/schemas/sentAt"
            description: 'test' # Should not be valid
  schemas:
    sentAt:
      type: string
      format: date-time
      description: Date and time when the message was sent.

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

As it can be seen both name in the AsyncAPI reference object for the message is applied, which results in the message being called MyOtherMessageName and not MyMessage.

Same with the JSON Schema the description of the payload message object it has the description test and not Date and time when the message was sent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions