Skip to content

Commit 66e5494

Browse files
committed
Update README to be useful
Closes #1
1 parent 3da8a42 commit 66e5494

File tree

11 files changed

+68
-22
lines changed

11 files changed

+68
-22
lines changed

README.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,49 @@
11
# openapi-python-client
2-
3-
## Purpose
42
Generate modern Python clients from OpenAPI
53

6-
## Release Process
7-
1. Start a release with Git Flow
8-
1. Update the version number in `pyproject.toml` with `poetry version <rule>`
9-
1. Ensure all requirements are pointing to released versions
10-
1. Add the release date to the new version in [CHANGELOG.md]
11-
1. Commit and push any changes
12-
1. Create a pull request from the release branch to master
13-
1. Get approval from all stakeholders
14-
1. Ensure all checks pass (e.g. CircleCI)
15-
1. Open and merge the pull request
16-
1. Create a tag on the merge commit with the release number
4+
**This project is still in early development and does not support all OpenAPI features**
5+
6+
## Why This?
7+
The Python clients generated by openapi-generator support Python 2 and therefore come with a lot of baggage. This tool
8+
aims to generate clients which:
9+
1. Use all the latest and greatest Python features like type annotations and dataclasses
10+
1. Don't carry around a bunch of compatibility code for older version of Python (e.g. the `six` package)
11+
1. Have better documentation and more obvious usage instructions
12+
13+
Additionally, because this generator is written in Python, it should be more accessible to contribution by the people
14+
using it (Python developers).
15+
16+
## Installation
17+
`pip install openapi-python-client`
18+
19+
## Usage
20+
`openapi-python-client generate --url https://my.api.com/openapi.json`
21+
22+
This will generate a new client library named based on the title in your OpenAPI spec. For example, if the title
23+
of your API is "My API", the expected output will be "my-api-client". If a folder already exists by that name, you'll
24+
get an error.
25+
26+
## What You Get
27+
1. A `pyproject.toml` file with some basic metadata intended to be used with [Poetry].
28+
1. A `README.md` you'll most definitely need to update with your project's details
29+
1. A Python module named just like the auto-generated project name (e.g. "my_api_client") which contains:
30+
1. A `client` module which will have both a `Client` class and an `AuthenticatedClient` class. You'll need these
31+
for calling the functions in the `api` module.
32+
1. An `api` module which will contain one module for each tag in your OpenAPI spec, as well as a `default` module
33+
for endpoints without a tag. Each of these modules in turn contains one function for calling each endpoint.
34+
1. A `models` module which has all the classes defined by the various schemas in your OpenAPI spec
35+
36+
## OpenAPI features supported
37+
1. All HTTP Methods
38+
1. JSON and form bodies, path and query parameters
39+
1. float, string, int, datetimes, string enums, and custom schemas or lists containing any of those
40+
1. html/text or application/json responses containing any of the previous types
41+
1. Bearer token security
42+
1743

1844
## Contributors
1945
- Dylan Anthony <[email protected]> (Owner)
2046

2147

2248
[CHANGELOG.md]: CHANGELOG.md
49+
[Poetry]: https://python-poetry.org/

openapi_python_client/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
""" Generate modern Python clients from OpenAPI """
2-
import sys
32
from pathlib import Path
43
from typing import Any, Dict
54

65
import orjson
76
import requests
87
from jinja2 import Environment, PackageLoader
98

10-
from .models import OpenAPI, import_string_from_reference
9+
from .openapi_parser import OpenAPI, import_string_from_reference
1110

1211

13-
def main() -> None:
12+
def main(url: str) -> None:
1413
""" Generate the client library """
15-
url = sys.argv[1]
1614
json = _get_json(url)
1715
data_dict = _parse_json(json)
1816
openapi = OpenAPI.from_dict(data_dict)
@@ -33,6 +31,7 @@ def _build_project(openapi: OpenAPI) -> None:
3331

3432
# Create output directories
3533
project_name = f"{openapi.title.replace(' ', '-').lower()}-client"
34+
print(f"Generating {project_name}")
3635
package_name = f"{openapi.title.replace(' ', '_').lower()}_client"
3736
project_dir = Path.cwd() / project_name
3837
project_dir.mkdir()

openapi_python_client/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from . import main
1+
from .cli import cli
22

3-
main()
3+
cli()

openapi_python_client/cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import click
2+
3+
from . import main
4+
5+
6+
@click.group()
7+
def cli():
8+
""" Entrypoint into CLI """
9+
pass
10+
11+
12+
@cli.command()
13+
@click.option("--url", required=True, help="The URL to the openapi.json file")
14+
def generate(url: str):
15+
""" Generate a new OpenAPI Client library """
16+
main(url=url)

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "openapi-python-client"
3-
version = "0.1.0"
3+
version = "0.1.0-dev.0"
44
description = "Generate modern Python clients from OpenAPI"
55

66
authors = [
@@ -20,6 +20,10 @@ requests = "^2.22.0"
2020
orjson = "^2.4.0"
2121
jinja2 = "^2.11.1"
2222
stringcase = "^1.2.0"
23+
click = "^7.0"
24+
25+
[tool.poetry.scripts]
26+
openapi-python-client = "openapi_python_client.cli:cli"
2327

2428
[tool.poetry.dev-dependencies]
2529
pytest = "*"

0 commit comments

Comments
 (0)