0%

介绍

Swagger/OpenAPI 用于定义后端的REST API,协调前后端的开发。

几种开发模式

手工模式

  1. 使用工具 swagger editor 手工编写出 API 文档
  2. 前后端根据该API文档进行开发,前后端都可以用openapi-generator进行生成
  3. 当 API 发生变更,需要先手工更新API文档

自动生成模式

  1. 编写后端 API 代码
  2. 使用工具 springdoc-openapi 根据后端 API 代码生成 API 文档
  3. 使用 openapi-generator 生成前端(客户端)代码
  4. 当 API 发生变更,直接改写后端 API 代码,然后重新生成 API 文档和前端代码

本文介绍第二种模式,因为这种模式下,API文档可维护性高,会强制保持最新版本

阅读全文 »

Run Python Jupyter notebook in VSCode on remote host

Steps

  1. Install “Remote Development” plugin for VSC

  2. Install “Python” plugin for VSC

  3. Install jupyter kernel on the remote host

    1
    pip3 install ipykernel
  4. Open the remote directory with VSC,
    Create New Jupyter Notebook command from the Command Palette (Ctrl+Shift+P) or by creating a new .ipynb file in your workspace.

Jupyter notebooks in Visual Studio Code does not use the active virtual environment

Option 1

VSCode:
Windows: F1
Mac: _

Python:Select Interpreter

Option 2

1
(venv) $ ipython kernel install --user --name=venv_name

Ref: https://stackoverflow.com/questions/58119823/jupyter-notebooks-in-visual-studio-code-does-not-use-the-active-virtual-environm

yield

用于写生成器,但是可以用来写协程(现在用 async 库来写协程库更好)

1
2
3
4
5
6
7
def f123():
yield 1
yield 2
yield 3

for item in f123():
print(item)
1
2
3
1
2
3

Kubernetes API

OpenAPI Spec

Kubernetes Open API spec 有两个版本,同时存在

2.0

1
https://github.com/kubernetes/kubernetes/blob/master/api/openapi-spec/swagger.json

3.0

1
https://github.com/kubernetes/kubernetes/tree/master/api/openapi-spec

目前,各个语言的客户端都用 2.0 生成。

kubernetes/kube-openapi 项目,扫描 kubernetes 源代码,根据 // tag 的指示,生成 spec 文件,我个人认为会同时生成 2.0 和 3.0 的文件。

阅读全文 »