api - Post a json body with swagger -
i post json body swagger, :
curl -h "content-type: application/json" -x post -d {"username":"foobar","password":"xxxxxxxxxxxxxxxxx", "email": "foo@bar.com"}' http://localhost/user/register currently, have definition :
"/auth/register": { "post": { "tags": [ "auth" ], "summary": "create new user account", "parameters": [ { "name": "username", "in": "query", "description": "the username of user", "required": true, "type": "string" }, { "name": "password", "in": "query", "description": "the password of user", "required": true, "type": "string", "format": "password" }, { "name": "email", "in": "query", "description": "the email of user", "required": true, "type": "string", "format": "email" } ], "responses": { "201": { "description": "the user account has been created", "schema": { "$ref": "#/definitions/user" } }, "default": { "description": "unexpected error", "schema": { "$ref": "#/definitions/errors" } } } } } but data sent in url. here generated curl provided swagger :
curl -x post --header 'content-type: application/json' --header 'accept: application/json' 'http://localhost/user/register?username=foobar&password=password&email=foo%40bar.com' i understand query keywork not good, didn't find way post json body. tried formdata didn't work.
you need use body parameter:
"parameters": [ { "in": "body", "name": "body", "description": "pet object needs added store", "required": false, "schema": { "$ref": "#/definitions/pet" } } ], and #/definitions/pet defined model:
"pet": { "required": [ "name", "photourls" ], "properties": { "id": { "type": "integer", "format": "int64" }, "category": { "$ref": "#/definitions/category" }, "name": { "type": "string", "example": "doggie" }, "photourls": { "type": "array", "xml": { "name": "photourl", "wrapped": true }, "items": { "type": "string" } }, "tags": { "type": "array", "xml": { "name": "tag", "wrapped": true }, "items": { "$ref": "#/definitions/tag" } }, "status": { "type": "string", "description": "pet status in store", "enum": [ "available", "pending", "sold" ] } }, "xml": { "name": "pet" } }, openapi/swagger spec: https://github.com/oai/openapi-specification/blob/master/versions/2.0.md#parameter-object
Comments
Post a Comment