27

次のように、Swagger を使用して JSON 本体を POST したいと思います。

curl -H "Content-Type: application/json" -X POST -d {"username":"foobar","password":"xxxxxxxxxxxxxxxxx", "email": "foo@bar.com"}' http://localhost/user/register

現在、私はこの定義を持っています:

"/auth/register": {
        "post": {
            "tags": [
              "auth"
            ],
            "summary": "Create a new user account",
            "parameters": [
                {
                    "name": "username",
                    "in": "query",
                    "description": "The username of the user",
                    "required": true,
                    "type": "string"
                },
                {
                    "name": "password",
                    "in": "query",
                    "description": "The password of the user",
                    "required": true,
                    "type": "string",
                    "format": "password"
                },
                {
                    "name": "email",
                    "in": "query",
                    "description": "The email of the 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"
                    }
                }
            }
        }
    } 

ただし、データは URL で送信されます。Swagger によって生成された curl は次のとおりです。

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' 'http://localhost/user/register?username=foobar&password=password&email=foo%40bar.com'

キーワークが良くないことは理解してqueryいますが、JSON 本文を POST する方法が見つかりませんでした。試してみformDataましたが、うまくいきませんでした。

4

1 に答える 1