在 RAML 中重用枚举定义

Reuse enum definition in RAML

在 Swagger/OpenAPI 3.0 中,是否可以重用枚举定义?

示例 - 共享颜色枚举定义:

openapi: 3.0.0
info:
  description: "This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters."
  version: "1.0.0"
  title: "Swagger Petstore"
  termsOfService: "http://swagger.io/terms/"
  contact:
    email: "apiteam@swagger.io"
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
paths:
  /products:
    get:
      parameters:
      - in: query
        name: color
        required: true
        schema:
          $ref: '#/components/schemas/Color'
      responses:
        '200':
          description: OK
  /products2:
    get:
      parameters:
      - in: query
        name: color
        required: true
        schema:
          $ref: '#/components/schemas/Color'
      responses:
        '200':
          description: OK
          
components:
  schemas:
    Color:
      type: string
      enum:
        - black
        - white
        - red
        - green
        - blue

我想在 RAML 中做同样的事情,但找不到解决方案。

在 RAML 1 中,您可以这样做:

#%RAML 1.0
title: Example API
version: v1
types:
  platform:
    enum:
      - win
      - mac
/installer:
  get:
    queryParameters:
      platform:
        type: platform
/foo:
  get:
    queryParameters:
      platform:
        type: platform

您可以将 type/s 定义分离到它自己的文件中并包含它。使用此处描述的任何技术:https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#modularization

此外,您可以定义一个带有查询参数的特征,以便在许多资源中重复使用。更多相关信息:https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#resource-types-and-traits