【发布时间】:2021-06-24 23:23:53
【问题描述】:
我有以下规格:
---
openapi: 3.0.0
info:
title: Players API
version: 0.0.1-alpha1
paths:
/players/{id}:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/PlayerWrapper'
components:
schemas:
PlayerWrapper:
type: object
properties:
display_name:
type: string
example: 76ers
config:
description: |
The configuration of the player.
example: { spec: { team: 76ers, names: [ 1, 2 ] } }
allOf:
- $ref: '#/components/schemas/Player'
Player:
type: object
properties:
spec:
allOf:
- $ref: '#/components/schemas/BasicPlayer'
additionalProperties: false
BasicPlayer:
type: object
properties:
team:
type: string
names:
allOf:
- $ref: '#/components/schemas/Names'
additionalProperties: false
Names:
type: array
items:
type: string
example: [ Ben, Joel ]
我确实在Swagger 上验证了它确实有效。问题是为什么我可以看到names: [ 1, 2 ] 而不是[ Ben, Joel ]。当我删除 example 的东西 (# example: { spec: { team: 76ers, names: [ 1, 2 ] } }) 时,我可以看到 Ben, Joel 示例:
有没有办法强制覆盖/合并这些示例?截至目前,我觉得我的示例被这些字段中的任何一个(即 76ers / [1, 2] 或 string / [Ben, Joel] 但我想得到 76ers / [Ben, Joel] 代替)。
【问题讨论】: