[x] We support only a subset of JSON Schema objects, arrays, primitive types.
[x] We should support polymorphic arrays.
[x] We support validators which are or can be added in the @rawmodel/validators.
[x] Should throw on invalid or unsupported schema style.
[x] Should work in backend or frontend with no additional dependencies
RawModel should provide its own schema structure which follows and can be created from JSON Schema. A schema in RawModel are basically arrays of property definitions.
export function parseJsonSchema(json) {
...
}
export function createModelClass(json: Schema) {
const Model = eval(`class ${json.title} extends Model {}`);
json.properties.forEach((prop) => {
Model.addProp(prop);
});
return Model;
}
import { parseJsonSchema, createModelClass } from '@rawmodel/schema';
// Parse JSON schema into RawModel Schema.
const schema = parseJsonSchema({ ...JSON_SCHEMA... });
// Create a new Model class object.
const User = createModelClass(schema);
@rawmodel/schema
package.RawModel should provide its own schema structure which follows and can be created from JSON Schema. A schema in RawModel are basically arrays of property definitions.
The new interface should look like this:
Refs: https://github.com/rawmodel/framework/issues/24, https://github.com/rawmodel/framework/issues/15