在业务逻辑应用程序中使用 swagger 生成的数据模型的最佳方法

Mau*_*aus 5 python flask swagger connexion

我有一个 Python 程序,它封装了应用程序的业务逻辑。一个例子:

$ app pets list
[{
 "name": "Hasso",
 "age": 21
},{
 "name": "Lassy",
 "age": 15
 }]
Run Code Online (Sandbox Code Playgroud)

现在我想用Swagger.io实现一个 REST API 。YAML 的摘录如下所示:

 summary: Gets all dogs 
  produces:
  - application/json
  responses:
    200:
      description: array of dogs
      schema:
        type: array
        items:
        $ref: '#/definitions/Dog'
Run Code Online (Sandbox Code Playgroud)

Swagger-codgen 使用 Flask & connexion生成 python 代码并提供以下目录结构:

??? python-flask
    ??? swagger_server
        ??? controllers
        ??? models
        ??? __pycache__
        ??? swagger
        ??? test
Run Code Online (Sandbox Code Playgroud)

-目录中有所有使用的对象类型的类models

我想将 API-App 和 BL-App(业务应用程序)分开,但为了方便起见使用相同的模型。

将这些模型定义之间的模型定义共享给应用程序的最佳方式是什么?我还将这个 BL-App 导入 API-Project 以实现controllers-part。