前后端交互的api文档,用swagger,yaml语法

自己随收写的一个,备忘用的,所以可能帮助不到别人;
得用notepad或者swagger按yml打开

openapi: 3.0.0
info:
title: api
description: ‘no more description’
version: 1.0.0
servers:

  • url: ‘http://localhost/’
    description: sth. null server url
    paths:
    /triplist:
    get:
    summary: Post a json type request to backend and get corresponding data
    responses:
    ‘200’:
    description: OK
    content:
    application/json:
    schema:
    $ref: ‘#/components/schemas/returnTriplist’
    example:
    [
    {
    “tripid”: “Tripid_1565768780784”,
    “startDate” : “1789555655342025”,
    “stopDate” : “1986666638203112”,
    “soundUrl”:“http://…”,
    “ball” : “String”
    },

    ]
    ‘401’:
    $ref: ‘#/components/responses/Unauthorized’ # <-----
    ‘404’:
    $ref: ‘#/components/responses/NotFound’ # <-----
    /candata:
    post:
    summary: Post a json type request to backend and get corresponding data
    requestBody:
    content:
    application/json:
    schema:
    $ref: ‘#/components/schemas/candata’
    example:
    {
    “tripid”:“Tripid_1565768780784”,
    “datatype”: “ESP_FRONT_WHEEL”,
    “startdate”: “1852369855342025”,
    “stopdate”: “1985314625348931”
    }
    responses:
    ‘200’:
    description: OK
    content:
    application/json:
    schema:
    $ref: ‘#/components/schemas/returnCandata’
    example:
    {
    “tripid”:“Tripid_1565768780784”,
    “startdate”:“1863286355342025”,
    “stopdate”:“1983472355348931”,
    “datatype” : “ESP_02_WheelAngle”,
    “data” :
    [
    {
    “timestamp”: “1893532812342025”,
    “value”: “123”
    },
    {
    “timestamp”: “1987231255342080”,
    “value”: “2342”
    },

    ]
    }
    ‘401’:
    $ref: ‘#/components/responses/Unauthorized’ # <-----
    ‘404’:
    $ref: ‘#/components/responses/NotFound’ # <-----
    /coordinatedata:
    post:
    summary: Post a json type request to backend and get corresponding data
    requestBody:
    content:
    application/json:
    schema:
    $ref: ‘#/components/schemas/coordinatedata’
    example:
    {
    “tripid”:“Tripid_1565768780784”,
    “startdate”: “1888289255342025”,
    “stopdate”: “1999289255342025”
    }
    responses:
    ‘200’:
    description: OK
    content:
    application/json:
    schema:
    $ref: ‘#/components/schemas/returnCoordinatedata’
    example:
    {“tripid”:“Tripid_1777768780784”,
    “data”:[
    {
    “timestamp” : “1932189255342025”,
    “path” : [lon1,lat1]
    },
    {
    “timestamp” : “2144349255342025”,
    “path” : [lon2,lat2]
    },

    ]
    }
    ‘401’:
    $ref: ‘#/components/responses/Unauthorized’ # <-----
    ‘404’:
    $ref: ‘#/components/responses/NotFound’ # <-----

components:
schemas:
returnTriplist:
type: array
items:
type: object
properties:
tripid:
type: string
startDate:
type: string
stopDate:
type: string
videoUrl:
type: string
vehicle:
type: string

candata:
  type: object
  properties:
    tripid:
      type: string
    datatype:
      type: string
    startdate:
      type: string
    stopdate:
      type: string
returnCandata:
  type: object
  properties:
    tripid:
      type: string
    startdate:
      type: string
    stopdate:
      type: string
    datatype:
      type: string
    data:
      items:
        type: object
        properties:
          timestamp:
            type: string
          value:
            type: string
        enum: [
                {
                  "timestamp":"7864689255342025",
                  "value":"123"
                },
                ...
              ]
      
coordinatedata:
  type: object
  properties:
    tripid:
      type: string
    startdate:
      type: string
    stopdate:
      type: string
returnCoordinatedata:
  type: object
  properties:
    tripid:
      type: string
    datatype:
      type: string
    data:
      type: array
      items:
        type: object
        properties:
          timestamp:
            type: string
            description: a timestamp
          path:
            type: array
            items:
              type: string
              description: longitude and latitude
              properties:
                lon: 
                  type: string
                  description: a longitude
                lat:
                  type: string
                  description: a latitude
        enum: [
                {
                  "timestamp":string,
                  "path":[lon,lat]
                },
                ...
              ]
        
Error:
  type: object
  properties:
    code:
      type: string
    message:
      type: string
  required:
    - code
    - message

responses:
NotFound:
description: The specified resource was not found
content:
application/json:
schema:
$ref: ‘#/components/schemas/Error’
Unauthorized:
description: Unauthorized
content:
application/json:
schema:
$ref: ‘#/components/schemas/Error’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值