我很难弄清楚如何在swagger 2.0中嵌套模型.
目前我有:
SomeModel:
properties:
prop1:
type: string
prop2:
type: integer
prop3:
type:
$ref: OtherModel
OtherModel:
properties:
otherProp:
type: string
Run Code Online (Sandbox Code Playgroud)
我尝试了很多其他方法:
prop3:
$ref: OtherModel
# or
prop3:
schema:
$ref: OtherModel
# or
prop3:
type:
schema:
$ref: OtherModel
Run Code Online (Sandbox Code Playgroud)
以上都不适用.
但是,使用数组工作正常:
prop3:
type: array
items:
$ref: OtherModel
Run Code Online (Sandbox Code Playgroud) 我正在编写Swagger 2.0规范的API基本上是任何JSON值的存储.
我想要一个读取值的路径和一个存储非预定义深度的任何JSON值(null,数字,整数,字符串,对象,数组)的路径.
不幸的是,似乎Swagger 2.0对输入和输出的模式非常严格,并且不允许JSON Schema允许的整套模式.Swagger编辑器不允许使用示例混合值(例如,可以是布尔值或整数的属性)或松散定义的数组(必须严格定义项的类型)和对象.
所以我正在通过定义MixedValue架构来尝试解决方法:
---
swagger: '2.0'
info:
version: 0.0.1
title: Data store API
consumes:
- application/json
produces:
- application/json
paths:
/attributes/{attrId}/value:
parameters:
- name: attrId
in: path
type: string
required: true
get:
responses:
'200':
description: Successful.
schema:
$ref: '#/definitions/MixedValue'
put:
parameters:
- name: value
in: body
required: true
schema:
$ref: '#/definitions/MixedValue'
responses:
responses:
'201':
description: Successful.
definitions:
MixedValue:
type: object
properties:
type:
type: string
enum:
- 'null'
- boolean
- number
- integer
- …Run Code Online (Sandbox Code Playgroud)