-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add type json-schemas for all data models #124
Changes from all commits
18267d0
cc7920c
04db976
746e2d1
40a631e
382a1e2
34b0d70
18fdac0
e5f39bd
20abced
d6edc58
3dfe2d3
5edc378
382fc71
6e8febe
662ba60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"id": "agents/Profile", | ||
"title": "Profile", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "integer", | ||
"description": "Id referencing profile" | ||
}, | ||
"agentId": { | ||
"type": "integer", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be
oh wait nevermind, we don't have a schema for Agent. all good! |
||
"description": "Id referencing agent" | ||
}, | ||
"name": { | ||
"type": "string", | ||
"faker": "name.findName", | ||
"description": "An agent name" | ||
}, | ||
"description": { | ||
"type": "string", | ||
"description": "Agent biography" | ||
}, | ||
"avatar" : { | ||
"type": "string", | ||
"faker": "internet.avatar", | ||
"format": "uri", | ||
"description": "Agent avatar image link" | ||
} | ||
}, | ||
"required": [ | ||
"id", | ||
"agentId" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,17 @@ import React from 'react' | |
import { storiesOf } from '@storybook/react' | ||
import { action } from '@storybook/addon-actions' | ||
import { reduxForm, Field } from 'redux-form' | ||
import h from 'react-hyperscript' | ||
import jsf from 'json-schema-faker' | ||
|
||
import schema from '../schemas/profile' | ||
import Profile from '../components/Profile' | ||
|
||
const alice = { | ||
profile: { | ||
name: 'Alice', | ||
description: 'a cool cat', | ||
avatar: 'http://dinosaur.is/images/mikey-small.jpg' | ||
} | ||
} | ||
const profile = jsf(schema) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fk ya |
||
|
||
storiesOf('agents.Profile', module) | ||
.add('basic', () => ( | ||
<Profile agent={alice} /> | ||
h(Profile, { | ||
initialValues: profile | ||
}) | ||
)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const Ajv = require('ajv') | ||
const ajv = new Ajv() | ||
|
||
const taskPlanSchema = require('../tasks/schemas/taskPlan') | ||
const taskRecipeSchema = require('../tasks/schemas/taskRecipe') | ||
ajv.addSchema([ | ||
taskRecipeSchema, | ||
taskPlanSchema | ||
]) | ||
|
||
export default ajv |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"id": "/tasks/taskPlan", | ||
"title": "Task Plan", | ||
"description": "An assignment of the task to an agent", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! thanks you. |
||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"$ref": "#/definitions/id" | ||
}, | ||
"parentTaskPlanID": { | ||
"$ref": "#/definitions/id" | ||
}, | ||
"assigneeId": { | ||
"type": "integer", | ||
"description": "Person or group or related agents (e.g. admins) being assigned" | ||
}, | ||
"taskRecipeId": { | ||
"$ref": "/tasks/taskRecipe#/definitions/id", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sweet. 🍈 |
||
"description": "Task recipe that this taask plan is related to" | ||
}, | ||
"params": { | ||
"type": "object", | ||
"description": "Util paramaters" | ||
} | ||
}, | ||
"required": [ | ||
"assigneeId", | ||
"taskRecipeId" | ||
], | ||
"definitions": { | ||
"id": { | ||
"type": "integer", | ||
"description": "Id referencing task plan" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"id": "/tasks/taskRecipe", | ||
"title": "Task Recipe", | ||
"description": "An abstract description of the task", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"$ref": "#/definitions/id" | ||
}, | ||
"ownerAgentId": { | ||
"type": "integer", | ||
"description": "Id of the agent that owns the recipe" | ||
}, | ||
"childTaskRecipes": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"$ref": "#" | ||
} | ||
], | ||
"description": "Task recipes that make up this task recipe..." | ||
} | ||
}, | ||
"definitions": { | ||
"id": { | ||
"enum": [ | ||
"setupGroup", | ||
"setupSupplier", | ||
"finishPrereqs" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"id" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
const feathersKnex = require('feathers-knex') | ||
const { iff } = require('feathers-hooks-common') | ||
import { isEmpty, ifElse, is, assoc, prop, map, pipe, __ } from 'ramda' | ||
const { iff, validateSchema } = require('feathers-hooks-common') | ||
const taskPlanSchema = require('../schemas/taskPlan') | ||
import ajv from '../../app/schemas' | ||
import * as taskRecipes from '../../tasks/data/recipes' | ||
|
||
module.exports = function () { | ||
|
@@ -16,8 +18,17 @@ module.exports = function () { | |
|
||
const hooks = { | ||
before: { | ||
all: [ | ||
// encodeParams | ||
create: [ | ||
validateSchema(taskPlanSchema, ajv), | ||
encodeParams | ||
], | ||
update: [ | ||
validateSchema(taskPlanSchema, ajv), | ||
encodeParams | ||
], | ||
patch: [ | ||
validateSchema(taskPlanSchema, ajv), | ||
encodeParams | ||
] | ||
}, | ||
after: { | ||
|
@@ -46,11 +57,11 @@ function createChildTaskPlans (hook) { | |
parentTaskPlanId: hook.result.id, | ||
assigneeId: hook.data.assigneeId, | ||
taskRecipeId: childTaskRecipe.id, | ||
params: hook.data.params | ||
params: hook.result.params | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice catch |
||
}) | ||
}) | ||
) | ||
.then(() => hook) | ||
.then(() => hook) | ||
} | ||
|
||
const transformProp = transformer => propName => object => pipe( | ||
|
@@ -77,5 +88,4 @@ function decodeParams (hook) { | |
if (hook.result) { | ||
hook.result = transformPropMaybeArray(JSON.parse)('params')(hook.result) | ||
} | ||
return hook | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import test from 'ava' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. woo hoo tests 😊 |
||
import * as mock from '../data/mock' | ||
import ajv from '../../app/schemas' | ||
|
||
const { validateSchema } = require('feathers-hooks-common') | ||
const schema = require('../schemas/taskPlan') | ||
|
||
let hookBefore | ||
|
||
test.beforeEach(t => { | ||
hookBefore = { | ||
type: 'before', | ||
method: 'create', | ||
params: { provider: 'rest' }, | ||
data: mock.mockTaskPlans[1] | ||
} | ||
console.log(hookBefore.data) | ||
}) | ||
|
||
test('works with simple plan', (t) => { | ||
try { | ||
validateSchema(schema, ajv)(hookBefore) | ||
} catch (err) { | ||
if (err.errors) { | ||
console.log('validation errors: ', err.errors) | ||
} | ||
t.fail('validation failed unexpectedly') | ||
} | ||
t.pass('recipe was validated') | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 yay docs 📔