相关疑难解决方法(0)

对swagger 2.0上的模型的属性引用(嵌套)

我很难弄清楚如何在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

7
推荐指数
2
解决办法
1万
查看次数

Swagger 2.0:接受任何(复杂)JSON值的模式

我正在编写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)

api json swagger-2.0 openapi

4
推荐指数
1
解决办法
7791
查看次数

标签 统计

api ×1

json ×1

openapi ×1

swagger ×1

swagger-2.0 ×1