首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何重用RAML 1.0中的标头定义

如何重用RAML 1.0中的标头定义
EN

Stack Overflow用户
提问于 2017-04-07 08:37:11
回答 2查看 8.8K关注 0票数 1

我有一个RAML 1.0规范,其中我定义了多个资源。每个资源都有相同的标题集。

我需要使用RAML的哪些构造来一次声明头并在各种资源定义中重用它们?

例如:

代码语言:javascript
复制
/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

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-07 12:22:24

您可以使用traits

代码语言:javascript
复制
#%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
票数 1
EN

Stack Overflow用户

发布于 2017-04-07 16:41:55

特征必须表示一种行为,它是通过路线和动词来应用的。对于我来说,标头适用于任何路由/动词,您可以定义资源类型:

代码语言:javascript
复制
#%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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43273475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档