Skip to content

khulnasoft-lab/readyapi-openapi-specs-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReadyAPI OpenAPI Specs Action

This is a simple GitHub action intended on automatically generating the openapi.yaml (or openapi.json) file for ReadyAPI 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
installDependencies Command used to install dependencies before running ReadyAPI application. This command runs as a standard shell command. 🟡 pip install -r requirements.txt
moduleDir The directory in which the ReadyAPI Python app lives. This should be the first folder in your project with a __init__.py file. 🟢
fileName The file from which your ReadyAPI application gets initialized. 🟡 main.py
appName The name of the ReadyAPI object inside your {moduleDir}/{fileName}.py. This is used to do from {moduleDir}.{fileName} import {appName}. 🟡 app
readyapiVersioning Only use this if your application uses the readyapi-versioning package. If the readyapi-versioning is being used each version of your application has its own individual ReadyAPI app that is ran in conjunction. This variable defines which ReadyAPI API to use to generate the client. Use the package's VersionedReadyAPI.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 readyapi-openapi-specs-action with the openapitools-generator-action to automatically generate the ReadyAPI 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 ReadyAPI project.
    - name: Generate OpenAPI file
      uses: khulnasoft-lab/[email protected]
      with:
        moduleDir: collector
        fileName: main.py
        appName: app
        readyapiVersioning: 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

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Packages