Use Swagger tool to generate a Python package from Chuk Norris OpenAPI service description

When you have an OpenAPI documentation, you know how to build your requests and how to parse responses. Swagger can help you speed up that process by generating a client package that wraps the calls for you.

  1. Go to Swagger Editor online.
  2. File menu / Import file / upload the following "chuckNorris_openAPI-v2.yaml" file.
    This file is similar to the one created in a previous activity except for 2 things:
  3. Use the Generate Client menu / python
  4. Unzip the downloaded file: unzip ~/Downloads/python-client-generated.zip
    The docs folder contains the documentation for the 3 generated classes that you will use:
    (You can use the ReText program to display Markdown file: retext ~/Downloads/docs/ChuckNorrisApi.md.)
  5. To install the API client library to your python environment:
    1. Create a new virtual environment (python -m venv environment_name) or create a new project with PyCharm.
    2. With the virtual environment activated (if not in PyCharm, run source environment_location/bin/activate (replace environment_location with the appropriate path), your terminal should now prepend your environment name to your command prompt), move to the directory where you've unzipped the generated client library and run python setup.py install --user --install-lib environment_location/lib/python3.8/site-packages/ and pip install -r requirements.txt
  6. import the module and use it (as explained in the README.md):
  7. Execute!