swagger前后端使用说明

editor中yaml配置文件

swagger: '2.0'
info:
  description: '共1个接口'
  version: 1.0.0
  title: XXX接口
  license:
    name: springMVC前后端交互说明
    url: 'http://192.168.2.206/rdms-login-center/wmf/'
host: 192.168.2.206
tags:
  - name: XX系统
    description: '四种请求get/post/put/delete。Content-Type是两种类型application/json和multipart/form-data,在consumes中定义。返回类型都是application/json,produces中定义。入参类型有path/query/formData/body。'
schemes:
  - http
paths:
  /user/{id}:
    post:
      tags:
        - XX系统
      summary: '操作用户信息'
      description: 'multipart/form-data接口,multipart针对文件上传,非文件上传可以省略;后端接收参数时也可以直接用实体类作为入参'
      consumes:
        - multipart/form-data
      produces:
        - application/json
      parameters:
        - name: id
          in: path
          description: path参数,前端直接拼接到url后即可,后端对应springmvc的@PathVariable;required可以省略,描述是否必填项;type可以是array/boolean/integer/null/number/object/string
          required: true
          type: integer
        - name: name
          in: query
          description: query参数,前端用?拼接,后端对应@RequestParam
          type: string 
        - name: img
          in: formData
          description: formData参数,文件,配合consumes:- multipart/form-data,前端指定Content-Type:multipart/form-data,后端用@RequestParam("img") MultipartFile img接收文件参数,也可以接收数组@RequestParam("img") MultipartFile[] imgs
          type: file 
        - name: sex
          in: formData
          description: formData参数,基本属性,后端用@RequestParam接收参数
          type: string 
      responses:
        '200':
          description: 返回用户信息
          schema:
            $ref: '#/definitions/User'
        '201':
          description: '直接返回数组'  
          schema:
            type: array
            description: 信息数组
            items:
              $ref: '#/definitions/User'      
        '202':
          description: '分页查询返回'  
          schema:
            type: array
            description: 信息数组
            items:
              $ref: '#/definitions/PageObject' 
        '203':
          description: '自定义返回属性'  
          schema:
            type: object
            description: 接口异常返回对象
            properties:
              code:
                description: 0代表正常
                type: integer
        '500':
          description: 异常返回
          schema:
            $ref: '#/definitions/ErrorResponseBody'
  /man:
    put:
      tags:
        - XX系统
      summary: '操作用户信息'
      description: 'application/json接口;后端接收参数时也可以直接用实体类作为入参'
      produces:
        - application/json
      parameters:
        - name: body
          in: body
          required: true
          description: 'body参数,也可以直接引用实体schema:$ref: #/definitions/User;前端Content-Type:application/json,请求体放入json对象,js编写方式是JSON.stringify(obj)后端用@RequestBody接收 '
          schema:
            type: object
            properties:
              name:
                type: string
                description: 站点名称,必填
      responses:
        '200':
          description: 返回用户信息
          schema:
            $ref: '#/definitions/User'      
definitions:
  User:
    type: object
    description: 实体
    properties:
      id:
        description: 属性,type可以是array/boolean/integer/null/number/object/string
        type: integer
      imgList:
        type: array
        description: 数组,自定义属性
        items:
          type: object
          properties:
            stationId:
              description: id
              type: integer
      img1List:
        type: array
        description: $ref直接引用
        items:
          $ref: '#/definitions/User'   
  ErrorResponseBody:
      type: object
      description: 接口异常返回对象
      properties:
        code:
          description: 0代表正常
          type: integer
        message:
          description: 描述信息
          type: string
  PageObject:
      type: object
      description: 分页接口返回对象
      properties:
        content:
          description: 记录
          type: array
          items:
            type: object
        last:
          description: 是否最后一页
          type: boolean
        totalPages:
          type: integer 
          description: 总页数
        totalElements:
          type: boolean
          description: 总记录数 
        size:
          type: integer
          description: 分页大小   
        number:
          type: integer
          description: 当前页序号   
        sort:
          type: array
          description: 排序对象
          items:
            type: object 
            properties:
              direction:
                description: 排序类型asc/desc
                type: string
              property:
                description: 排序字段
                type: string
              ascending:
                description: 升序
                type: boolean 
        first:
          type: boolean
          description: 是否第一页

预览

这里写图片描述

下载

需要2积分,坑爹,我想免积分的,没积分的也可以联系我
http://download.csdn.net/download/wm5920/10123823

相关文章
相关标签/搜索