Skip to content

add type json-schemas for all data models#124

Merged
ahdinosaur merged 16 commits into
masterfrom
chore/json-schemas
Aug 30, 2017
Merged

add type json-schemas for all data models#124
ahdinosaur merged 16 commits into
masterfrom
chore/json-schemas

Conversation

@michael-smith-nz

@michael-smith-nz michael-smith-nz commented Aug 1, 2017

Copy link
Copy Markdown
Member

In this PR:

  • added docs to readme explaining json-schema and json-schema-faker
  • profile, taskPlan and taskRecipe json schema
  • profile story now uses json-faker for mock data (see gif below)
  • feathers hook for validating taskPlan and taskRecipe
  • tests for feathers validation
  • minor bug fixes that were blocking me

Not in this PR

  • schemas for models that are not being used by feathers (e.g taskWork)
  • dogstack auth schemas

mock-profile

closes #118

@michael-smith-nz michael-smith-nz changed the title chore(docs): add json schema info add type json-schemas for all data models Aug 1, 2017
Comment thread agents/components/Profile.js Outdated
}),
connectForm({
form: 'profile',
initialValues: {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, ideally we pass it in from here. i think we did something about this in #120, one sec.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahdinosaur Thanks! Added those lines (see below commit)

@michael-smith-nz michael-smith-nz self-assigned this Aug 3, 2017

const Ajv = require('ajv')
const { validateSchema } = require('feathers-hooks-common')
const schema = require('../schemas/taskPlan')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tasks/schemas/taskRecipe.json Outdated
"type": "object",
"properties": {
"id": {
"$ref": "#/id"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe this should be #/definitions/id?

Comment thread README.md
heroku run npm run db migrate:latest --app=cobuy
```

### JSON schema

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 yay docs 📔

@ahdinosaur ahdinosaur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

Comment thread agents/schemas/profile.json Outdated
"required": [
"id",
"agentId",
"name"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread agents/stories/Profile.js
avatar: 'http://dinosaur.is/images/mikey-small.jpg'
}
}
const profile = jsf(schema)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fk ya

"description": "Id referencing profile"
},
"agentId": {
"type": "integer",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet. 🍈

{
"id": "/tasks/taskPlan",
"title": "Task Plan",
"description": "An assignment of the task to an agent",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! thanks you.

Comment thread tasks/schemas/taskPlan.json Outdated
"description": "Id referencing task plan"
},
"parentTaskPlanID": {
"type": "integer",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be a $ref like taskRecipeId?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch

Comment thread tasks/services/plans.js Outdated
const Ajv = require('ajv')
const taskPlanSchema = require('../schemas/taskPlan')
const taskRecipeSchema = require('../schemas/taskRecipe')
const ajv = new Ajv({$data: true})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tasks/services/plans.js Outdated
all: [
// encodeParams
]
create: [validateSchema(taskPlanSchema, ajv), encodeParams],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very legit.

minor nit: maybe format for each hook to be on its own line.

Comment thread tasks/services/plans.js
assigneeId: hook.data.assigneeId,
taskRecipeId: childTaskRecipe.id,
params: hook.data.params
params: hook.result.params

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

@@ -0,0 +1,34 @@
import test from 'ava'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woo hoo tests 😊

@michael-smith-nz

Copy link
Copy Markdown
Member Author

@ahdinosaur Changes and rebase made ready for merge

@ahdinosaur ahdinosaur merged commit 114dc88 into master Aug 30, 2017
@ahdinosaur ahdinosaur removed the review label Aug 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add type json-schemas for all data models

2 participants