Swagger POST/PUT body 参数未传递到我的控制器
Swagger POST/PUT body parameters not passing to my controller
我简单的 swagger API 文档。执行 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 !
失误:
"consumes": [
"application/x-www-form-urlencoded"
],
更改为:
"consumes": [
"application/json"
],
我简单的 swagger API 文档。执行 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 !
失误:
"consumes": [ "application/x-www-form-urlencoded" ],
更改为:
"consumes": [ "application/json" ],