闊歩

2016-02-15 13 views
14

とポストJSONボディ私はこのように、闊歩してJSON本体をPOSTしたいと思います:闊歩

curl -H "Content-Type: application/json" -X POST -d {"username":"foobar","password":"xxxxxxxxxxxxxxxxx", "email": "[email protected]"}' 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。ここで生成されたカール闊歩提供:

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 keyworkが良くないことを理解し、私はJSON本体を投稿する方法を見つけることができませんでした。私はformDataを試しましたが、動作しませんでした。あなたはbodyパラメータを使用する必要があります

答えて

29

"parameters": [ 
     { 
     "in": "body", 
     "name": "body", 
     "description": "Pet object that needs to be added to the store", 
     "required": false, 
     "schema": { 
      "$ref": "#/definitions/Pet" 
     } 
     } 
    ], 

#/definitions/Petは、モデルのように定義されます。

"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 the store", 
     "enum": [ 
     "available", 
     "pending", 
     "sold" 
     ] 
    } 
    }, 
    "xml": { 
    "name": "Pet" 
    } 
}, 

参考:https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.json#L81

OpenAPIの/闊歩仕様:https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object

+0

それは完璧です、ありがとう! – ncrocfer

+0

laravel-5.5でモデルを作成するには? –

関連する問題