Skip to content
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

ignore $schema definition #1324

Merged
merged 3 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions __tests__/server/schema-ignore.js
Original file line number Diff line number Diff line change
@@ -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: '[email protected]',
}

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)
})
})
3 changes: 3 additions & 0 deletions src/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}

Expand Down
5 changes: 5 additions & 0 deletions src/server/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down