Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about references ($ref) #1508

Closed
shonigbaum opened this issue May 16, 2024 · 2 comments
Closed

Question about references ($ref) #1508

shonigbaum opened this issue May 16, 2024 · 2 comments

Comments

@shonigbaum
Copy link

shonigbaum commented May 16, 2024

Hello together,

I have a small question about references. I’m currently in a discussion with a library owner whether the provided $ref is valid or invalid.

Given is the following schema:

{
  "$id": "schemaA/1.0",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "fee": {
      "type": "object",
      "properties": {
        "modificationFee": {
          "$ref": "#/properties/purchaseRate/allOf/0"
        }
      }
    },
    "purchaseRate": {
      "allOf": [
        {
          "type": "object",
          "properties": {
            "amount": {
              "type": "number",
              "format": "float"
            }
          }
        },
        {
          "type": "object",
          "$ref": "#/properties/fee/properties/modificationFee/properties/amount"
        }
      ]
    }
  }
}

Question:
Is the $ref to #/properties/fee/properties/modificationFee/properties/amount a valid $ref?

The first part points to #/properties/fee/properties/modificationFee, which contains a second $ref to #/properties/purchaseRate/allOf/0. And the second part /properties/amount relates on this second $ref.

It appears incorrect to me. Is there a section in the specifications that addresses this topic? I couldn’t find anything related.

Thanks in advance.

@mwadams
Copy link

mwadams commented May 16, 2024

It is not a valid $ref, no. It's also slightly odd.

First, in draft 7, $ref causes all other sibling keywords to be ignored, so the "type": "object" is irrelevant. This isn't a "problem" it's just odd.

Then, a $ref resolves relative to the base uri for the schema. There is no such property at this path #/properties/fee/properties/modificationFee/properties/amount so the ref is unresolved.

It doesn't work by "copying" the referenced value in the document and then resolving against the "expanded" document, which is what it looks like the schema is intending.

@shonigbaum
Copy link
Author

Thank you for your fast answer, @mwadams! :-)

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

No branches or pull requests

3 participants