add type json-schemas for all data models#124
Conversation
| }), | ||
| connectForm({ | ||
| form: 'profile', | ||
| initialValues: { |
There was a problem hiding this comment.
@ahdinosaur How can I fill the form with data from props? When I remove the initialValues the form is empty. I'm needing this to fill the Profile story with fake data.
There was a problem hiding this comment.
right, we pass in initivalValues and enableReinitialize. can either cherry-pick from there, merge that pull request as is and rebase on top, or add those lines here.
There was a problem hiding this comment.
@ahdinosaur Thanks! Added those lines (see below commit)
|
|
||
| const Ajv = require('ajv') | ||
| const { validateSchema } = require('feathers-hooks-common') | ||
| const schema = require('../schemas/taskPlan') |
There was a problem hiding this comment.
Hey @ahdinosaur Would love some help here as I've been working on this problem for a while with no luck.
I'm getting this error when running this test:
[SyntaxError: Error resolving $ref pointer "http://localhost:3000/tasks/schemas/taskRecipe.json#/id".
Token "id" does not exist.]
Even when the id property is in the schema
Thanks!
There was a problem hiding this comment.
it seems the library expects to find referenced schemas at a particular remote URL, according to the JSON schema standard. we want to somehow locally pass in all the schemas up front and tell it not to look remotely.
| "type": "object", | ||
| "properties": { | ||
| "id": { | ||
| "$ref": "#/id" |
There was a problem hiding this comment.
or maybe this should be #/definitions/id?
f2bb8df to
4f81f6a
Compare
| heroku run npm run db migrate:latest --app=cobuy | ||
| ``` | ||
|
|
||
| ### JSON schema |
| "required": [ | ||
| "id", | ||
| "agentId", | ||
| "name" |
There was a problem hiding this comment.
i'm not sure if name is required. or at least, at the moment i think we create "empty" profiles when we create a group agent to be updated later.
| avatar: 'http://dinosaur.is/images/mikey-small.jpg' | ||
| } | ||
| } | ||
| const profile = jsf(schema) |
| "description": "Id referencing profile" | ||
| }, | ||
| "agentId": { | ||
| "type": "integer", |
There was a problem hiding this comment.
can this be
{
"$ref": "/agents/Agent#/definitions/id"
}
oh wait nevermind, we don't have a schema for Agent. all good!
| "description": "Person or group or related agents (e.g. admins) being assigned" | ||
| }, | ||
| "taskRecipeId": { | ||
| "$ref": "/tasks/taskRecipe#/definitions/id", |
| { | ||
| "id": "/tasks/taskPlan", | ||
| "title": "Task Plan", | ||
| "description": "An assignment of the task to an agent", |
| "description": "Id referencing task plan" | ||
| }, | ||
| "parentTaskPlanID": { | ||
| "type": "integer", |
There was a problem hiding this comment.
can this be a $ref like taskRecipeId?
| const Ajv = require('ajv') | ||
| const taskPlanSchema = require('../schemas/taskPlan') | ||
| const taskRecipeSchema = require('../schemas/taskRecipe') | ||
| const ajv = new Ajv({$data: true}) |
There was a problem hiding this comment.
i wonder if this should be a singleton somewhere in a module. like we export the ajv object with all the schemas added in app/schema.js. then we'd require that here.
| all: [ | ||
| // encodeParams | ||
| ] | ||
| create: [validateSchema(taskPlanSchema, ajv), encodeParams], |
There was a problem hiding this comment.
very legit.
minor nit: maybe format for each hook to be on its own line.
| assigneeId: hook.data.assigneeId, | ||
| taskRecipeId: childTaskRecipe.id, | ||
| params: hook.data.params | ||
| params: hook.result.params |
| @@ -0,0 +1,34 @@ | |||
| import test from 'ava' | |||
Have not tested internal $ref yet
Still need to write tests to test the self referencing taskRecipe
commiting to recieve feedback
90b9312 to
662ba60
Compare
|
@ahdinosaur Changes and rebase made ready for merge |
In this PR:
Not in this PR
closes #118