5

I have a Python program which encapsulates the business logic of an app. An example:

$ app pets list
[{
 "name": "Hasso",
 "age": 21
},{
 "name": "Lassy",
 "age": 15
 }]

Now I want to realize a REST API with Swagger.io. An extract of the YAML looks like this:

 summary: Gets all dogs 
  produces:
  - application/json
  responses:
    200:
      description: array of dogs
      schema:
        type: array
        items:
        $ref: '#/definitions/Dog'

Swagger-codgen generates python code using Flask & connexion and provides the following directory structure:

└── python-flask
    └── swagger_server
        ├── controllers
        ├── models
        ├── __pycache__
        ├── swagger
        └── test

There are classes for all used object types in the models-directory.

I want to keep the API-App and the BL-App(business app) separate but use the same models for convenience.

What's the best way of sharing the model definitions in-between these to applications? I will also import this BL-App into the API-Project in order to implement the controllers-part.

WeiChing 林煒清
  • 4,452
  • 3
  • 30
  • 65
Maus
  • 2,724
  • 5
  • 32
  • 37
  • A 'superior user' might want to create the [connexion] tag... – Maus Jan 12 '18 at 14:19
  • 2
    FWIW, for my projects, I've found I prefer the [`bravado`](https://bravado.readthedocs.io/en/latest/) library, which generates model types from the `swagger.yaml`/`swagger.json` of the API server on the fly. That also neatly sidesteps the issue of where to store the generated classes. – Daniel Pryden Jan 12 '18 at 14:24

0 Answers0