Giter Club home page Giter Club logo

openapi-demo's Introduction

OpenApi App Experiments

Requirements

  • Python3.7 or higher
  • Virtualenv
$ python --version
Python 3.7.1

Setup

Note: You may need to explicitly install virtualenv, it depends on how you installed python.

Lets inspect our python/pip binaries:

$ which python3.7
/usr/local/bin/python3.7
$ which pip3.7
/usr/local/bin/pip3.7

Notice that this is the system python/pip...

Now, let's create and activate virtualenv.

$ python3.7 -m venv venv
$ source venv/bin/activate
$ which python3.7
./venv/bin/python3.7
$ which pip3.7

After activating the virtualenv python/pip are project specific!

Now lets install our project dependencies. Since we have listed all of then in our requirements.txt this is an easy task.

$ pip install -r requirements.txt
...

Run Flask Development Server

FLASK_ENV=development FLASK_APP=app.py flask run
 * Serving Flask app "app.py" (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 235-428-926

Run Connexion Development Server

$ FLASK_ENV=development python connexion_app.py
[INFO] added x persons to the database
 * Serving Flask app "connexion_app" (lazy loading)
 * Environment: development
 * Debug mode: off
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
$ curl 0.0.0.0:8080/persons -X post -d '{"name": "juanito", "age": 11, "beautiful": true}' -H "Content-Type: application/json"
{
  "age": 11,
  "beautiful": true,
  "name": "juanito",
  "person_id": 3
}

$ curl 0.0.0.0:8080/persons/1
{
  "age": 27,
  "beautiful": true,
  "name": "Catz",
  "person_id": 1
}

$ curl 0.0.0.0:8080/persons  
[
  {
    "age": 27,
    "beautiful": true,
    "name": "Catz",
    "person_id": 1
  },
  {
    "age": 31,
    "beautiful": false,
    "name": "Luis Amarelo",
    "person_id": 2
  },
  {
    "age": 26,
    "beautiful": true,
    "name": "Chi",
    "person_id": 33
  },
  {
    "age": 47,
    "beautiful": true,
    "name": "Juan",
    "person_id": 101
  }
]

Run Tests & Quality Control Tools

This is very important, even if you don't believe it. To run the tests we use the following command:

Tests

$ pytest -v  
...
...
==== x passed in 0.05 seconds ====

Type Checking

$ mypy .

Linting

$ flake8

Formating

Import sorting:

$ isort -rc persons test_persons flask_app.py connexion_app.py

Code formating:

$ black persons test_persons flask_app.py connexion_app.py
All done! ✨ 🍰 ✨
x files left unchanged.

Open Api docs

Install docs generator:

npm install redoc-cli -g

Generate Docs:

redoc-cli bundle openapi3.yaml
mv redoc-static.html persons.html

Todo

  • implement and test endpoints (flask app)

  • setup code test coverage

  • setup continuous integration

  • auto generate Open API spec (from flask app) ?

openapi-demo's People

Contributors

acciaioli avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.