vapor/vapor

template error

sinduke opened this issue · 4 comments

Describe the bug

I created a new project using vapor new and ran it directly without modifying anything to create todos
The error that comes up is:
"reason": "Value required for key at path 'id'. No value associated with key "id"."

I use
struct CreateTodoData: Content {
let title: String
}
When using CreateTodoData.self instead of Todo.self in req.content.decode(), it can be created normally. It is obvious that something went wrong when using the model directly. I used the project created by vapor new and did not modify other You can test the contents of

vzsg commented

How did you test the request?

image

This is use struct CreateTodoData: Content Still can't use Todo.self
vzsg commented

I can't seem to reproduce your issue. In a freshly cloned template with postgres, after adding autoMigrate to create the table easily, the following request worked just fine in Postman:

image

As unfortunately I can't read Chinese, especially not on screenshots, I can't tell what that client is and what's misconfigured... Be sure that you're sending the Content-Type: application/json header with the request. In my case, it's added automatically as I selected a raw body and JSON (in blue).