swagger-api / swagger-petstore

http://petstore.swagger.io
Apache License 2.0
246 stars 349 forks source link

create pet shows 500 error when I am running the process locally #40

Open fabiandelgadop3112 opened 3 years ago

fabiandelgadop3112 commented 3 years ago

Hi, I'm running the process localy on http://localhost:8080/api/v3/openapi.json but when i want to create a new pet in the store, the response shows:

{ "code": 500, "message": "There was an error processing your request. It has been logged (ID: cc7b40b0becf48c4)" }

My request is:

{ "id": 0, "name": "Nalita", "category": { "id": 1, "name": "Dogs" }, "photoUrls": [ "https://cdn.pixabay.com/photo/2017/09/25/13/12/dog-2785074__340.jpg" ], "tags": [ { "id": 0, "name": "DogoArgentino" } ], "status": "available" }

Here is a sample image in postman:

image

pd: for the create user method, happens the same

Regards

fabiandelgadop3112 commented 3 years ago

I change de order of the request like the example in the collection a int works, if i use the request of the swagger UI, it doesnt work.

here the correct request:

{ "id": 10, "category": { "id": 1, "name": "Dogs" }, "name": "doggie", "photoUrls": [ "string" ], "tags": [ { "id": 0, "name": "string" } ], "status": "available" }

clebio commented 3 years ago

I too ran into this. It's unclear to me why id is required, given that the spec doesn't seem to say that:

$ curl -s http://localhost:8080/api/v3/openapi.json | jq '.components.schemas.Pet.required'
[
  "name",
  "photoUrls"
]

but that seems to be the case:

$ curl -X POST "http://localhost:8080/api/v3/pet" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"id\":3,\"name\":\"rocky\",\"photoUrls\":[]}"
{"id":3,"name":"rocky","photoUrls":[],"tags":[]}

vs

$ curl -X POST "http://localhost:8080/api/v3/pet" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"name\":\"rocky barkboa\",\"photoUrls\":[]}"
{"code":500,"message":"There was an error processing your request. It has been logged (ID: 8e9a5d3300d2ee71)"

Thus, minimal valid POST/pet body:

{
  "id": -1,
  "name": "",
  "photoUrls": []
}

I'm running the mainline branch:

$ git remote -v
origin  git@github.com:swagger-api/swagger-petstore.git (fetch)
origin  git@github.com:swagger-api/swagger-petstore.git (push)

$ git branch
* master

$ mvn package jetty:run