我需要定义一个响应标头参数,该参数对于RAML API中的所有2xx响应代码都是通用的。
我只找到了一种为每个HTTP代码定义参数的方法,如下所示:
responses:
200:
headers:
X-Transaction-Id:
type: string
但是我需要做这样的事情:
responses:
[200-300):
headers:
X-Transaction-Id:
type: string
有什么帮助吗?
答案 0 :(得分:0)
不能那样做。您需要分别声明每个状态代码。
答案 1 :(得分:-1)
为什么不尝试将其实现为库中的资源类型。
#%RAML 1.0 Library
usage: |
All common response types...
types:
common-response:
type: object
properties:
key1: string
key2: string
resourceTypes:
common_response_types:
description: Common response types for API
get?:
responses:
200:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
201:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
300:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
post?:
responses:
200:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
201:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
300:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
patch?:
responses:
200:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
201:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
300:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
delete?:
responses:
200:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
201:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
300:
body:
application/json:
type: common-response
example: !include examples/example-response.raml
您可以使用它来调用它。
uses:
common_responses: libraries/common-responses.raml
/getuser:
type: common_responses.common_response_types