Skip to content

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

Open
@SebastienGllmt

Description

@SebastienGllmt

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'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions