openapi-client-codegen 0.1.0__tar.gz
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-0.1.0/.github/workflows/ci.yml +51 -0
- openapi_client_codegen-0.1.0/.gitignore +12 -0
- openapi_client_codegen-0.1.0/.python-version +1 -0
- openapi_client_codegen-0.1.0/AGENTS.md +56 -0
- openapi_client_codegen-0.1.0/CLAUDE.md +1 -0
- openapi_client_codegen-0.1.0/LICENSE +201 -0
- openapi_client_codegen-0.1.0/NOTICE +1 -0
- openapi_client_codegen-0.1.0/PKG-INFO +9 -0
- openapi_client_codegen-0.1.0/README.md +73 -0
- openapi_client_codegen-0.1.0/publish-config.json +11 -0
- openapi_client_codegen-0.1.0/pyproject.toml +37 -0
- openapi_client_codegen-0.1.0/ruff.toml +71 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/__init__.py +15 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/configs/csharp.json +24 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/configs/python.json +22 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/openapi-generator-ignore +3 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/templates-patches/csharp/0001-csharp-remove-errant-comma.patch +14 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/templates-patches/csharp/0002-csharp-models-required-only-constructors.patch +75 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/templates-patches/csharp/0003-csharp-httpclient-use-defaultT.patch +14 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/templates-patches/csharp/0004-csharp-support-hybrid-multipart-payloads.patch +144 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/templates-patches/csharp/0006-csharp-streaming-download-response.patch +34 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/templates-patches/csharp/0007-csharp-model-default-initializers.patch +13 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/_data/templates-patches/csharp/0008-csharp-redirect-documentation-file.patch +18 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/cli.py +53 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/client.py +115 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/downgrade.py +132 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/naming.py +26 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/py.typed +0 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/resources.py +8 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/templates.py +30 -0
- openapi_client_codegen-0.1.0/src/openapi_client_codegen/unity.py +75 -0
- openapi_client_codegen-0.1.0/tests/test_downgrade.py +68 -0
- openapi_client_codegen-0.1.0/tests/test_naming.py +19 -0
- openapi_client_codegen-0.1.0/tests/test_unity.py +68 -0
- openapi_client_codegen-0.1.0/uv.lock +222 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
check:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v5
|
|
18
|
+
|
|
19
|
+
- uses: astral-sh/setup-uv@v7
|
|
20
|
+
with:
|
|
21
|
+
enable-cache: true
|
|
22
|
+
|
|
23
|
+
- name: Lint
|
|
24
|
+
run: uv run ruff check .
|
|
25
|
+
|
|
26
|
+
- name: Format
|
|
27
|
+
run: uv run ruff format --check .
|
|
28
|
+
|
|
29
|
+
- name: Type check
|
|
30
|
+
run: uv run basedpyright
|
|
31
|
+
|
|
32
|
+
- name: Test
|
|
33
|
+
run: uv run pytest
|
|
34
|
+
|
|
35
|
+
publish:
|
|
36
|
+
needs: check
|
|
37
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
permissions:
|
|
40
|
+
contents: write
|
|
41
|
+
id-token: write
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/checkout@v5
|
|
44
|
+
|
|
45
|
+
# Workaround: fetch-tags is broken with shallow clones
|
|
46
|
+
- run: git fetch --tags origin
|
|
47
|
+
|
|
48
|
+
- uses: astral-sh/setup-uv@v7
|
|
49
|
+
|
|
50
|
+
- name: Publish
|
|
51
|
+
run: uvx --from git+https://github.com/outernet-foundation/pubpkg.git@ea2ecf35a93a3c6405b9430a651d2a7b3d2faa6c publish-packages --config publish-config.json
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# openapi-client-codegen
|
|
2
|
+
|
|
3
|
+
## What this is
|
|
4
|
+
|
|
5
|
+
`openapi-client-codegen` wraps [OpenAPI Generator](https://openapi-generator.tech/) to turn an OpenAPI schema into typed client packages — a Python (`httpx`) client and a Unity-consumable C# (`httpclient`) client. It owns every step that is generic across consumers: downgrading 3.1→3.0, authoring and patching the C# templates, running the generator, and writing the Unity package metadata. The caller owns what is inherently project-specific: **producing the OpenAPI spec** (however its app exposes one), which projects map to which clients, the package-name policy, and the output paths.
|
|
6
|
+
|
|
7
|
+
The package is `openapi_client_codegen` (src-layout under `src/openapi_client_codegen/`), renamed from `openapi-clientgen` before the first publish (operator, 2026-09-20 — no artifact carries the old name). Its Python dependencies are `bashrun` (the guardrailed subprocess wrapper) and `typer` (the thin CLI), both from PyPI — git-source pins only in scratch branches testing unreleased changes. At **runtime** it also needs **Java (JDK 11+)** and **`uvx`** on PATH — the generator itself runs as `uvx --from 'openapi-generator-cli[jdk4py]==<pin>' ...`.
|
|
8
|
+
|
|
9
|
+
## Release flow
|
|
10
|
+
|
|
11
|
+
Publishing rides `ci.yml`'s `publish` job on every push to `main` (gated on the check job): pubpkg — invoked uvx-isolated from a pinned git ref, never a project dependency (openapi-client-codegen sits inside pubpkg's transitive dependency graph; a project-level pubpkg edge is a resolver cycle) — computes the plan from the tag ledger and path-diff, patches the version ephemerally, and publishes to PyPI under OIDC trusted publishing (pending publisher bound to `ci.yml`, no environment). The committed `pyproject.toml` version is permanently the `0.0.0.dev0` sentinel; the `openapi-client-codegen-v*` tags are the version ledger (first release `0.1.0`, patch-auto thereafter). API-breaking changes ship with a manually bumped version — patch-auto assumes additive changes.
|
|
12
|
+
|
|
13
|
+
## Public API
|
|
14
|
+
|
|
15
|
+
`__init__` re-exports the surface; import from the package root.
|
|
16
|
+
|
|
17
|
+
| Symbol | Role |
|
|
18
|
+
|---|---|
|
|
19
|
+
| `downgrade_openapi_3_1_to_3_0(schema)` | In-place 3.1.0→3.0.3 fixup (openapi-generator rejects 3.1). Pure function. |
|
|
20
|
+
| `regenerate_templates(target_dir, extra_patches_dir=None)` | Author the C# templates into `target_dir/csharp` and apply the shipped (then optional extra) patches. |
|
|
21
|
+
| `generate_client(spec, generator, output_dir, names, templates_dir=None, extra_references=None, npm_scope=None, license_spdx=None, repository_url=None)` | Run the generator for one `(spec, generator)` and sync the result into `output_dir`. `templates_dir` is required for `csharp`. For csharp, `npm_scope` composes the UPM identity `{scope}.{base-minus-dashes}` (e.g. `org.outernet.placeframe.apiclient`); unset falls back to the legacy `org.nuget.{camel-lower}` identity. `license_spdx` / `repository_url` populate the manifest's `license` / `repository` fields when given. |
|
|
22
|
+
| `write_unity_package_metadata(package_dir, package_name, extra_references=None, npm_name=None, license_spdx=None, repository_url=None)` | Write `package.json` / `.asmdef` / `csc.rsp` / `Directory.Build.props`. Called by `generate_client` for csharp. |
|
|
23
|
+
| `DefaultNamingPolicy(root_name)` / `ClientNaming` / `NamingPolicy` | Package-name derivation. `DefaultNamingPolicy("placeframe")("docker/api")` → base `api-client`, dashed `placeframe-api-client`, underscored `placeframe_api_client`, camel `PlaceframeApiClient`. |
|
|
24
|
+
|
|
25
|
+
A consumer orchestrates: `regenerate_templates(tmp)` once, then per `(project, client)` produce the spec, `downgrade` it, and call `generate_client`. The generator version pin and the shipped configs/patches/ignore-file live in `src/openapi_client_codegen/_data/` (paths in `_data.py`).
|
|
26
|
+
|
|
27
|
+
## Constraints
|
|
28
|
+
|
|
29
|
+
### The C# template patches are path-generic and repo-independent
|
|
30
|
+
|
|
31
|
+
The shipped patches (`_data/templates-patches/csharp/00NN-*.patch`) carry generic `a/csharp/<path>` headers, not any consumer's repo layout. `regenerate_templates` applies them with `git apply -p1` and `cwd=target_dir`, which lands them on the freshly-authored tree **without needing a surrounding git repository** — `git apply` patches worktree files fine outside any repo as long as `--index` is not used. Patches apply in filename order (the `00NN` prefix is load-bearing: later patches depend on earlier hunks' context); `extra_patches_dir` patches apply after the shipped set.
|
|
32
|
+
|
|
33
|
+
To author a new patch: author the raw templates (`openapi-generator-cli author template -g csharp --library httpclient`) into a scratch dir, copy it, edit a `.mustache` in the copy, `git diff --no-index` the two trees, and normalize the diff's path headers to `csharp/<path>` so it applies under the same `-p1` convention.
|
|
34
|
+
|
|
35
|
+
### Generator env vars are passed per-call, never set at module level
|
|
36
|
+
|
|
37
|
+
`JAVA_OPTS=-Dlog.level=warn` (quiets the generator) is passed as `bash(..., env={"JAVA_OPTS": "-Dlog.level=warn"})` on the two `openapi-generator-cli` calls that need it, so it reaches only those child processes and never touches this process's `os.environ`. `bashrun`'s `env=` overlays the inherited environment for that one child (see its AGENTS.md), which is the whole point — the alternative, mutating the global `os.environ`, leaks the var into every later subprocess. This covers only the generator this package runs itself; a consumer's spec-production step owns its own environment (e.g. any import-gating flag its services read).
|
|
38
|
+
|
|
39
|
+
### The Unity reference set is coupled to the patched templates
|
|
40
|
+
|
|
41
|
+
`unity.write_unity_package_metadata` hardcodes the `.asmdef` base references `Newtonsoft.Json / Polly / JsonSubTypes`. These are exactly the runtime support the patched C# templates emit calls against (Polly retry, JsonSubTypes discriminators, Newtonsoft serialization). They travel with the patches as one unit; a consumer adds project-specific references via `extra_references`, it does not replace the base set.
|
|
42
|
+
|
|
43
|
+
`BASE_DEPENDENCIES` is the UPM dual of that reference set: the same three libraries expressed as `package.json` dependencies (Newtonsoft as the Unity-blessed `com.unity.nuget.newtonsoft-json`, the others as UnityNuGet `org.nuget.*` identities), as exact versions — UPM's package.json dependencies accept SemVer values only, no range syntax, and the resolver treats a value as a minimum, so consumer manifests carrying newer minors still resolve without conflict. It travels with `BASE_REFERENCES` — change one, change the other.
|
|
44
|
+
|
|
45
|
+
### The csproj ships in the package; MSBuild output is redirected around it
|
|
46
|
+
|
|
47
|
+
The generated `.csproj` stays inside the UPM package because it is the `dotnet pack` input for the nuget feed. To keep IDE builds from writing `bin/`/`obj/` into the package (Unity errors on the missing `.meta` files, and the npm tarball must not carry build output), `write_unity_package_metadata` writes a `Directory.Build.props` next to it that redirects `BaseIntermediateOutputPath` / `BaseOutputPath` two directories up — outside the package root under every consumption layout (repo checkout → client grouping dir; Unity PackageCache → `Library/`, which the asset importer ignores). The shipped template patch `0008` points the csproj's `DocumentationFile` at `$(BaseOutputPath)` for the same reason; `Directory.Build.props` is imported before the project body, so the property is visible at that evaluation point.
|
|
48
|
+
|
|
49
|
+
### What the consumer owns
|
|
50
|
+
|
|
51
|
+
The project→clients mapping, the naming policy, and the output paths are the consumer's. This package ships `DefaultNamingPolicy` as a convenience but defines no schema for the mapping file — the consumer iterates its own config and calls the API per entry. `NamingPolicy` is a `Protocol`; a consumer can supply any callable `(project: str) -> ClientNaming`.
|
|
52
|
+
|
|
53
|
+
## See also
|
|
54
|
+
|
|
55
|
+
- `README.md` — human-facing setup and usage.
|
|
56
|
+
- [`bashrun`](https://github.com/outernet-foundation/bashrun) — the subprocess wrapper this package shells out through.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright 2026 Tyler Hatch
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: openapi-client-codegen
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: OpenAPI client-generation wrapper: Litestar spec dump, 3.1->3.0 downgrade, patched openapi-generator templates, Unity package metadata
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
License-File: NOTICE
|
|
7
|
+
Requires-Python: >=3.13
|
|
8
|
+
Requires-Dist: bashrun>=0.1.0
|
|
9
|
+
Requires-Dist: typer>=0.17.4
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# openapi-client-codegen
|
|
2
|
+
|
|
3
|
+
Generate typed API clients from an OpenAPI schema. `openapi-client-codegen` wraps [OpenAPI Generator](https://openapi-generator.tech/): it downgrades OpenAPI 3.1→3.0 (the generator only accepts 3.0), authors and patches the C# templates, runs the generator, and writes Unity package metadata. It produces a Python (`httpx`) client and a Unity-consumable C# (`httpclient`) client.
|
|
4
|
+
|
|
5
|
+
The generic steps live here; the caller supplies the OpenAPI spec, the project→client mapping, the package-name policy, and the output paths. See [`AGENTS.md`](./AGENTS.md) for the API surface, the lib-owns/consumer-owns boundary, and the patch mechanism.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Python 3.13+ and [uv](https://docs.astral.sh/uv/)
|
|
10
|
+
- **Java (JDK 11+)** and **`uvx`** on PATH at runtime — the generator runs as `uvx --from 'openapi-generator-cli[jdk4py]==<pin>' ...`
|
|
11
|
+
|
|
12
|
+
## CLI
|
|
13
|
+
|
|
14
|
+
A thin CLI exposes the OpenAPI 3.1→3.0 downgrade and single-client generation:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
uv run openapi-client-codegen downgrade path/to/openapi.json # 3.1→3.0 in place
|
|
18
|
+
uv run openapi-client-codegen downgrade path/to/openapi.json out.json # write elsewhere
|
|
19
|
+
|
|
20
|
+
uv run openapi-client-codegen generate path/to/openapi.json generated/csharp/api-client \
|
|
21
|
+
--root-name myproject --project services/api \
|
|
22
|
+
--npm-scope org.example.myproject --license-spdx Apache-2.0 \
|
|
23
|
+
--repository-url https://github.com/org/repo.git
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Client generation itself is driven from Python (it needs the consumer's project map, naming policy, and output paths):
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import json
|
|
30
|
+
import tempfile
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
from openapi_client_codegen import (
|
|
34
|
+
DefaultNamingPolicy,
|
|
35
|
+
downgrade_openapi_3_1_to_3_0,
|
|
36
|
+
generate_client,
|
|
37
|
+
regenerate_templates,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
naming = DefaultNamingPolicy("myproject")
|
|
41
|
+
templates_dir = Path(tempfile.mkdtemp())
|
|
42
|
+
regenerate_templates(templates_dir)
|
|
43
|
+
|
|
44
|
+
# Produce the raw OpenAPI JSON however your app exposes it, then downgrade it.
|
|
45
|
+
schema = json.loads(my_openapi_spec_json())
|
|
46
|
+
downgrade_openapi_3_1_to_3_0(schema)
|
|
47
|
+
spec = json.dumps(schema, indent=2)
|
|
48
|
+
|
|
49
|
+
generate_client(spec, "python", Path("generated/python/api-client"), naming("services/api"))
|
|
50
|
+
generate_client(
|
|
51
|
+
spec, "csharp", Path("generated/csharp/api-client"), naming("services/api"), templates_dir=templates_dir
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Consuming from another repo
|
|
56
|
+
|
|
57
|
+
Install from PyPI:
|
|
58
|
+
|
|
59
|
+
```toml
|
|
60
|
+
[project]
|
|
61
|
+
dependencies = ["openapi-client-codegen>=0.1.0"]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`bashrun` resolves transitively. At **runtime** the generator also needs Java (JDK 11+) and `uvx` on PATH. To test an unreleased change, pin the repo at a git ref in a scratch branch instead (`openapi-client-codegen = { git = "…", rev = "<sha>" }` under `[tool.uv.sources]`) and drop the pin when the release lands.
|
|
65
|
+
|
|
66
|
+
## Development
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
uv run ruff check .
|
|
70
|
+
uv run ruff format --check .
|
|
71
|
+
uv run basedpyright
|
|
72
|
+
uv run pytest
|
|
73
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "openapi-client-codegen"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "OpenAPI client-generation wrapper: Litestar spec dump, 3.1->3.0 downgrade, patched openapi-generator templates, Unity package metadata"
|
|
5
|
+
requires-python = ">=3.13"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"bashrun>=0.1.0",
|
|
8
|
+
"typer>=0.17.4",
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
[dependency-groups]
|
|
12
|
+
dev = ["basedpyright>=1.39.10", "ruff>=0.14.11", "pytest>=8.0.0"]
|
|
13
|
+
|
|
14
|
+
[build-system]
|
|
15
|
+
requires = ["hatchling"]
|
|
16
|
+
build-backend = "hatchling.build"
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
openapi-client-codegen = "openapi_client_codegen.cli:app"
|
|
20
|
+
|
|
21
|
+
[tool.hatch.build.targets.wheel]
|
|
22
|
+
packages = ["src/openapi_client_codegen"]
|
|
23
|
+
include = [
|
|
24
|
+
"src/openapi_clientgen/py.typed",
|
|
25
|
+
"src/openapi_clientgen/_data/**",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[tool.uv.sources]
|
|
29
|
+
|
|
30
|
+
[tool.basedpyright]
|
|
31
|
+
venvPath = "."
|
|
32
|
+
venv = ".venv"
|
|
33
|
+
typeCheckingMode = "strict"
|
|
34
|
+
include = ["src", "tests"]
|
|
35
|
+
|
|
36
|
+
[tool.pytest.ini_options]
|
|
37
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
target-version = "py313"
|
|
2
|
+
line-length = 120
|
|
3
|
+
preview = true
|
|
4
|
+
|
|
5
|
+
[lint]
|
|
6
|
+
select = ["ALL"]
|
|
7
|
+
ignore = [
|
|
8
|
+
# ── Permanent ─────────────────────────────────────────────────────────
|
|
9
|
+
# Type annotations — basedpyright strict mode handles this
|
|
10
|
+
"ANN",
|
|
11
|
+
# No docstrings, no copyright headers
|
|
12
|
+
"D",
|
|
13
|
+
"DOC",
|
|
14
|
+
"CPY",
|
|
15
|
+
# TODO/FIXME comment formatting
|
|
16
|
+
"TD",
|
|
17
|
+
"FIX",
|
|
18
|
+
# Exception message ergonomics — literal-indirection and custom-class churn without benefit
|
|
19
|
+
"EM101",
|
|
20
|
+
"EM102",
|
|
21
|
+
"TRY003",
|
|
22
|
+
# Class attribute names never conflict with builtins via self.x
|
|
23
|
+
"A003",
|
|
24
|
+
# Function-size counters — C901 already covers structural complexity
|
|
25
|
+
"PLR0911",
|
|
26
|
+
"PLR0912",
|
|
27
|
+
"PLR0913",
|
|
28
|
+
"PLR0914",
|
|
29
|
+
"PLR0915",
|
|
30
|
+
"PLR0917",
|
|
31
|
+
# Typer's Option/Argument in argument defaults is its standard API pattern
|
|
32
|
+
"B008",
|
|
33
|
+
# Boolean parameters read fine as keyword-only flags here
|
|
34
|
+
"FBT001",
|
|
35
|
+
"FBT002",
|
|
36
|
+
"FBT003",
|
|
37
|
+
# Relative imports are the intra-package convention
|
|
38
|
+
"TID252",
|
|
39
|
+
# Formatter-owned; enforced by `ruff format`
|
|
40
|
+
"COM812",
|
|
41
|
+
"I001",
|
|
42
|
+
# Magic values in comparisons are readable in this CLI
|
|
43
|
+
"PLR2004",
|
|
44
|
+
# The formatter owns wrapping; long string literals and URLs stay on one line
|
|
45
|
+
"E501",
|
|
46
|
+
# src-layout tests need no __init__.py
|
|
47
|
+
"INP001",
|
|
48
|
+
# Runtime-used typing imports stay at module level
|
|
49
|
+
"TC001",
|
|
50
|
+
"TC002",
|
|
51
|
+
"TC003",
|
|
52
|
+
# Small literal tuples read fine in membership tests
|
|
53
|
+
"PLR6201",
|
|
54
|
+
|
|
55
|
+
# ── Deferred to PLE-248 — Enforce the deferred ruff rules
|
|
56
|
+
# https://linear.app/plerionplatforms/issue/PLE-248
|
|
57
|
+
# Mirrors placeframe's root ruff.toml transitional Ticket-N blocks; lifting
|
|
58
|
+
# a rule here should happen alongside lifting it from placeframe's ruff.toml.
|
|
59
|
+
"C901", # function too complex — Ticket 9
|
|
60
|
+
"PLR1702", # too many nested blocks — Ticket 9
|
|
61
|
+
|
|
62
|
+
# ── Deferred to PLE-336 — Replace print() with structured logging
|
|
63
|
+
# https://linear.app/plerionplatforms/issue/PLE-336
|
|
64
|
+
"T201", # print found
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
[lint.per-file-ignores]
|
|
68
|
+
"tests/**" = ["S101", "S404", "S607", "PLR6301"]
|
|
69
|
+
|
|
70
|
+
[lint.flake8-builtins]
|
|
71
|
+
ignorelist = ["id", "map"]
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"generatorName": "csharp",
|
|
3
|
+
"globalProperties": {
|
|
4
|
+
"apiTests": false,
|
|
5
|
+
"modelTests": false,
|
|
6
|
+
"modelDocs": false,
|
|
7
|
+
"apiDocs": false
|
|
8
|
+
},
|
|
9
|
+
"additionalProperties": {
|
|
10
|
+
"library": "httpclient",
|
|
11
|
+
"packageVersion": "0.1.0",
|
|
12
|
+
"targetFramework": "netstandard2.1",
|
|
13
|
+
"validatable": false,
|
|
14
|
+
"conditionalSerialization": true,
|
|
15
|
+
"nullableReferenceTypes": true,
|
|
16
|
+
"sortModelPropertiesByRequiredFlag": true,
|
|
17
|
+
"sortParamsByRequiredFlag": true,
|
|
18
|
+
"caseInsensitiveResponseHeaders": true,
|
|
19
|
+
"examples": false
|
|
20
|
+
},
|
|
21
|
+
"typeMappings": {
|
|
22
|
+
"number": "double"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"generatorName": "python",
|
|
3
|
+
"globalProperties": {
|
|
4
|
+
"apiTests": false,
|
|
5
|
+
"modelTests": false,
|
|
6
|
+
"modelDocs": false,
|
|
7
|
+
"apiDocs": false
|
|
8
|
+
},
|
|
9
|
+
"additionalProperties": {
|
|
10
|
+
"library": "httpx",
|
|
11
|
+
"packageVersion": "0.1.0",
|
|
12
|
+
"generateSourceCodeOnly": false,
|
|
13
|
+
"hideGenerationTimestamp": true,
|
|
14
|
+
"disallowAdditionalPropertiesIfNotPresent": false,
|
|
15
|
+
"mapNumberTo": "Union[StrictFloat, StrictInt]",
|
|
16
|
+
"useOneOfDiscriminatorLookup": false,
|
|
17
|
+
"examples": false
|
|
18
|
+
},
|
|
19
|
+
"typeMappings": {
|
|
20
|
+
"number": "float"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Fix errant comma in generated C# AnyOf classes
|
|
2
|
+
diff --git a/csharp/modelAnyOf.mustache b/csharp/modelAnyOf.mustache
|
|
3
|
+
index f3eac97..036b383 100644
|
|
4
|
+
--- a/csharp/modelAnyOf.mustache
|
|
5
|
+
+++ b/csharp/modelAnyOf.mustache
|
|
6
|
+
@@ -10,7 +10,7 @@
|
|
7
|
+
{{/vendorExtensions.x-com-visible}}
|
|
8
|
+
[JsonConverter(typeof({{classname}}JsonConverter))]
|
|
9
|
+
[DataContract(Name = "{{{name}}}")]
|
|
10
|
+
- {{>visibility}} partial class {{classname}} : AbstractOpenAPISchema, {{#lambda.joinWithComma}}{{#parent}}{{{.}}} {{/parent}}{{#equatable}}IEquatable<{{classname}}> {{/equatable}}{{#validatable}}IValidatableObject {{/validatable}}{{/lambda.joinWithComma}}
|
|
11
|
+
+ {{>visibility}} partial class {{classname}} : {{#lambda.joinWithComma}}AbstractOpenAPISchema {{#parent}}{{{.}}} {{/parent}}{{#equatable}}IEquatable<{{classname}}> {{/equatable}}{{#validatable}}IValidatableObject {{/validatable}}{{/lambda.joinWithComma}}
|
|
12
|
+
{
|
|
13
|
+
{{#isNullable}}
|
|
14
|
+
/// <summary>
|