Can't import external schema and spread it into the local schema
bitflower opened this issue · 2 comments
Expected behavior
Tell us what should happen
Actual behavior
We are maintaining a separate repo for all our JSON schemas. That's because we have schema we only use in the client for example. Some are also used as Feathers schemas. With the new generator we want to import an external schema and use it in the local schema. The term at the top of the file
// Define the Feathers schema for service `secondTest`. (Can be re-generated.)
// !code: imports
led me to believe this is possible - maybe it's not?
This is how I imagined it to work:
// Define the Feathers schema for service `secondTest`. (Can be re-generated.)
// !code: imports
import { CoSchemas } from '@case-os/schema';
// !end
// !code: init
// !end
// Define the model using JSON-schema
let schema = {
// !<DEFAULT> code: schema_header
title: 'SecondTest',
description: 'SecondTest database.',
// !end
// !code: schema_definitions // !end
// Required fields.
required: [
// !code: schema_required
'_id',
'name'
// !end
],
// Fields with unique values.
uniqueItemProperties: [
// !code: schema_unique // !end
],
// Fields in the model.
properties: {
// !code: schema_properties
...CoSchemas.atom.properties
// !end
}
// !code: schema_more // !end
};
An even better approach would be to just do:
let schema = CoSchemas.atom;
But that gets completely replaced.
Repo
Here is a repo that produces the error. I've detailed how to reproduce it in the readme.md
I don't think you can do ...CoSchemas
inside a json object like that.
What you should do is create and populate the properties object outside the json object and Object.assign
it (or lodash
_.merge
depending on need) with the schema object.
You should do this between:
// !code: init
// !end
and then the merge between:
// !code: more // !end
Thanks @MarcGodard . In the meantime I've gone a completely different road the Feathers project being the "lead".