Skip to content

Commit 96f4000

Browse files
committed
CI fix ; increased coverage
1 parent 2c7b4c2 commit 96f4000

File tree

20 files changed

+557
-64
lines changed

20 files changed

+557
-64
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v6
1515
- name: Set up Python
1616
uses: actions/setup-python@v5
1717
with:
@@ -30,7 +30,7 @@ jobs:
3030
- name: Build WASM
3131
run: make build_wasm
3232
- name: Upload Build Artifacts
33-
uses: actions/upload-artifact@v4
33+
uses: actions/upload-artifact@v6
3434
with:
3535
name: python-build
3636
path: dist/
@@ -40,12 +40,12 @@ jobs:
4040
if: startsWith(github.ref, 'refs/tags/')
4141
runs-on: ubuntu-latest
4242
steps:
43-
- uses: actions/checkout@v4
43+
- uses: actions/checkout@v6
4444
- uses: actions/download-artifact@v4
4545
with:
4646
name: python-build
4747
path: dist/
4848
- name: Release
49-
uses: softprops/action-gh-release@v1
49+
uses: softprops/action-gh-release@v2
5050
with:
5151
files: dist/**/*

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
docs/
2+
out_server/
13
build/
24
dist/
35
*.xml

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,32 @@ dual licensed as above, without any additional terms or conditions.
120120
| WebAssembly (WASM) Build | [x] | [ ] | |
121121

122122
For more details, see [WASM.md](WASM.md).
123+
\n## CLI Usage\n\n```
124+
usage: cdd-python [-h] [--version]
125+
{from_openapi,to_openapi,sync,to_docs_json,server_json_rpc}
126+
...
127+
128+
CDD Python Client generator and extractor.
129+
130+
positional arguments:
131+
{from_openapi,to_openapi,sync,to_docs_json,server_json_rpc}
132+
from_openapi Generate code from OpenAPI
133+
to_openapi Extract OpenAPI from code
134+
sync Sync a directory containing client.py, mock_server.py,
135+
test_client.py, cli_main.py
136+
to_docs_json Generate JSON documentation
137+
server_json_rpc Run JSON-RPC server
138+
139+
options:
140+
-h, --help show this help message and exit
141+
--version show program's version number and exit
142+
```\n
143+
```
144+
usage: cdd-python from_openapi [-h] {to_sdk,to_sdk_cli,to_server} ...
145+
146+
positional arguments:
147+
{to_sdk,to_sdk_cli,to_server}
148+
149+
options:
150+
-h, --help show this help message and exit
151+
```\n

client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from urllib3 import PoolManager
2+
from typing import Any, Dict, Optional, List
3+
from pydantic import BaseModel, Field
4+
5+
class Client:
6+
def __init__(self, base_url: str):
7+
self.base_url = base_url
8+
self.http = PoolManager()

docs.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"language": "python",
4+
"operations": [
5+
{
6+
"method": "GET",
7+
"path": "/test",
8+
"code": {
9+
"snippet": "response = client.getTest()"
10+
},
11+
"operationId": "getTest"
12+
}
13+
]
14+
}
15+
]

parse_spec.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies = [
1212
"pydantic>=2.0",
1313
"libcst",
1414
"urllib3",
15+
"python-cdd>=0.0.98",
1516
]
1617

1718
[project.optional-dependencies]

spec.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"openapi": "3.2.0",
3+
"info": {"title": "Test", "version": "1.0"},
4+
"paths": {
5+
"/test": {
6+
"get": {
7+
"operationId": "getTest",
8+
"responses": {"200": {"description": "OK"}}
9+
}
10+
}
11+
}
12+
}

src/openapi_client/cli.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def generate_docs_json(
9999

100100
out_json = json.dumps(output, indent=2)
101101
if output_file:
102-
Path(output_file).write_text(out_json, encoding="utf-8")
102+
Path(output_file).write_text(out_json + "\n", encoding="utf-8")
103103
else:
104104
print(out_json)
105105

@@ -168,7 +168,12 @@ def process_from_openapi(
168168
"""Process from_openapi subcommands."""
169169
if not output_dir:
170170
output_dir = "."
171-
out_dir = Path(output_dir)
171+
out_path = Path(output_dir)
172+
if out_path.suffix: # It's a file path
173+
out_dir = out_path.parent
174+
else:
175+
out_dir = out_path
176+
172177
out_dir.mkdir(parents=True, exist_ok=True)
173178

174179
if input_path:
@@ -196,10 +201,21 @@ def process_from_openapi(
196201
(out_dir / "client.py").write_text(
197202
generator.generate_code(), encoding="utf-8"
198203
)
204+
from openapi_client.cli_sdk_cdd.emit import emit_cli_sdk
205+
199206
(out_dir / "cli_main.py").write_text(emit_cli_sdk(spec), encoding="utf-8")
200207
elif subcommand == "to_server":
201-
mock_module = emit_mock_server(spec)
202-
(out_dir / "mock_server.py").write_text(mock_module.code, encoding="utf-8")
208+
from openapi_client.fastapi.emit import emit_fastapi
209+
from openapi_client.sqlalchemy_cdd.emit import emit_sqlalchemy
210+
211+
# Emit FastAPI server
212+
fastapi_code = emit_fastapi(spec)
213+
(out_dir / "main.py").write_text(fastapi_code, encoding="utf-8")
214+
215+
# Emit SQLAlchemy models
216+
sa_code = emit_sqlalchemy(spec)
217+
if sa_code:
218+
(out_dir / "models.py").write_text(sa_code, encoding="utf-8")
203219

204220
if not no_installable_package:
205221
scaffold_package(out_dir)

src/openapi_client/cli_sdk_cdd/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)