相关链接

编辑器:https://editor.swagger.io/

文档:https://openapi.apifox.cn/

基础信息设置

openapi: 3.0.3
info:
title: 后端服务接口
description: |-
## 描述
由萌狼蓝天创建 ## 相关介绍
`terOfServer`:服务隐私条款 ## 相关连接 termsOfService: https://mllt.cc
contact:
email: mllt9920@qq.com
license:
name: Apache 2.0
url: https://mllt.cc
version: 1.0.0
externalDocs:
description: 萌狼蓝天的博客园
url: https://cnblogs.com/mllt servers:
- url: https://api.mllt.cc/api/v2024

一个简单的例子

openapi: 3.0.3
info:
title: 后端服务接口
description: |-
## 描述
由萌狼蓝天创建 ## 相关介绍
`terOfServer`:服务隐私条款 ## 相关连接 termsOfService: https://mllt.cc
contact:
email: mllt9920@qq.com
license:
name: Apache 2.0
url: https://mllt.cc
version: 1.0.0
externalDocs:
description: 萌狼蓝天的博客园
url: https://cnblogs.com/mllt servers:
- url: https://api.mllt.cc/api/v2024 tags:
- name: user
description: 用户相关接口
externalDocs:
description: 接口地址
url: https://api.mllt.cc/api/user paths:
/user/get:
get:
tags:
- 用户列表
summary: 所有用户
description: 获取所有的用户信息
responses:
'200':
description: 成功获取所有的用户
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: 获取失败,请检查前端
'500':
description: 获取失败,请检查后端
'404':
description: 获取失败,请检查后端是否正常运行,是否存在跨域问题
/user/add:
post:
tags:
- 用户新增
summary: 新增用户
description: 新增一个用户
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'200':
description: 成功新增用户
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: 失败,请检查前端
'500':
description: 失败,请检查后端
'404':
description: 失败,请检查后端是否正常运行,是否存在跨域问题 components:
schemas:
User:
type: object
properties:
id:
type: integer
format: int64
example: 10
username:
type: string
example: 萌狼蓝天
firstName:
type: string
example: 萌狼
lastName:
type: string
example: 蓝天
email:
type: string
example: mllt9920@qq.com
password:
type: string
example: '123456'
phone:
type: string
example: '13140209920'
userStatus:
type: integer
description: User Status
format: int32
example: 1
xml:
name: user
requestBodies:
User:
description: User对象
content:
application/json:
schema:
$ref: '#/components/schemas/User'
application/xml:
schema:
$ref: '#/components/schemas/User'
UserArray:
description: List of user object
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'

借助工具

我个人爱用apifox

apifox支持导出openapi(swagger)-json格式的文件

