Required check list:
- [x] I'm gonna mark the checkboxes like this.
- [x] I didn't find in the repository's issues section similar bug.
- [x] I understand, this is Open Source and not-for-profit product.
- [x] This is not about third-party project, framework, package or technology.
My environment:
- OS (
uname -a
): Linux 89327648a97a 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 Linux (inside docker)
- Golang (
go version
): go version go1.18.3 linux/amd64
Describe the bug:
I followed your article & successfully run it. But when I tried to test the create book API, it fail. I tried using Swagger, it still the same. Do you have any sample JSON for create book ?
Steps to reproduce the behavior:
- Run the app like shown in readme & run the migration. Make sure no records in DB.
- Generate token & copy the token using swagger or
curl -X 'GET' 'http://127.0.0.1:5000/api/v1/token/new' -H 'accept: application/json'
- Put the token at swagger. By click "Authorize" button on top right. Fill with
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTczMDIzNzF9.0VJubL5Z_49W2-9BHvqQaFn2pN1TxkysFIvzb5SpUow

- Try Swagger POST /v1/book by clicking Try It Out & fill Title, Author, etc.

- Click Execute
- See error

I tried to change the JSON, it still error, you can try this curl
curl -X 'POST' \
'http://127.0.0.1:5000/api/v1/book' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTcyOTc2NzN9.fCjWNsiCVoUecjY1fhKNB_zHrZWS3SQohTeese5HdqM' \
-H 'Content-Type: application/json' \
-d '{
"author": "Michael Crichton",
"book_attrs": {
"description": "A cautionary tale about genetic engineering",
"picture": "https://upload.wikimedia.org/wikipedia/en/3/33/Jurassicpark.jpg",
"rating": 8
},
"title": "Jurassic Park"
}
And it show error
{"error":true,"msg":{"ID":"Key: 'Book.ID' Error:Field validation for 'ID' failed on the 'uuid' tag","UserID":"Key: 'Book.UserID' Error:Field validation for 'UserID' failed on the 'uuid' tag"}}
Expected behavior:
Successfully create book
Screenshots:
