添加openapi编写示例
This commit is contained in:
parent
0aff29b24d
commit
24afed3120
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
25
task01.md
25
task01.md
|
@ -225,6 +225,31 @@ Django REST Framework 本身提供方便的工具可以查看已有接口的返
|
|||
|
||||
页面左边为`openapi.yaml`的内容,右边为解析后的接口呈现。可以看到目前已经定义了5个API接口,包括其HTTP方法、URL Path、
|
||||
返回格式等内容。
|
||||
### 编辑示例
|
||||
编写openapi 文档涉及以下步骤:
|
||||
1、明确接口需求,如 我们需要查询文章列表,在最近文章页面里展示
|
||||
2、设计请求url、请求参数、响应内容,这里为了让小伙伴们先熟悉openapi已经给小伙伴做好了接口设计,大家可以在此基础上修改调整(开发中需要前后端根据需求协商确定url、属性名、类型等接口信息)
|
||||
> 可以在前端浏览器,如chrome 快捷键F12打开web调试器 查看接口请求和响应信息
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
3、打开编辑器,如swagger editor,编辑器或者插件提供了一些便捷操作辅助我们编写,这里我们先插入path
|
||||

|
||||
4、再添加操作
|
||||

|
||||
5、添加响应信息
|
||||

|
||||
> 为了结构清晰和数据复用(相同的内容可以用$ref引用),我们在 components.schemas 下创建 响应对象
|
||||
|
||||

|
||||
|
||||
6、参考其他接口或者openapi规范 手动调整一下接口,如添加参数等
|
||||

|
||||
> 编写时注意yaml语法、tab空格对齐
|
||||
|
||||
7、尝试执行,如果响应如期正常返回就编写完成了
|
||||
|
||||
## 运行mock server
|
||||
|
||||
|
|
Loading…
Reference in New Issue