openapi-client-codegen 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openapi_client_codegen/__init__.py +0 -15
- openapi_client_codegen/cli.py +38 -0
- openapi_client_codegen/client.py +1 -1
- openapi_client_codegen/orchestrator.py +95 -0
- openapi_client_codegen/templates.py +1 -1
- {openapi_client_codegen-0.1.1.dist-info → openapi_client_codegen-0.1.2.dist-info}/METADATA +1 -1
- {openapi_client_codegen-0.1.1.dist-info → openapi_client_codegen-0.1.2.dist-info}/RECORD +11 -10
- {openapi_client_codegen-0.1.1.dist-info → openapi_client_codegen-0.1.2.dist-info}/WHEEL +0 -0
- {openapi_client_codegen-0.1.1.dist-info → openapi_client_codegen-0.1.2.dist-info}/entry_points.txt +0 -0
- {openapi_client_codegen-0.1.1.dist-info → openapi_client_codegen-0.1.2.dist-info}/licenses/LICENSE +0 -0
- {openapi_client_codegen-0.1.1.dist-info → openapi_client_codegen-0.1.2.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from .client import generate_client
|
|
2
|
-
from .downgrade import downgrade_openapi_3_1_to_3_0
|
|
3
|
-
from .naming import ClientNaming, DefaultNamingPolicy, NamingPolicy
|
|
4
|
-
from .templates import regenerate_templates
|
|
5
|
-
from .unity import write_unity_package_metadata
|
|
6
|
-
|
|
7
|
-
__all__ = [
|
|
8
|
-
"ClientNaming",
|
|
9
|
-
"DefaultNamingPolicy",
|
|
10
|
-
"NamingPolicy",
|
|
11
|
-
"downgrade_openapi_3_1_to_3_0",
|
|
12
|
-
"generate_client",
|
|
13
|
-
"regenerate_templates",
|
|
14
|
-
"write_unity_package_metadata",
|
|
15
|
-
]
|
openapi_client_codegen/cli.py
CHANGED
|
@@ -8,6 +8,7 @@ from typer import Argument, Option, Typer
|
|
|
8
8
|
from .client import generate_client
|
|
9
9
|
from .downgrade import downgrade_openapi_3_1_to_3_0
|
|
10
10
|
from .naming import DefaultNamingPolicy
|
|
11
|
+
from .orchestrator import SpecProducer, generate_projects
|
|
11
12
|
from .templates import regenerate_templates
|
|
12
13
|
|
|
13
14
|
app = Typer(pretty_exceptions_show_locals=False)
|
|
@@ -51,3 +52,40 @@ def generate(
|
|
|
51
52
|
license_spdx=license_spdx,
|
|
52
53
|
repository_url=repository_url,
|
|
53
54
|
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@app.command("generate-projects")
|
|
58
|
+
def generate_projects_command(
|
|
59
|
+
config: Annotated[Path, Option(help="JSON file mapping project paths to client generator lists")],
|
|
60
|
+
root_name: Annotated[str, Option(help="Root name handed to DefaultNamingPolicy")],
|
|
61
|
+
generated_root: Annotated[Path, Option(help="Root directory the generated clients sync into")],
|
|
62
|
+
spec_command: Annotated[
|
|
63
|
+
str,
|
|
64
|
+
Option(
|
|
65
|
+
help="Shell command printing the project's raw OpenAPI JSON to stdout; runs with the project directory as cwd"
|
|
66
|
+
),
|
|
67
|
+
],
|
|
68
|
+
npm_scope: Annotated[str | None, Option(help="npm scope composing the UPM package identity")] = None,
|
|
69
|
+
license_spdx: Annotated[str | None, Option(help="SPDX license id written to package.json")] = None,
|
|
70
|
+
repository_url: Annotated[str | None, Option(help="git repository URL written to package.json")] = None,
|
|
71
|
+
project: Annotated[str | None, Option(help="Generate only this project, as keyed in the config")] = None,
|
|
72
|
+
client: Annotated[str | None, Option(help="Generate only this client generator")] = None,
|
|
73
|
+
no_cache: Annotated[
|
|
74
|
+
bool, Option("--no-cache", help="Regenerate even when the committed spec is unchanged")
|
|
75
|
+
] = False,
|
|
76
|
+
root: Annotated[Path, Option(help="Repository root the project paths resolve against")] = Path(),
|
|
77
|
+
) -> None:
|
|
78
|
+
projects: dict[str, list[str]] = json.loads(config.read_text(encoding="utf-8"))
|
|
79
|
+
generate_projects(
|
|
80
|
+
projects,
|
|
81
|
+
root_name=root_name,
|
|
82
|
+
generated_root=generated_root,
|
|
83
|
+
dump_spec=SpecProducer(spec_command),
|
|
84
|
+
npm_scope=npm_scope,
|
|
85
|
+
license_spdx=license_spdx,
|
|
86
|
+
repository_url=repository_url,
|
|
87
|
+
project=project,
|
|
88
|
+
client=client,
|
|
89
|
+
no_cache=no_cache,
|
|
90
|
+
root=root,
|
|
91
|
+
)
|
openapi_client_codegen/client.py
CHANGED
|
@@ -4,7 +4,7 @@ from pathlib import Path
|
|
|
4
4
|
from shutil import copytree
|
|
5
5
|
from tempfile import NamedTemporaryFile, TemporaryDirectory
|
|
6
6
|
|
|
7
|
-
from bashrun import bash
|
|
7
|
+
from bashrun.bash import bash
|
|
8
8
|
|
|
9
9
|
from .resources import CONFIGS_DIR, IGNORE_FILE, OPENAPI_GENERATOR_CLI_VERSION
|
|
10
10
|
from .naming import ClientNaming
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from tempfile import TemporaryDirectory
|
|
7
|
+
|
|
8
|
+
from bashrun.bash import bash_output
|
|
9
|
+
|
|
10
|
+
from .client import generate_client
|
|
11
|
+
from .downgrade import downgrade_openapi_3_1_to_3_0
|
|
12
|
+
from .naming import DefaultNamingPolicy
|
|
13
|
+
from .templates import regenerate_templates
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SpecProducer:
|
|
17
|
+
def __init__(self, command: str) -> None:
|
|
18
|
+
self.command = command
|
|
19
|
+
|
|
20
|
+
def __call__(self, project: Path) -> str:
|
|
21
|
+
return bash_output(self.command, cwd=project)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def generate_projects(
|
|
25
|
+
projects: dict[str, list[str]],
|
|
26
|
+
root_name: str,
|
|
27
|
+
generated_root: Path,
|
|
28
|
+
dump_spec: Callable[[Path], str],
|
|
29
|
+
npm_scope: str | None = None,
|
|
30
|
+
license_spdx: str | None = None,
|
|
31
|
+
repository_url: str | None = None,
|
|
32
|
+
project: str | None = None,
|
|
33
|
+
client: str | None = None,
|
|
34
|
+
no_cache: bool = False,
|
|
35
|
+
root: Path = Path(),
|
|
36
|
+
) -> None:
|
|
37
|
+
root = root.resolve()
|
|
38
|
+
naming = DefaultNamingPolicy(root_name)
|
|
39
|
+
|
|
40
|
+
with TemporaryDirectory() as templates_directory_string:
|
|
41
|
+
templates_directory = Path(templates_directory_string)
|
|
42
|
+
regenerate_templates(templates_directory)
|
|
43
|
+
|
|
44
|
+
for project_name, clients in projects.items():
|
|
45
|
+
if project is not None and project != project_name:
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
openapi_spec = _produce_and_cache_spec(root / project_name, dump_spec, no_cache)
|
|
49
|
+
|
|
50
|
+
if openapi_spec is None:
|
|
51
|
+
continue
|
|
52
|
+
|
|
53
|
+
names = naming(project_name)
|
|
54
|
+
|
|
55
|
+
for client_name in clients:
|
|
56
|
+
if client is not None and client_name != client:
|
|
57
|
+
continue
|
|
58
|
+
|
|
59
|
+
generate_client(
|
|
60
|
+
openapi_spec,
|
|
61
|
+
client_name,
|
|
62
|
+
generated_root / client_name / names.base,
|
|
63
|
+
names,
|
|
64
|
+
templates_dir=templates_directory,
|
|
65
|
+
npm_scope=npm_scope,
|
|
66
|
+
license_spdx=license_spdx,
|
|
67
|
+
repository_url=repository_url,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def dump_openapi_spec(project: Path) -> str:
|
|
72
|
+
# CODEGEN=1 gates a service package's heavy imports so the app imports cleanly for the spec
|
|
73
|
+
# dump; it reaches the child through bashrun's per-call env overlay.
|
|
74
|
+
return bash_output("uv run --project . python -m src.dump_openapi", cwd=project, env={"CODEGEN": "1"})
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _produce_and_cache_spec(project: Path, dump_spec: Callable[[Path], str], no_cache: bool) -> str | None:
|
|
78
|
+
print(f"Producing OpenAPI spec for project: {project}")
|
|
79
|
+
|
|
80
|
+
openapi_json = json.loads(dump_spec(project))
|
|
81
|
+
downgrade_openapi_3_1_to_3_0(openapi_json)
|
|
82
|
+
openapi_spec = json.dumps(openapi_json, indent=2)
|
|
83
|
+
|
|
84
|
+
spec_path = project / "openapi.json"
|
|
85
|
+
|
|
86
|
+
if spec_path.exists():
|
|
87
|
+
old_spec = spec_path.read_text(encoding="utf-8")
|
|
88
|
+
|
|
89
|
+
if openapi_spec == old_spec and not no_cache:
|
|
90
|
+
print("OpenAPI spec unchanged, skipping client generation")
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
spec_path.write_text(openapi_spec, encoding="utf-8")
|
|
94
|
+
|
|
95
|
+
return openapi_spec
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: openapi-client-codegen
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: OpenAPI client-generation wrapper: Litestar spec dump, 3.1->3.0 downgrade, patched openapi-generator templates, Unity package metadata
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
License-File: NOTICE
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
openapi_client_codegen/__init__.py,sha256=
|
|
2
|
-
openapi_client_codegen/cli.py,sha256=
|
|
3
|
-
openapi_client_codegen/client.py,sha256=
|
|
1
|
+
openapi_client_codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
openapi_client_codegen/cli.py,sha256=2KZLSgzPrLc0Re2wtLrokO6QybFfIvqi2PbTBgpADrU,4145
|
|
3
|
+
openapi_client_codegen/client.py,sha256=rQ2j24MyV9mcaAXDCIVrXeJuiKjsufcw5_h7wEv-xr8,4638
|
|
4
4
|
openapi_client_codegen/downgrade.py,sha256=7cxQZJRgWR5lNpvyJT-6pg4lVj72LsMRfdYzsNF9DtY,5230
|
|
5
5
|
openapi_client_codegen/naming.py,sha256=c-GmnQk0zb2bsOi0gXOaUD5P_1c-dLfw8FaaNLQxb1I,742
|
|
6
|
+
openapi_client_codegen/orchestrator.py,sha256=83Kb1kT1R0fgfaq6MBA0HDBjw-L-Mo051cyqHROlSzI,3076
|
|
6
7
|
openapi_client_codegen/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
8
|
openapi_client_codegen/resources.py,sha256=Vavy0_zqot1eDrFpDJ_BT4Sbx47vh7zuclPjQtW3QMw,266
|
|
8
|
-
openapi_client_codegen/templates.py,sha256=
|
|
9
|
+
openapi_client_codegen/templates.py,sha256=ll3NQfdnpVgDOz4WJrEga5lHljEOOItSD1aeVP5Hp80,1198
|
|
9
10
|
openapi_client_codegen/unity.py,sha256=CLFoNjKJNq-InkaXoqUIJ3q293pWoaLdFNn39D-avgc,3292
|
|
10
11
|
openapi_client_codegen/_data/openapi-generator-ignore,sha256=EckS2MSJlfHzvb6rug11ionYoXnsXSJOkQGdHP6jz98,76
|
|
11
12
|
openapi_client_codegen/_data/configs/csharp.json,sha256=_uezrromftc2dNmDH6JLhKO3MswWXWIesBYOnv8SqFc,587
|
|
@@ -17,9 +18,9 @@ openapi_client_codegen/_data/templates-patches/csharp/0004-csharp-support-hybrid
|
|
|
17
18
|
openapi_client_codegen/_data/templates-patches/csharp/0006-csharp-streaming-download-response.patch,sha256=ma-QkJA94jmN3scbJifaVPMcg_NNZ8klVO2HUrLMz_Y,2417
|
|
18
19
|
openapi_client_codegen/_data/templates-patches/csharp/0007-csharp-model-default-initializers.patch,sha256=_fIimm7K0Gh1IYE3_fYyhUom_g-Bm4HlN9jLgsP27IE,862
|
|
19
20
|
openapi_client_codegen/_data/templates-patches/csharp/0008-csharp-redirect-documentation-file.patch,sha256=HQXDgm_CzFYK4oxOoqBkYAz4wrKKPlYpLgTNHI_0IYc,1363
|
|
20
|
-
openapi_client_codegen-0.1.
|
|
21
|
-
openapi_client_codegen-0.1.
|
|
22
|
-
openapi_client_codegen-0.1.
|
|
23
|
-
openapi_client_codegen-0.1.
|
|
24
|
-
openapi_client_codegen-0.1.
|
|
25
|
-
openapi_client_codegen-0.1.
|
|
21
|
+
openapi_client_codegen-0.1.2.dist-info/METADATA,sha256=YvyxD6QZlxa9-1lfX9xpttq4ZixWQQrqCSHp4N-X9KU,336
|
|
22
|
+
openapi_client_codegen-0.1.2.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
23
|
+
openapi_client_codegen-0.1.2.dist-info/entry_points.txt,sha256=mw8FL3PBefHSxRjhBJunBk9G1efUKgxNXwAlghbc31E,74
|
|
24
|
+
openapi_client_codegen-0.1.2.dist-info/licenses/LICENSE,sha256=RFhQPdSOiMTguUX7JSoIuTxA7HVzCbj_p8WU36HjUQQ,10947
|
|
25
|
+
openapi_client_codegen-0.1.2.dist-info/licenses/NOTICE,sha256=jvglZza3GCdN7v4_TLuXUqX9C_uABlwAKUkcIeKwk_8,26
|
|
26
|
+
openapi_client_codegen-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
{openapi_client_codegen-0.1.1.dist-info → openapi_client_codegen-0.1.2.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{openapi_client_codegen-0.1.1.dist-info → openapi_client_codegen-0.1.2.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{openapi_client_codegen-0.1.1.dist-info → openapi_client_codegen-0.1.2.dist-info}/licenses/NOTICE
RENAMED
|
File without changes
|