swagger的yaml常用配置示例

1、配置无需传参的get接口(返回json)

/dwSubjectType/findAll:
   get:
     tags:
     - "损益报表开发"
     summary: "获取科目维度列表"
     description: ""
     operationId: ""
     produces:
     - "application/json"
     responses:
       200:
         description: "操作成功"
         schema:
           $ref: "#/definitions/DwSubjectType"

其中DwSubjectType为定义的对象,如下:

definitions:
 DwSubjectType:
   type: "object"
   description: "科目列表使用"
   properties:
     code:
       type: "integer"
       format: "int64"
       description: "操作结果成功失败标识(0:成功,非0:失败)"
     message:
       type: "string"
       format: "string"
       description: "操作结果描述"
     object1:
       type: "object"
       format: "object"
       properties:
         subject_CODE:
           type: "integer"
           format: "integer"
           description: "科目编号"
         data_ADJUSTMENT_FLG:
           type: "string"
           format: "string"
           description: "是否可调整(N:否,Y:是)"
         display_SUBJECTS_LV1:
           type: "string"
           format: "string"
           description: "二级科目标题"
         display_SUBJECTS_LV2:
           type: "string"
           format: "string"
           description: "一级科目标题"
         display_SUBJECTS_LV3:
           type: "string"
           format: "string"
           description: "三级科目标题"

2、配置参数的post提交接口(参数无json字符串)

 /dmAccDataAdjustment/add:
   get:
     tags:
     - "页面添加损益调整信息"
     summary: ""
     description: ""
     operationId: ""
     consumes:
     - "application/form-data"
     parameters:
     - name: "RES_CENTER_LV5_CODE"
       in: "query"
       description: "第五级成本中心编号"
       required: true
       type: "integer"
     - name: "Edition"
       in: "query"
       description: "调整的版本(精准版/预估版)"
       required: true
       type: "string"
     - name: "YEAR"
       in: "query"
       description: "调整的年份"
       required: true
       type: "string"
     produces:
     - "application/json"
     responses:
       200:
         description: "xx"
         schema:
           $ref: "#/definitions/DwSubjectType"

3、配置参数的post提交json参数

/dmAccDataAdjustment/testJson:
   post:
     tags:
     - "测试参数为json"
     description: ""
     operationId: ""
     consumes:
     - "application/json"
     parameters:
       - name: "strs"
         in: "body"
         description: "填入的数值(格式具体参考)"
         required: true
         schema:
           $ref: "#/definitions/jsonArray1"
     produces:
     - "application/json"
     responses:
       200:
         description: "成功"
         schema:
           $ref: "#/definitions/jsonArray1"

注意:这种方式接口参数类型和上面的会不一样,需要使用:

@RequestBody String json

转载于:https://my.oschina.net/puguole/blog/2993578

你可能感兴趣的:(swagger的yaml常用配置示例)