Jsonplaceholder: 嵌套资源正在返回所有资源

创建于 2019-01-10  ·  6评论  ·  资料来源: typicode/jsonplaceholder

https://jsonplaceholder.typicode.com/posts/1/comments调用 GET 时,将返回每个帖子的所有评论。 预期行为是只应返回 postId 为 1 的评论。 这发生在所有嵌套资源示例中。

bug help wanted

最有用的评论

你好,我会处理的,

所有6条评论

你好,我会处理的,

这个问题仍然存在。 这事有进一步更新吗?

@typicode我试图删除app.js中的_isFake选项并且嵌套资源正常工作。 我不知道 isFake 选项有什么作用,但我认为这需要在 json-server repo 中修复?

/** FROM */
const router = jsonServer.router(clone(data), { _isFake: true })
/** TO */
const router = jsonServer.router(clone(data))

@Riyenz你是对的。 我检查了 json-server 代码,发现路由器得到 2 个参数
module.exports = (db, opts = { foreignKeySuffix: 'Id', _isFake: false }) => {

然后在代码中

// Handle /:parent/:parentId/:resource router.use(nested(opts))

还发现了一个测试,其中涵盖了您在上面描述的情况

describe('GET /:parent/:parentId/:resource', () => { test('should respond with json and corresponding nested resources', () => request(server) .get('/posts/1/comments') .expect('Content-Type', /json/) .expect([db.comments[0], db.comments[1]]) .expect(200)) })

并且这个服务器作为参数传递给请求,它是在 beforeEach 方法中创建的,没有设置 _isFake 属性(默认设置为 false),当然,当我将 _isFake 设置为 true 作为参数时,测试已经通过jsonServer.router 方法测试失败并返回所有资源。

所以这个调查证明不是jsonplachelder过错。 这个 _isFake 属性是 7 个月前在 json-server 中引入的,也是 7 个月前 _isFake 属性被我错误地添加到 jsonplaceholder 但我不确定。

干杯

@类型代码

https://github.com/typicode/json-server/blob/8dd0b456ab313898f094c1e113f647425b2898a4/src/server/router/nested.js#L9

  // Rewrite URL (/:resource/:id/:nested -> /:nested) and request query

我认为这是 json-server 存储库中的设计,如果需要修复,应该在那里提出问题。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

antoniputra picture antoniputra  ·  3评论

vko-online picture vko-online  ·  7评论

andrasnemes picture andrasnemes  ·  4评论

rmat0n picture rmat0n  ·  7评论

adrianarodriguezgaona picture adrianarodriguezgaona  ·  10评论