Skip to content

$refs are not resolved correctly w/r/t JSON Schema #471

@hdonnay

Description

@hdonnay

In an OpenAPI doc like in the details, the $ref from one type should resolve to the other.

As I understand the OpenAPI and JSON Schema specs, the relative URI $ref should be resolved to an absolute URI using the context of the schema's $id if present, and that value should be checked against other already-resolved $ids. It seems that $ids are not checked, currently.

openapi: 3.1.0
components:
  schemas:
    s1:  # This object should be resolvable at "https://example.com/a.json" from anywhere, and "#/components/schemas/s1" from a schema object without a "$schema" field.
      $schema: "https://json-schema.org/draft/2020-12/schema"
      $id: "https://example.com/a.json"
      type: "string"
    s2:
      $schema: "https://json-schema.org/draft/2020-12/schema"
      $id: "https://example.com/b.json"
      $ref: "a.json"  # becomes "https://example.com/a.json", which should already be resolved.

This is freehand, so there may be some problem; sorry. I can try to bust down my real-world OpenAPI spec if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions