ngx-schema-form
ngx-schema-form copied to clipboard
`Maximum call stack size exceeded` if scheme has circular references
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"
}
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);
})();
}