Как создать схему Swagger, которая включает в себя массив различных типов
Я пытаюсь определить определение схемы Swagger для объекта, который содержит массив объектов различных типов.
Вот схема json для объекта шаблона (и всех связанных типов объектов). Мне известно, что Swagger не поддерживает предикат oneOf, поэтому я просто пытаюсь понять, как описать эту структуру данных в Swagger. Я перепробовал много вариантов этого синтаксиса, но ни один из них не сработал, и это было самое близкое, что я мог бы сделать, основываясь на спецификации и некоторых примерах, найденных здесь:http://json-schema.org/example2.html
swagger: '2.0'
info:
version: 1.0.0
title: IDMU
paths:
definitions:
template:
type: object
properties:
collection:
type: string
name:
type: string
columnValue:
type: string
description:
type: string
outputFile:
type: string
content:
type: string
directives:
type: array
items:
type: object
oneOf:
-
$ref: '#/definitions/directiveRequire'
-
$ref: '#/definitions/directiveReplace'
-
$ref: '#/definitions/directiveReplaceRowSql'
-
$ref: '#/definitions/directiveReplaceRowCsv'
-
$ref: '#/definitions/directiveReplaceColSql'
-
$ref: '#/definitions/directiveReplaceColCsv'
-
$ref: '#/definitions/directiveInsertTag'
-
$ref: '#/definitions/directiveInsertCsv'
-
$ref: '#/definitions/directiveInsertSql'
providerCsv:
type: object
properties:
type:
type: integer
maximum: 3
minimum: 3
tag:
type: string
url:
type: string
staticData:
type: string
providerTag:
type: object
properties:
type:
type: integer
maximum: 2
minimum: 2
tag:
type: string
condition:
type: integer
list:
type: boolean
value:
type: string
providerSql:
type: object
properties:
type:
type: integer
maximum: 1
minimum: 1
source:
type: string
columns:
type: string
from:
type: string
where:
type: string
directive:
type: object
discriminator: type
properties:
type:
type: integer
softFail:
type: boolean
required:
- type
directiveRequire:
type: object
allOf:
- $ref: '#/definitions/directive'
- properties:
tags:
type: array
items:
type: string
directiveReplace:
type: object
allOf:
- $ref: '#/definitions/directive'
- properties:
description:
type: string
from:
type: string
to:
type: string
directiveReplaceRowSql:
type: object
allOf:
- $ref: '#/definitions/directive'
- properties:
description:
type: string
provider:
$ref: '#/definitions/providerSql'
directiveReplaceRowCsv:
type: object
allOf:
- $ref: '#/definitions/directive'
- properties:
description:
type: string
provider:
$ref: '#/definitions/providerCsv'
directiveReplaceColCsv:
type: object
allOf:
- $ref: '#/definitions/directive'
- properties:
description:
type: string
fromColumn:
type: string
toColumn:
type: string
provider:
$ref: '#/definitions/providerCsv'
directiveReplaceColSql:
type: object
allOf:
- $ref: '#/definitions/directive'
- properties:
description:
type: string
fromColumn:
type: string
toColumn:
type: string
provider:
$ref: '#/definitions/providerSql'
directiveInsertTag:
type: object
allOf:
- $ref: '#/definitions/directive'
- properties:
description:
type: string
notLast:
type: array
items:
type: string
onlyLast:
type: array
items:
type: string
provider:
$ref: '#/definitions/providerTag'
directiveInsertSql:
type: object
allOf:
- $ref: '#/definitions/directive'
- properties:
description:
type: string
notLast:
type: array
items:
type: string
onlyLast:
type: array
items:
type: string
provider:
$ref: '#/definitions/providerSql'
directiveInsertCsv:
type: object
allOf:
- $ref: '#/definitions/directive'
- properties:
description:
type: string
notLast:
type: array
items:
type: string
onlyLast:
type: array
items:
type: string
provider:
$ref: '#/definitions/providerCsv'