Skip to content

Circluar reference detected one level too late when referencing local schema by name #378

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

Open
SebastienGllmt opened this issue Apr 6, 2025 · 0 comments

Comments

@SebastienGllmt
Copy link

What works

The given schema

{
  "$id": "recursive.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "label": {
      "anyOf": [
        {
          "type": "integer"
        }
      ]
    },
    "value": {
      "$ref": "#"
    }
  },
  "title": "RecursiveType",
  "type": "object"
}

gives the resulting JS object which is properly circular right away (object > [Circular])

<ref *1> {
  '$id': 'recursive.json',
  '$schema': 'https://json-schema.org/draft/2020-12/schema',
  properties: {
    label: { anyOf: [ { type: 'integer' } ] },
    value: [Circular *1]
  },
  title: 'RecursiveType',
  type: 'object'
}

What doesn't work

Change the reference to be by name instead of just #

{
  "$id": "recursive.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "label": {
      "anyOf": [
        {
          "type": "integer"
        }
      ]
    },
    "value": {
      "$ref": "recursive.json"
    }
  },
  "title": "RecursiveType",
  "type": "object"
}

This instead gives the following TS. Note that it's the same as above EXCEPT it's expanded one level too deep object > object > [Circular]

{
  '$id': 'recursive.json',
  '$schema': 'https://json-schema.org/draft/2020-12/schema',
  properties: {
    label: { anyOf: [ { type: 'integer' } ] },
    value: <ref *1> {
      '$id': 'recursive.json',
      '$schema': 'https://json-schema.org/draft/2020-12/schema',
      properties: {
        label: { anyOf: [ { type: 'integer' } ] },
        value: [Circular *1]
      },
      title: 'RecursiveType',
      type: 'object'
    }
  },
  title: 'RecursiveType',
  type: 'object'
}
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

1 participant