http - Swagger 无法识别 x-www-urleconded 参数
问题描述
我有一个关于 2.0 版的招摇文档,我将路径消耗为application/x-www-urlencoded但是当我尝试请求时,我收到以下错误。
{
"message": "Request validation failed: Parameter (username) is required",
"code": "REQUIRED",
"failedValidation": true,
"path": [
"paths",
"/auth/login",
"post",
"parameters",
"0"
],
"paramName": "username"
}
但是我已经传递了参数,正如我们在这个 curl 上看到的那样
curl -X POST \
http://localhost:10010/v1/auth/login \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'username=LOGIN&password=MYPASS&userType=employee'
我使用了以下 Swagger.yaml
这是你的定义。
definitions:
UserType: &UserType
type: string
enum: [customer, employee, supplier]
description: >
User Type:
* customer.
* employee.
* supplier.
这里是使用的路径。
paths:
/auth/login:
# binds a127 app logic to a route
x-swagger-router-controller: "authentication"
x-a127-apply: {}
post:
summary: Try to login
description: Try to login with credencials based on username/password. This API will return all "habitant" information if login were successful.
# used as the method name of the controller
operationId: login
consumes:
- application/x-www-form-urlencoded
tags:
- Auth
parameters:
- name: username
in: formData
description: Username to login.
required: true
type: string
- name: password
in: formData
description: Password to login.
required: true
type: string
format: password
- name: userType
in: formData
required: true
default: customer
<<: *UserType
responses:
"200":
description: Success. If there are attributes with empty values they won´t be returned
schema:
# a pointer to a definition
$ref: "#/definitions/AuthResponse"
"401":
description: Unauthorized
schema:
$ref: "#/definitions/ErrorResponse"
"500":
description: Internal Server Error
schema:
$ref: "#/definitions/ErrorResponse"
"501":
description: Not Implemented
schema:
$ref: "#/definitions/ErrorResponse"
谢谢你的帮助。
解决方案
我认为这可能与您的中间件有关。你用快递吗?
如果是这样,您可以添加类似“app.use(express.urlencoded());”的内容
你应该看看这个链接:
推荐阅读
- c++ - 重新实现第 3 方非虚拟功能
- html - 我的形象没有成为部门的一部分,但上形象正在成为?
- c++ - 如何在 C++ 中检查数组是否用零填充
- awk - 如何保留文件 B 中 L(B) 列对应值大于文件 A 列 L(A) 对应值的行?
- javascript - 如何在 SlickGrid 中合并行
- c++ - 编译适用于大多数 Windows 操作系统版本的 pybind11 python 模块
- javascript - 在按钮单击时对 vuetify 简单表进行排序
- r - 如何在 R 中将 8GB WAVE 文件(持续 24 小时)拆分为更小的文件(持续 1 小时)?
- reactjs - 将按钮 ID 设置为单击时的状态
- swift - 简单的编辑画面