app开发定制Swagger yaml定义Restful API那些事(持续更新)

一、复杂模型

1、Value是一个Map<String, Map<String, String>>结构

嵌套Mapapp开发定制的数据结构,如下示意

"translations": {  "zh-CN": {    "hello.world": "你好,世界"    "hello.earth": "你好,地球"    "hello.mars": "你好,火星"  },  "en-US": {    "hello.world": "Hello World"    "hello.earth": "hello earth"    "hello.mars": "hello mars"  }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

yaml定义如下:

BaseModel:  type: object  discriminator: name  properties:    translations:        $ref: '#/definitions/Translate'        Translate:  additionalProperties:    $ref: '#/definitions/TranslateItem'TranslateItem:  additionalProperties:    type: string
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

解释:

additionalProperties用于表示Map里面Value值的类型。

二、枚举相关

1、 yaml定义字符串的有效值范围,可以如下animal方式

2、如果定义一个属性的值就是一个枚举类型,可以用beasts方式

definitions:  MyLoves:    type: object    properties:      animal:        type: string        enum:          - "dog"          - "cat"      beasts:        $ref: '#/definitions/Beasts'  Beasts:    enum:      - "donkey"      - "pig"    type: string    x-ms-enum:      name: Beasts      modelAsString: true
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发