在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中做同样的事情,但找不到解决方案。
发布于 2018-07-30 13:46:32
在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
您可以将类型定义分离到它自己的文件中并包含它。使用这里描述的任何技术: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
https://stackoverflow.com/questions/51591774
复制相似问题