Git Product home page Git Product logo

fastapi-openapi-specs-action's Introduction

FastAPI OpenAPI Specs Action

This is a simple GitHub action intended on automatically generating the openapi.yaml (or openapi.json) file for FastAPI projects. Intended on being used in conjunction with other actions to create complete workflows.

Inputs

Label Icon
๐ŸŸข Required
๐ŸŸก Required but defaults
๐Ÿ”ด Not required
Name Description Required Default
installDepedencies Command used to install depedencies before running FastAPI application. This command runs as a standard shell command. ๐ŸŸก pip install -r requirements.txt
moduleDir The directory in which the FastAPI Python app lives. This should be the first folder in your project with a __init__.py file. ๐ŸŸข
fileName The file from which your FastAPI application gets initialized. ๐ŸŸก main.py
appName The name of the FastAPI object inside your {moduleDir}/{fileName}.py. This is used to do from {moduleDir}.{fileName} import {appName}. ๐ŸŸก app
fastapiVersioning Only use this if your application uses the fastapi-versioning package. If the fastapi-versioning is being used each version of your application has its own individual FastAPI app that is ran in conjunction. This variable defines which FastAPI API to use to generate the client. Use the package's VersionedFastAPI.prefix_format string, something like v{number} typically (e.g. v1). ๐Ÿ”ด None
outputName The name of the output file without the extension. ๐ŸŸก openapi
outputExtension Output extension. May be either yaml or json. ๐ŸŸก yaml

Output

A new file called {outputName}.{outputExtension} is created in the current directory.

Example Usage

The example below is a complete example that utilizes the fastapi-openapi-specs-action with the openapitools-generator-action to automatically generate the FastAPI client code and publish it to the repository under the branch client.

name: Generate Client

# Runs this action whenever there are any changes to the master branch.
on:
  push:
    branches:
      - master

jobs:
  client:
    runs-on: ubuntu-latest

    # Checks out the entire repo.
    steps:
    - name: Checks out repo
      uses: actions/checkout@v1

    # Generates a openapi.yaml file based on the FastAPI project.
    - name: Generate OpenAPI file
      uses: column-street/[email protected]
      with:
        moduleDir: collector
        fileName: main.py
        appName: app
        fastapiVersioning: v1

    # Uses an external tool, openapitools-generator-action, to generate the client code.
    # The 'openapirc.json' file is the following: { "packageName": "collector", "projectName": "collector" }
    # and it lives inside the master branch of the repository. Command outputs a new folder called 
    # 'python-client' with the relevant client code.
    - name: Generate Python Client
      uses: triaxtec/[email protected]
      with:
        generator: python
        openapi-file: openapi.yaml
        config-file: openapirc.json

    # Deletes every file in the folder, except '.git' and the new generated 'python-client' folder.
    # Moves all content of the 'python-client' folder to the root directory.
    - name: Cleans the branch up.
      run: |
        # Removes all files except the .git and python-client folder.
        shopt -s extglob
        sudo rm -rf !(.|..|.git|python-client)
        # Moves all of the content of the python-client folder out, 
        # and deletes the folder.
        mv python-client/* .
        rm -rf python-client

    # Commits the new changes into a new branch called 'client'.
    - name: Commit changes.
      run: |
        git checkout -b client
        git config --local user.email "[email protected]"
        git config --local user.name "GitHub Action"
        git add .
        git commit -m "Generated client." -a || true 

    # Pushes all of these changes into the GitHub repository.
    - name: Push changes to client branch
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: client
        force: True

fastapi-openapi-specs-action's People

Contributors

synchronizing avatar gungo 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.