diff --git a/__tests__/server/schema-ignore.js b/__tests__/server/schema-ignore.js new file mode 100644 index 000000000..8c1959d6b --- /dev/null +++ b/__tests__/server/schema-ignore.js @@ -0,0 +1,28 @@ +const request = require('supertest') +const jsonServer = require('../../src/server') + +describe('$schema-ignore', () => { + let server + let router + let db + + beforeEach(() => { + db = { + $schema: 'http://some.schema.somewhere/', + } + + db.user = { + name: 'foo', + email: 'foo@example.com', + } + + server = jsonServer.create() + router = jsonServer.router(db) + server.use(jsonServer.defaults()) + server.use(router) + }) + + test('doesnt error with $schema node', () => { + return request(server).get('/user').expect(200, db.user) + }) +}) diff --git a/src/cli/run.js b/src/cli/run.js index 9c62594aa..c4238f473 100644 --- a/src/cli/run.js +++ b/src/cli/run.js @@ -15,6 +15,9 @@ function prettyPrint(argv, object, rules) { console.log() console.log(chalk.bold(' Resources')) for (const prop in object) { + // skip printing $schema nodes + if (prop === '$schema') continue + console.log(` ${root}/${prop}`) } diff --git a/src/server/router/index.js b/src/server/router/index.js index 8a246b1bc..6b59d8441 100644 --- a/src/server/router/index.js +++ b/src/server/router/index.js @@ -54,6 +54,11 @@ module.exports = (db, opts) => { // Create routes db.forEach((value, key) => { + if (key === '$schema') { + // ignore $schema + return + } + if (_.isPlainObject(value)) { router.use(`/${key}`, singular(db, key, opts)) return