Open sovanyio opened 8 years ago
As our objective is to generate a form (and not just use a schema to manipulate some structured data), we had to extend JSON Schema so we can handle form-specific features (like field widget, help messages, fieldsets, etc.).
But we do want to support the standard as closely as possible.
Regarding title
: as far as I know, there is no title attribute for fields, do you mean the schema's title?
Regarding self-reference: what use case do you imagine?
An example of a self reference is a schema in which you have a definitions section containing Types, which you then use in the schema properties.
For example:
{
"id": "http://schange.com/schemas/a5sharedconfigschema.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"regions": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/definitions/regionType"
}
}
},
"definitions": {
"regionType": {
"properties": {
"tag": {
"description": "Tag that uniquely identifies a given region",
"type": "string"
},
"currency": {
"description": "Three letter alphabetic code for the currency from ISO 4217 (XYZ)",
"type": "string",
"pattern": "[A-Z]{3}"
}
},
"required": [
"tag",
"currency"
]
}
}
}
Note: this is a reference within the same schema file. We also would like to make use of references outside the schema file to allow re-use of type definitions.
Any plans to add the $ref support to this component?
Besides usage of $ref in Schema, I am also having a use case where I would like to make use of $ref support in the Model json.
Until it is implemented, you can resolve the $ref properties by compiling your schema with ZSchema:```
let zschema = new ZSchema({});
zschema.compileSchema(mySchema);
mySchema = zschema.getResolvedSchema(mySchema);
but note that $ref usage is often combined with allOf properties to add additional properties such as title, placeholder, etc... . But allOf is not yet supported. These two features will be added soon.
ok, thanks for the answer. Going to test this solution soon.
I tested the workaround with the example I posted before in this issue, and it does not work. The example I posted contains local references within the same json schema file. So for z-schema I suppose there is nothing to be resolved. Z-Schema resolving might only work for remote references. However, you end up in both scenarios with a schema containing $ref indicators which are not supported by angular2-schema-form.
@bombompb I used I used https://github.com/izumin5210/json-schema-parser to parse the schema. Produced the form ok for me with local $ref
@ebrehault hello, what about schema's title? As I understand it, now only the description works, right? Are there any plans to add support "title" schema's property as it stated in the standard?
@GermisMc the default widget template mainly use the description (but some use title, see https://github.com/makinacorpus/angular2-schema-form/blob/master/src/defaultwidgets/radio/radio.widget.ts), but you are free to override their template and use {{ schema.title }}
if you prefer.
This implementation doesn't support the schema standard, most notably on the use of 'title' to describe the fields and not supporting self-references.
http://json-schema.org/latest/json-schema-core.html