Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.8

RUN python -m pip install --upgrade pip
RUN pip install pipx

# Sets the user to the same user that the workflow runner uses so that it can access the generated client
USER 1001

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
# openapi-python-client-action
GitHub Action to generate a python client package from an openapi spec
The official GitHub Action for [openapi-python-client](https://github.com/triaxtec/openapi-python-client) - generates a modern Python client package from an OpenAPI document

## Inputs

### `openapi-python-client-version`

The version of the openapi-python-client package to use. If unspecified the latest released version will be used.

### `openapi-file`

The path (with respect to the current directory/the workspace) to the OpenAPI document (both JSON and YAML are supported). Defaults to just "openapi.json" i.e. a file in the current directory called openapi.json.

### `openapi-url`

The url of the OpenAPI document. Overrides `openapi-file` - If unspecified the value of the `openapi-file` input (which defaults to just `openapi.json`) will be used to generate the client.

### `config-file`

The path (with respect to the current directory/the workspace) to the config.yml to be used with openapi-python-client. Configuaration is not required so if this is unspecified then no configuration will be passed along. See [openapi-python-client's README](https://github.com/triaxtec/openapi-python-client#configuration) for available configuration

## Outputs

No outputs are returned.
The generated client is placed in the current directory. The name of the package (unless configured differently) will be `title-client` where "title" comes from the field with the same name within the `info` section of the openapi document.

## Example usage
```yaml
jobs:
generate-python-client:
runs-on: ubuntu-latest
name: Example
steps:

# Checkout your code
- name: Checkout
uses: actions/checkout@v2

# Generate your openapi document (if you don't write it manually)

# Use the action to generate a client package
# This uses all defaults (latest version, openapi.json in the current workspace, no configuration)
- name: Generate Python Client
uses: triaxtec/openapi-python-client-action@v1

# Do something with the generated client (likely publishing it somewhere)
# Here we assume that the info/title in the openapi document was "example-project"
- name: Do something with the client
run: |
cd example-project-client
```
32 changes: 32 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Generate A Python Client Package From An OpenAPI file"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the name that gets displayed in the marketplace? Or just in Actions when running?

If the first, this should be "openapi-python-client Action" or something. If the second, maybe just "Generate Python Client"?

Copy link
Collaborator Author

@emann emann Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The former; My thinking was to make it a tad more search friendly (on the actions marketplace that is) so that its a bit discoverable + easy to get what it does just from reading the name. That seems to be the standard way of doing it based off of what I've seen in the marketplace - unless its a multipurpose/function action the name briefly tells you what it does. I think it could do with being shortened however - how do you feel about just "Generate Python Client From An OpenAPI File"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or "Generate Python Client from OpenAPI"?

description: "Generates a Python client package from an OpenAPI document using the openapi-python-client project"
branding:
icon: "target"
color: "green"

inputs:
openapi-python-client-version:
description: The version of openapi-python-client to use
required: false
default: NOT_SPECIFIED
openapi-file:
description: The path to the OpenAPI document to generate a client library for e.g. docs/openapi.json
required: false
default: openapi.json
openapi-url:
description: The url of the OpenAPI document to generate a client library for e.g. https://petstore3.swagger.io/api/v3/openapi.json
required: false
default: NOT_SPECIFIED
config-file:
description: Path to the config file to be passed along to openapi-python-client
required: false
default: NOT_SPECIFIED

runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.openapi-python-client-version }}
- ${{ inputs.openapi-file }}
- ${{ inputs.openapi-url }}
- ${{ inputs.config-file }}
25 changes: 25 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

openapi_python_client_version=$1
openapi_file_path=$2
openapi_url=$3
config_file_path=$4

if [[ "$openapi_python_client_version" != "NOT_SPECIFIED" ]]; then
version_arg="--spec openapi-python-client==${openapi_python_client_version}"
else
version_arg=""
fi

if [[ "$config_file_path" != "NOT_SPECIFIED" ]]; then
config_arg="--config ${config_file_path}"
else
config_arg=""
fi

openapi_document_path_or_url_arg="--path ${openapi_file_path}"
if [[ "$openapi_url" != "NOT_SPECIFIED" ]]; then
openapi_document_path_or_url_arg="--url ${openapi_url}"
fi

pipx run ${version_arg} openapi-python-client ${config_arg} generate ${openapi_document_path_or_url_arg}