ngx-schema-form icon indicating copy to clipboard operation
ngx-schema-form copied to clipboard

`Maximum call stack size exceeded` if scheme has circular references

Open KEIII opened this issue 5 years ago • 1 comments

Schema example with circular references what produce an Maximum call stack size exceeded error.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "Diagram": {
      "properties": {
        "DiagramObjects": {
          "items": {
            "$ref": "#/definitions/DiagramObject"
          },
          "type": "array"
        }
      },
      "type": "object"
    },
    "DiagramObject": {
      "properties": {
        "Diagram": {
          "$ref": "#/definitions/Diagram"
        }
      },
      "type": "object"
    }
  },
  "description": "Core schema meta-schema",
  "id": "http://json-schema.org/draft-04/schema#",
  "properties": {
    "Diagram": {
      "$ref": "#/definitions/Diagram"
    }
  },
  "type": "object"
}

KEIII avatar Feb 11 '20 19:02 KEIII

Important missing thing — scheme must be compiled before send into sf-form.

Example:

// app.component.html
<sf-form [schema]="schema"></sf-form>
// app.component.ts
import { Component } from '@angular/core';
import * as ZSchema from 'z-schema';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
})
export class AppComponent {
  public readonly schema = (() => {
    const zSchema = new ZSchema({});
    zSchema.compileSchema(require('./schema.json'));
    return zSchema.getResolvedSchema(schema);
  })();
}

KEIII avatar Feb 20 '20 17:02 KEIII