我简单的swagger API文档。在执行post和put操作时,参数没有传递给我的控制器。(Get和Delete操作执行正常)
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!
答案 0 :(得分:0)
大错:
"消费":[ "应用程序/ X WWW的窗体-urlencoded" ],
更改为:
"消费":[ "应用/ JSON" ],