我正在为params
字段编写OpenAPI定义,它是一个对象,包含一个名为name
的字段,默认情况下它是字符串类型,但可以是任何类型,例如整数、数字、布尔值、字符串或字符串数组、布尔值、数字、整数。
参数:{ name: string: int | string | number | boolean | int[] | string[] | number[] | boolean[] }
如何在OpenAPI中定义这样的字段?
我尝试过以下几种方法
params:
description: Simple parameters map
type: object
additionalProperties:
name:
type: object
oneOf:
- type: string
- type: boolean
- type: integer
- type: number
- type: array
items:
- string
- integer
- number
- boolean
但这会产生以下语法错误:
不应包含其他属性名称。
发布于 2019-05-23 03:39:38
参数,它是一个对象,包括名为name的字段,默认情况下它是string类型,它可以是任何类型,如下所述:整数、数字、布尔字符串或字符串数组、布尔值、数字、整数。它可以是任何东西。
通过根本不指定type
来定义"Can be anything“。但在本例中,可能的"anything“值包括对象和对象数组,您没有提到它们。
params:
description: Simple parameters map
type: object
properties:
name: {}
# OR if you want to add a description, use
# name:
# description: Can be anything
但是,如果"anything“仅指您列出的特定类型,则需要anyOf
。请注意,OpenAPI3.0 (openapi: 3.0.0
)支持anyOf
,而OpenAPI2.0 (swagger: "2.0"
)不支持。
# openapi: 3.0.0
params:
type: object
properties:
name:
anyOf:
- type: string
- type: integer
- type: number
- type: boolean
- type: array
items:
type: string
- type: array
items:
type: integer
- type: array
items:
type: number
- type: array
items:
type: boolean
https://stackoverflow.com/questions/56186187
复制相似问题