Javascript 当存在验证错误时,为什么swagger codegen生成返回状态200的代码
我使用swagger codegen用javascript构建了一个服务api。当调用工作时,它返回自定义定义的类型和状态200,但当出现验证错误时,它返回错误,但也返回状态200 例如:Javascript 当存在验证错误时,为什么swagger codegen生成返回状态200的代码,javascript,node.js,swagger,swagger-codegen,Javascript,Node.js,Swagger,Swagger Codegen,我使用swagger codegen用javascript构建了一个服务api。当调用工作时,它返回自定义定义的类型和状态200,但当出现验证错误时,它返回错误,但也返回状态200 例如: { "message": "Request validation failed: Parameter (model) is required", "code": "REQUIRED", "failedValidation": true, "path": [ "paths",
{
"message": "Request validation failed: Parameter (model) is required",
"code": "REQUIRED",
"failedValidation": true,
"path": [
"paths",
"/make/ford",
"get",
"parameters",
"0"
],
"paramName": "model"
}
我希望它返回状态代码400,因为my swagger.yml只将用户定义的类型指定为响应。如何使生成的代码返回验证错误的状态400
端点描述如下(部分文件):
注意:AWS API Gateway不支持默认响应,因此我可以去掉它。如何在swagger.yaml中定义响应?你能包括那部分吗?我更新了我的问题验证结果(
false
)本身就是一个有效的结果。输入有什么问题并不重要——服务器确实生成了正确的结果,没有任何服务器端错误。但是swagger只允许我为200状态代码定义一种类型。Swagger不支持类似JSON模式的
/make/ford:
x-swagger-router-controller: controller
get:
description: Description
operationId: get_car
parameters:
- name: model
in: query
description: Model
required: true
type: array
items:
type: string
responses:
"200":
description: Success
schema:
$ref: "#/definitions/ModelResponse"
# responses may fall through to errors
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
definitions:
ModelResponse:
properties:
options:
type: array
items:
type: string
ErrorResponse:
required:
- message
properties:
message:
type: string