Skip to content

Commit 6630ed2

Browse files
emanndbanty
andauthored
Initial Release (#1)
* Initial draft/some testing * fixing the dockerfile name * Fixed Dockerfile name * Fixed typo * Fixed typo in dockerfile * Copy entrypoint into image * Fix typo * Made entrypoint executable * Added shebang to entrypoint * Input is now actaully used * Attempt to fix file permissions issues * Attempt #2 to fix file permission issues * Trying changing user back to 1001 * Updated inputs and how they are handled * Debugging * Fix formatting in entrypoint script * Switched to using pipx for running openapi-python-client * Trying to fix user permissions again * Cleaned up the entrypoint script a bit * Added documentation/usages details to README * Added a note about the "USER 1001" in the Dockerfile * Apply suggestions from code review Co-authored-by: Dylan Anthony <[email protected]> * Added support for specifying a url instead of a file path for the openapi doc Co-authored-by: Ethan Mann <[email protected]> Co-authored-by: Dylan Anthony <[email protected]>
1 parent 850c3cb commit 6630ed2

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.8
2+
3+
RUN python -m pip install --upgrade pip
4+
RUN pip install pipx
5+
6+
# Sets the user to the same user that the workflow runner uses so that it can access the generated client
7+
USER 1001
8+
9+
COPY entrypoint.sh /entrypoint.sh
10+
11+
ENTRYPOINT ["/entrypoint.sh"]

README.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# openapi-python-client-action
2-
GitHub Action to generate a python client package from an openapi spec
2+
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
3+
4+
## Inputs
5+
6+
### `openapi-python-client-version`
7+
8+
The version of the openapi-python-client package to use. If unspecified the latest released version will be used.
9+
10+
### `openapi-file`
11+
12+
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.
13+
14+
### `openapi-url`
15+
16+
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.
17+
18+
### `config-file`
19+
20+
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
21+
22+
## Outputs
23+
24+
No outputs are returned.
25+
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.
26+
27+
## Example usage
28+
```yaml
29+
jobs:
30+
generate-python-client:
31+
runs-on: ubuntu-latest
32+
name: Example
33+
steps:
34+
35+
# Checkout your code
36+
- name: Checkout
37+
uses: actions/checkout@v2
38+
39+
# Generate your openapi document (if you don't write it manually)
40+
41+
# Use the action to generate a client package
42+
# This uses all defaults (latest version, openapi.json in the current workspace, no configuration)
43+
- name: Generate Python Client
44+
uses: triaxtec/openapi-python-client-action@v1
45+
46+
# Do something with the generated client (likely publishing it somewhere)
47+
# Here we assume that the info/title in the openapi document was "example-project"
48+
- name: Do something with the client
49+
run: |
50+
cd example-project-client
51+
```

action.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Generate A Python Client Package From An OpenAPI file"
2+
description: "Generates a Python client package from an OpenAPI document using the openapi-python-client project"
3+
branding:
4+
icon: "target"
5+
color: "green"
6+
7+
inputs:
8+
openapi-python-client-version:
9+
description: The version of openapi-python-client to use
10+
required: false
11+
default: NOT_SPECIFIED
12+
openapi-file:
13+
description: The path to the OpenAPI document to generate a client library for e.g. docs/openapi.json
14+
required: false
15+
default: openapi.json
16+
openapi-url:
17+
description: The url of the OpenAPI document to generate a client library for e.g. https://petstore3.swagger.io/api/v3/openapi.json
18+
required: false
19+
default: NOT_SPECIFIED
20+
config-file:
21+
description: Path to the config file to be passed along to openapi-python-client
22+
required: false
23+
default: NOT_SPECIFIED
24+
25+
runs:
26+
using: "docker"
27+
image: "Dockerfile"
28+
args:
29+
- ${{ inputs.openapi-python-client-version }}
30+
- ${{ inputs.openapi-file }}
31+
- ${{ inputs.openapi-url }}
32+
- ${{ inputs.config-file }}

entrypoint.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
openapi_python_client_version=$1
4+
openapi_file_path=$2
5+
openapi_url=$3
6+
config_file_path=$4
7+
8+
if [[ "$openapi_python_client_version" != "NOT_SPECIFIED" ]]; then
9+
version_arg="--spec openapi-python-client==${openapi_python_client_version}"
10+
else
11+
version_arg=""
12+
fi
13+
14+
if [[ "$config_file_path" != "NOT_SPECIFIED" ]]; then
15+
config_arg="--config ${config_file_path}"
16+
else
17+
config_arg=""
18+
fi
19+
20+
openapi_document_path_or_url_arg="--path ${openapi_file_path}"
21+
if [[ "$openapi_url" != "NOT_SPECIFIED" ]]; then
22+
openapi_document_path_or_url_arg="--url ${openapi_url}"
23+
fi
24+
25+
pipx run ${version_arg} openapi-python-client ${config_arg} generate ${openapi_document_path_or_url_arg}

0 commit comments

Comments
 (0)