Api 如何在RAML 1.0中重用头定义
我有一个RAML 1.0规范,其中定义了多个资源。每个资源都有相同的标题集 我需要使用什么RAML结构来一次性声明头并在各种资源定义中重用它们 例如Api 如何在RAML 1.0中重用头定义,api,http-headers,raml,Api,Http Headers,Raml,我有一个RAML 1.0规范,其中定义了多个资源。每个资源都有相同的标题集 我需要使用什么RAML结构来一次性声明头并在各种资源定义中重用它们 例如 /read/records: post: description: api for reading records queryParameters: table_name: string headers: Authorization: displa
/read/records:
post:
description: api for reading records
queryParameters:
table_name: string
headers:
Authorization:
displayName: Authorization
description: Basic authentication base 64 encoded string
type: string
required: true
Tenant-Id:
displayName: Tenant-Id
description: Tenant id for multi-tenant environments
type: string
required: true
Content-type:
displayName: Content-type
description: either xml or json
type: string
required: true
/adjust/records:
post:
description: api for editing records
headers:
Authorization:
displayName: Authorization
description: Basic authentication base 64 encoded string
type: string
required: true
Tenant-Id:
displayName: Tenant-Id
description: Tenant id for multi-tenant environments
type: string
required: true
Content-type:
displayName: Content-type
description: either xml or json
type: string
required: true
谢谢 您可以使用:
#%RAML 1.0
traits:
hasHeaders:
headers:
Authorization:
displayName: Authorization
description: Basic authentication base 64 encoded string
type: string
required: true
Tenant-Id:
displayName: Tenant-Id
description: Tenant id for multi-tenant environments
type: string
required: true
Content-type:
displayName: Content-type
description: either xml or json
type: string
required: true
/read/records:
post:
is: ["hasHeaders"]
description: api for reading records
queryParameters:
table_name: string
/adjust/records:
post:
is: ["hasHeaders"]
description: api for editing records
特质必须表征一种行为,并通过路径和动词加以应用。对于我来说,标题适用于任何路由/动词,您可以定义资源类型:
#%RAML 1.0 ResourceType
get?:
headers:
Authorization:
displayName: Authorization
description: Basic authentication base 64 encoded string
type: string
required: true
Tenant-Id:
displayName: Tenant-Id
description: Tenant id for multi-tenant environments
type: string
required: true
Content-type:
displayName: Content-type
description: either xml or json
type: string
required: true
post?:
headers:
Authorization:
displayName: Authorization
description: Basic authentication base 64 encoded string
type: string
required: true
Tenant-Id:
displayName: Tenant-Id
description: Tenant id for multi-tenant environments
type: string
required: true
Content-type:
displayName: Content-type
description: either xml or json
type: string
required: true
太神了这只不过是一个小小的改变。我不必为hashheader提供[]。它只与is:hasHeaders一起工作。还有别的需要吗?“是”结构表示什么?trait是否也适用于一般性地声明查询参数?“Is”表示在何处应用trait。当它是唯一一个没有“[]”就可以使用的。可以对资源+动词应用多个特征,在这种情况下,可以使用数组“[]”。