Error when creating book using swagger & curl
ganjarsetia opened this issue · 3 comments
Required check list:
- I'm gonna mark the checkboxes like this.
- I didn't find in the repository's issues section similar bug.
- I understand, this is Open Source and not-for-profit product.
- 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:
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template!
👋 Hello. Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.
wave Hello. Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.
Yes. The problem already told in first thread. I dont know how to solve it