2017-03-23 21 views
0

我的簡單的swagger API文檔。參數不傳遞給我的控制器在執行職務,並把操作(Get和刪除操作進行微調)Swagger POST/PUT身體參數沒有傳遞到我的控制器

Swaggerjson文件:

"paths": {  
    "/api/AddEmployee": { 
     "post": { 
      "summary": "Add an Employee", 
      "description": "Adds a new Employee to the employees list.", 
      "consumes": [ 
       "application/x-www-form-urlencoded" 
      ], 
      "parameters": [ 
       { 
        "name": "body", 
        "in": "body", 
        "required": true, 
        "description": "An Employee to create.", 
        "schema": { 
         "$ref": "#/definitions/Employee" 
        } 
       } 
      ], 
      "responses": { 
       "200": { 
        "description": "Employee Added Sucessfully" 
       } 
      } 
     } 
    }, 
    "/api/UpdateEmployee": { 
     "post": { 
      "summary": "Update an Employee", 
      "description": "Updates an exist employee", 
      "consumes": [ 
       "application/x-www-form-urlencoded" 
      ], 
      "parameters": [ 
       { 
        "name": "body", 
        "in": "body", 
        "description": "An Employee to be updated.", 
        "schema": { 
         "$ref": "#/definitions/Employees" 
        } 

       } 
      ], 
      "responses": { 
       "200": { 
        "description": "Employee Added Sucessfully" 
       } 
      } 
     } 
    } 

}, 
"definitions": { 
    "Employees": { 
     "type": "object", 
     "properties": { 
      "EmpId": { 
       "type": "integer", 
       "format": "int32" 
      }, 
      "FirstName": { 
       "type": "string" 
      }, 
      "LastName": { 
       "type": "string" 
      }, 
      "age": { 
       "type": "integer" 
      } 
     } 
    }, 
    "Employee": { 
     "Type": "object", 
     "required": [ 
      "FirstName", 
      "LastName", 
      "age" 
     ], 
     "properties": { 
      "FirstName": { 
       "type": "string" 
      }, 
      "LastName": { 
       "type": "string" 
      }, 
      "age": { 
       "type": "integer" 
      } 
     } 
    } 

}

可以在這個問題上的任何一個導向。 TIA!

Controller Add and Update

Error Msg

+0

我想你使用WebApi?如果是這樣,你可以發佈你的控制器,行動和路線細節,你希望收到請求?問題可能在那裏。 –

+0

@PhilCooper更新,你現在可以檢查。 – k11k2

回答

0

大錯:

「消耗」:[ 「應用程序/ x WWW的形式進行了urlencoded」 ],

更改爲:

「消耗」:[ 「application/json」 ],