我在 swagger 之上使用 Apigee 127 来创建 REST API。
这是配置文件的头swagger.yaml
:
swagger: 2.0
info:
version: "0.0.1"
title: LMS API Gateway
# during dev, should point to your local machine
host: localhost
# basePath prefixes all resource paths
basePath: /
#
schemes:
# tip: remove http to make production-grade
- http
- https
# format of bodies a client can send (Content-Type)
consumes:
- application/json
# format of the responses to the client (Accepts)
produces:
- application/json
x-a127-config: {}
x-volos-resources: {}
paths:
/lms/oauth2/token:
# binds a127 app logic to a route
x-swagger-router-controller: authentication
x-volos-authorizations: {}
x-volos-apply: {}
post:
description: Authenticates a user
operationId: authenticate
parameters:
- name: body
in: body
description: The JSON request body
required: true
schema:
$ref: AuthenticationRequest
responses:
"200":
description: Success
schema:
$ref: AuthenticationResponseSuccess
default:
description: Error
schema:
$ref: AuthenticationResponseError
然后我有这个AuthenticationRequest
模式对象,它描述了身份验证的请求正文应该是怎样的。到目前为止,一切都很好。
当我提出有效请求时,它工作正常,但是当我提出无效请求时,我得到以下响应:
HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 60
Date: Mon, 06 Oct 2014 16:31:08 GMT
Connection: keep-alive
Parameter (body) is not a valid AuthenticationRequest model
如果我的 API 规范没有指定我必须400 Bad Request
为无效请求返回响应代码(顺便说一句,这更有意义),那将没有问题。
所以问题是我在 Swagger 文档中找不到改变这种行为的方法。
任何人?