可以用在线工具转为yaml格式(例如:https://json2yaml.com/)

但是转换后可能会因为有一些地方有问题

比如说没设置字段type的,为null的时候,就会出问题

如果想用工具来写的话,我个人认为应该尽可能的去完整、规范的填写

看一看转后的效果

openapi: 3.0.0
info:
title: server-system
description: ''
version: 1.0.0
tags:
- name: 用户相关
- name: 资讯相关
paths:
"/users":
get:
summary: 用户_查询_全部
x-apifox-folder: 用户相关
x-apifox-status: developing
deprecated: false
description: 查询全部用户
tags:
- 用户相关
parameters: []
responses:
'200':
description: 成功
content:
application/json:
schema:
type: array
items:
type: object
properties:
userId:
type: integer
userNickname:
type: string
userAccount:
type: string
userPassword:
type: string
userRegTime:
type: string
userLastLoginTime:
type: string
userStatus:
type: integer
userIdentity:
type: string
remarks:
type: string
required:
- userId
- userNickname
- userAccount
- userPassword
- userRegTime
- userLastLoginTime
- userStatus
- userIdentity
- remarks
x-apifox-orders:
- userId
- userNickname
- userAccount
- userPassword
- userRegTime
- userLastLoginTime
- userStatus
- userIdentity
- remarks
x-apifox-ignore-properties: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-144831280-run
security: []
post:
summary: 用户_新增
x-apifox-folder: 用户相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 用户相关
parameters: []
requestBody:
content:
application/json:
schema:
type: object
properties:
userNickname:
type: string
description: 用户昵称
userAccount:
type: string
description: 用户账号
userPassword:
type: string
description: 用户密码
userIdentity:
type: string
description: 用户身份
remarks:
type: string
description: 备注
required:
- userNickname
- userAccount
- userPassword
- remarks
- userIdentity
x-apifox-orders:
- userNickname
- userAccount
- userPassword
- userIdentity
- remarks
x-apifox-ignore-properties: []
example:
userNickname: JohnDoe
userAccount: johndoe123
userPassword: password123
userIdentity: 测试员
remarks: 测试用户
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-144847680-run
security: []
put:
summary: 用户_更新
x-apifox-folder: 用户相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 用户相关
parameters: []
requestBody:
content:
application/json:
schema:
type: object
properties:
userNickname:
type: string
description: 用户昵称
userPassword:
type: string
description: 用户密码
userIdentity:
type: string
description: 用户身份
remarks:
type: string
description: 备注
userStatus:
type: string
description: 用户状态
userId:
type: string
description: 用户ID
userLoginTime:
type: string
required:
- userId
x-apifox-orders:
- userNickname
- userPassword
- userIdentity
- remarks
- userStatus
- userId
- userLoginTime
x-apifox-ignore-properties: []
example:
userNickname: JohnDoe
userAccount: johndoe123
userPassword: password123
userIdentity: 测试员
remarks: 测试用户
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-144895492-run
security: []
"/users/6":
get:
summary: 用户_查询_根据ID
x-apifox-folder: 用户相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 用户相关
parameters: []
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-144872718-run
security: []
"/users/4":
delete:
summary: 用户_删除_根据ID
x-apifox-folder: 用户相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 用户相关
parameters: []
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-144891769-run
security: []
"/users/login":
post:
summary: 用户_登录
x-apifox-folder: 用户相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 用户相关
parameters:
- name: userAccount
in: query
description: ''
required: false
example: wenjun
schema:
type: string
- name: userPassword
in: query
description: ''
required: false
example: '123456'
schema:
type: string
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-144929527-run
security: []
"/informationTable/all":
get:
summary: 资讯_查询_全部
x-apifox-folder: 资讯相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 资讯相关
parameters: []
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-145428475-run
security: []
"/informationTable/add":
post:
summary: 资讯_新增
x-apifox-folder: 资讯相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 资讯相关
parameters: []
requestBody:
content:
application/json:
schema:
type: object
properties:
title:
type: string
content:
type: string
type:
type: string
attachments:
type: string
creator:
type: string
x-apifox-orders:
- title
- content
- type
- attachments
- creator
required:
- title
- content
- creator
- attachments
- type
x-apifox-ignore-properties: []
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-145430645-run
security: []
"/informationTable/get/1":
get:
summary: 资讯_查询_根据ID
x-apifox-folder: 资讯相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 资讯相关
parameters: []
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-145430948-run
security: []
"/informationTable/update":
put:
summary: 资讯_更新_根据ID
x-apifox-folder: 资讯相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 资讯相关
parameters: []
requestBody:
content:
application/json:
schema:
type: object
properties:
title:
type: string
content:
type: string
type:
type: string
attachments:
type: string
creator:
type: string
id:
type: string
x-apifox-orders:
- title
- content
- type
- attachments
- creator
- id
required:
- title
- content
- creator
- attachments
- type
- id
x-apifox-ignore-properties: []
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-145430958-run
security: []
"/informationTable/delete/2":
delete:
summary: 资讯_删除
x-apifox-folder: 资讯相关
x-apifox-status: developing
deprecated: false
description: 删除成功code1,当data为1时是有数据成功删除,当data为0时表示数据库根本没这条数据
tags:
- 资讯相关
parameters: []
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-145431877-run
security: []
"/informationTable/statistics":
get:
summary: 资讯_数据统计
x-apifox-folder: 资讯相关
x-apifox-status: developing
deprecated: false
description: ''
tags:
- 资讯相关
parameters: []
responses:
'200':
description: 成功
content:
application/json:
schema:
type: object
properties: {}
x-apifox-ignore-properties: []
x-apifox-orders: []
x-run-in-apifox: https://apifox.com/web/project/3965777/apis/api-145432712-run
security: []
components:
schemas: {}
securitySchemes: {}
servers:
- url: http://test-cn.your-api-server.com
description: 测试环境
- url: http://localhost:8080
description: 开发环境
- url: http://prod-cn.your-api-server.com
description: 正式环境

个人认为还是可以的。(只是里面似乎夹带了一点apifox的私货啊,算了影响不大)

【萌狼蓝天】swagger速成的更多相关文章

  1. 【HarmonyOS】【Json解析】ZSON 与 HiJson 使用

    HiLog配置 为了方便调试,查看,先设置好Hilog public static final HiLogLabel loglabel = new HiLogLabel(HiLog.LOG_APP,0 ...

  2. 【HarmonyOS】【DevEco Studio】NOTE04:How to Jump to a Page(页面间的跳转)

    页面创建与基本设置 创建页面 创建两个新页面,分别为AbilityPage1.AbilityPage2 设置页面基本内容 以AbilityPage1为例 导包 import com.example.m ...

  3. 【HarmonyOS】【DevEco Studio】NOTE02 :Create a  “Hello World ”Application

    Author:萌狼蓝天 StudyTime:2021/12/06 Version:3.0 Beta1 包结构 src | --> resource 资源文件目录 | --> layout/ ...

  4. 【Linux】【CentOS】【FTP】FTP服务器安装与配置(vsftpd、lftp)

    [初次学习.配置的笔记,如有不当,欢迎在评论区纠正 -- 萌狼蓝天 @ 2021-12-02] 基本概念 FTP访问方式 实体账号:本地账户 来宾账户:guest 匿名登录:anonymous fp ...

  5. 【Linux】【专项突破】Linux重定向与管道

    [专项突破]Linux重定向与管道 This article is written by Xrilang(Chinese Name:萌狼蓝天) If you want find me ,You can ...

  6. 【Linux】【RedHat】下载 安装 注册

    RedHat 下载 安装 注册 记录 因为找入口太麻烦了,所以写了篇博文记录下来大致入口@萌狼蓝天 注册 点击进入注册地址(https://www.redhat.com/wapps/ugc/regis ...

  7. 【JavaWeb】【JSP】JSP传值到Servlet后端为NULL的问题

    JSP传值到Servlet后端为NULL的问题 哔哩哔哩@萌狼蓝天 博客:萌狼工作室-博客园 联系QQ:#3447902411# | 仅限技术交流可添加 | 添加请说明你的方向和来意 1.目标文件路径 ...

  8. 【Linux】【CentOS7】免密登录突然失效

    [报错解决]免密登录突然失效 哔哩哔哩 萌狼蓝天 博客:萌狼工作室-博客园 [问题描述] 原本配置好了的免密登录,今天启动hadoop发现免密登录失效了 [解决方案] 1.切换到管理员模式,进入配置文 ...

  9. 【Spark】【复习】Spark入门考前概念相关题复习

    Spark考前概念相关题复习 AUthor:萌狼蓝天 哔哩哔哩:萌狼蓝天 博客园:我的文章 - 萌狼蓝天 博客:萌狼工作室 - 萌狼蓝天 (mllt.cc) 选择题 Hadoop 1.HADOOP的三 ...

  10. 【Spark】【RDD】初次学习RDD 笔记 汇总

    RDD Author:萌狼蓝天 [哔哩哔哩]萌狼蓝天 [博客]https://mllt.cc [博客园]萌狼蓝天 - 博客园 [微信公众号]mllt9920 [学习交流QQ群]238948804 目录 ...

随机推荐

  1. vue的计算属性computed和监视属性waatch的区别

    共同的:都是用于监听数据变化的属性: 计算属性:必须有返回值return ,依赖其它属性值,其它属性值发生变化的时候就会重新计算 : 监视属性:每当数据变化的时候就会触发执行,watch有两个新值和旧 ...

  2. 从零开始学机器学习——构建一个推荐web应用

    首先给大家介绍一个很好用的学习地址:https://cloudstudio.net/columns 今天,我们终于将分类器这一章节学习完活了,和回归一样,最后一章节用来构建web应用程序,我们会回顾之 ...

  3. Java 如何确保 JS 不被缓存

    大家好,我是 V 哥.今天咱们来聊一聊 Java 后端确保 JavaScript 不被缓存的问题,先来了解一下为什么需要这样做,通常源于以下几种场景或问题: 1. 先来看几个问题 1. 文件更新后无法 ...

  4. 洛谷 P1540 [NOIP2010 提高组] 机器翻译

    题目概括 给定 N 个整数,和一个容量为 M 的"字典",从头到尾依次翻译,每次翻译先看自家字典,没有的话再看别人的字典并存到自家字典,如果自家字典满了,当前单词的翻译会代替最早进 ...

  5. LeetCode题目练习记录 _数组和链表01 _20211007

    LeetCode题目练习记录 _数组和链表01 _20211007 26. 删除有序数组中的重复项 难度简单2247 给你一个有序数组 nums ,请你原地 删除重复出现的元素,使每个元素 只出现一次 ...

  6. Vmware Workstation的虚拟机如何通过宿主机的无线网卡和外部通信

    今天需要在我的笔记本w10电脑上安装一个linux虚拟机,苦于我的w10是家庭版,没有hyper-v功能,所以安装了 vmware的workstation的软件,然后创建了虚拟机,但是总是搞不定如何让 ...

  7. 根据字符串,获取实体属性上的annotation,如:createTime” 找到对应实体属性中的 TableField(value = "create_time", fill = FieldFill.INSERT)

    根据字符串,获取实体属性上的annotation,如:createTime" 找到对应实体属性中的 TableField(value = "create_time", f ...

  8. “应用程序无法正常启动(0xc000007)”处理办法

    前几天使用非静态方式编译了一个程序,在部分系统上运行提示缺少msvcp140.dll,就从VS2019安装目录找了一个同名文件放在了程序同级目录,程序也可以正常运行了.今天重新打开虚拟机,突然就报了这 ...

  9. Typora实现双击图片放大 Mac

    前置条件 Typora LightBox: github下载 添加LightBox拓展 打开应用程序,找到typora,右键选择"显示包内容". 解压lightbox2代码,将di ...

  10. FPGA时序约束基础

    一.时序约束的目的 由于实际信号在FPGA内部期间传输时,由于触发器等逻辑期间并非理想期间,因此不可避免地存在传输延时,这种延迟在高速工作频率.高逻辑级数时会造成后级触发器地建立时间和保持时间不满足, ...