otterapi 0.1.8__tar.gz → 0.1.9__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.
- {otterapi-0.1.8 → otterapi-0.1.9}/.gitignore +1 -0
- otterapi-0.1.9/LICENSE +22 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/PKG-INFO +15 -13
- {otterapi-0.1.8 → otterapi-0.1.9}/README.md +10 -10
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/__init__.py +4 -4
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/cli.py +22 -23
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/_openapi_adapter.py +1 -2
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/ast_utils.py +18 -12
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/client.py +4 -28
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/codegen.py +208 -197
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/endpoints.py +47 -27
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/runtime/_export.py +49 -26
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/schema.py +11 -7
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/splitting.py +11 -7
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/types.py +64 -42
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/utils.py +6 -3
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/config.py +2 -1
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v2/v2.py +13 -8
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v3/v3.py +4 -2
- otterapi-0.1.9/otterapi/py.typed +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_codegen.py +2 -1
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_codegen_structure.py +1 -1
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_export.py +7 -1
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_extra_forbid.py +1 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_nullable_upgrade.py +5 -1
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_schema_constraints.py +6 -1
- {otterapi-0.1.8 → otterapi-0.1.9}/pyproject.toml +13 -16
- otterapi-0.1.8/otterapi/tests/test_regen_script.py +0 -50
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/__main__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/__init__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/_body_builder.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/_features.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/dataframes.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/export.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/pagination.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/runtime/__init__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/runtime/_client_stub.py.tpl +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/runtime/_concurrency.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/runtime/_dataframe.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/runtime/_models_mixin.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/runtime/_pagination.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/codegen/runtime/_retry.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/exceptions.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/__init__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/_lenient.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/constants.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v2/__init__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v2/spec.json +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v3/__init__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v3/spec.json +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v3_1/__init__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v3_1/spec.json +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v3_1/v3_1.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v3_2/__init__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v3_2/spec.json +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/v3_2/v3_2.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/openapi/warnings.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/__init__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/fixtures/__init__.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/constraints/spec.yaml +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/dataframe/config.yaml +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/dataframe/spec.yaml +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/discriminator/spec.yaml +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/paginated/config.yaml +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/fixtures/golden/paginated/spec.yaml +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_ast_utils.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_body_builder.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_client_retry_lifecycle.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_codegen_edge_cases.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_concurrency_runtime.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_config_errors.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_dataframe.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_discriminated_unions.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_exceptions.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_feature_modules.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_html_repr.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_init_scaffold.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_lenient.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_not_schema.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_openapi_adapter.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_openapi_support.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_openapi_upgrade.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_pagination.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_per_status_errors.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_public_api.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_recursive_schema.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_retry_runtime.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_runtime_guards.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_smoke_generated_client.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_splitting_config.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_splitting_integration.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_splitting_resolver.py +0 -0
- {otterapi-0.1.8 → otterapi-0.1.9}/otterapi/tests/test_splitting_tree.py +0 -0
otterapi-0.1.9/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dan Plischke
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: otterapi
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: A cute
|
|
5
|
-
Project-URL: Source, https://github.com/danplischke/
|
|
3
|
+
Version: 0.1.9
|
|
4
|
+
Summary: A cute otter that turns OpenAPI & Swagger specs into type-safe, async Python clients — powered by httpx and Pydantic.
|
|
5
|
+
Project-URL: Source, https://github.com/danplischke/otterapi
|
|
6
6
|
Author: Dan Plischke
|
|
7
7
|
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
8
9
|
Classifier: Development Status :: 3 - Alpha
|
|
9
10
|
Classifier: Operating System :: MacOS
|
|
10
11
|
Classifier: Operating System :: Microsoft :: Windows
|
|
@@ -16,6 +17,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
16
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
19
|
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
21
|
Classifier: Topic :: Utilities
|
|
20
22
|
Requires-Python: >=3.10
|
|
21
23
|
Requires-Dist: httpx~=0.28.1
|
|
@@ -30,7 +32,7 @@ Description-Content-Type: text/markdown
|
|
|
30
32
|
|
|
31
33
|
# 🦦 OtterAPI
|
|
32
34
|
|
|
33
|
-
> *A cute
|
|
35
|
+
> *A cute otter that turns OpenAPI & Swagger specs into type-safe, async Python clients — powered by httpx and Pydantic.*
|
|
34
36
|
|
|
35
37
|
**OtterAPI** is a sleek Python library that transforms OpenAPI specifications into clean, type-safe client code with Pydantic models and httpx-based HTTP clients.
|
|
36
38
|
|
|
@@ -75,14 +77,14 @@ otter generate
|
|
|
75
77
|
3. Use the generated code:
|
|
76
78
|
|
|
77
79
|
```python
|
|
78
|
-
from petstore_client import get_pet_by_id,
|
|
80
|
+
from petstore_client import get_pet_by_id, async_get_pet_by_id
|
|
79
81
|
|
|
80
82
|
# Synchronous usage
|
|
81
83
|
pet = get_pet_by_id(pet_id=123)
|
|
82
84
|
|
|
83
85
|
# Asynchronous usage
|
|
84
86
|
import asyncio
|
|
85
|
-
pet = asyncio.run(
|
|
87
|
+
pet = asyncio.run(async_get_pet_by_id(pet_id=123))
|
|
86
88
|
```
|
|
87
89
|
|
|
88
90
|
---
|
|
@@ -522,14 +524,14 @@ pagination:
|
|
|
522
524
|
### Usage
|
|
523
525
|
|
|
524
526
|
```python
|
|
525
|
-
from client import list_users_iter,
|
|
527
|
+
from client import list_users_iter, async_list_users_iter
|
|
526
528
|
|
|
527
529
|
# Iterate all users (handles pagination automatically)
|
|
528
530
|
for user in list_users_iter():
|
|
529
531
|
print(user.name)
|
|
530
532
|
|
|
531
533
|
# Async variant
|
|
532
|
-
async for user in
|
|
534
|
+
async for user in async_list_users_iter():
|
|
533
535
|
print(user.name)
|
|
534
536
|
```
|
|
535
537
|
|
|
@@ -556,7 +558,7 @@ documents:
|
|
|
556
558
|
| Original | Pandas | Polars |
|
|
557
559
|
|----------|--------|--------|
|
|
558
560
|
| `get_users()` | `get_users_df()` | `get_users_pl()` |
|
|
559
|
-
| `
|
|
561
|
+
| `async_get_users()` | `async_get_users_df()` | `async_get_users_pl()` |
|
|
560
562
|
|
|
561
563
|
### Usage
|
|
562
564
|
|
|
@@ -726,8 +728,8 @@ response_unwrap:
|
|
|
726
728
|
```python
|
|
727
729
|
from client import get_user, create_user, list_orders
|
|
728
730
|
|
|
729
|
-
# Async versions are prefixed with '
|
|
730
|
-
from client import
|
|
731
|
+
# Async versions are prefixed with 'async_'
|
|
732
|
+
from client import async_get_user, async_create_user, async_list_orders
|
|
731
733
|
|
|
732
734
|
# Sync
|
|
733
735
|
user = get_user(user_id=123)
|
|
@@ -736,7 +738,7 @@ user = get_user(user_id=123)
|
|
|
736
738
|
import asyncio
|
|
737
739
|
|
|
738
740
|
async def main():
|
|
739
|
-
user = await
|
|
741
|
+
user = await async_get_user(user_id=123)
|
|
740
742
|
|
|
741
743
|
asyncio.run(main())
|
|
742
744
|
```
|
|
@@ -762,7 +764,7 @@ client = Client(
|
|
|
762
764
|
user = client.get_user(user_id=123)
|
|
763
765
|
|
|
764
766
|
async def main():
|
|
765
|
-
user = await client.
|
|
767
|
+
user = await client.async_get_user(user_id=123)
|
|
766
768
|
```
|
|
767
769
|
|
|
768
770
|
### Working with Models
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 🦦 OtterAPI
|
|
2
2
|
|
|
3
|
-
> *A cute
|
|
3
|
+
> *A cute otter that turns OpenAPI & Swagger specs into type-safe, async Python clients — powered by httpx and Pydantic.*
|
|
4
4
|
|
|
5
5
|
**OtterAPI** is a sleek Python library that transforms OpenAPI specifications into clean, type-safe client code with Pydantic models and httpx-based HTTP clients.
|
|
6
6
|
|
|
@@ -45,14 +45,14 @@ otter generate
|
|
|
45
45
|
3. Use the generated code:
|
|
46
46
|
|
|
47
47
|
```python
|
|
48
|
-
from petstore_client import get_pet_by_id,
|
|
48
|
+
from petstore_client import get_pet_by_id, async_get_pet_by_id
|
|
49
49
|
|
|
50
50
|
# Synchronous usage
|
|
51
51
|
pet = get_pet_by_id(pet_id=123)
|
|
52
52
|
|
|
53
53
|
# Asynchronous usage
|
|
54
54
|
import asyncio
|
|
55
|
-
pet = asyncio.run(
|
|
55
|
+
pet = asyncio.run(async_get_pet_by_id(pet_id=123))
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
---
|
|
@@ -492,14 +492,14 @@ pagination:
|
|
|
492
492
|
### Usage
|
|
493
493
|
|
|
494
494
|
```python
|
|
495
|
-
from client import list_users_iter,
|
|
495
|
+
from client import list_users_iter, async_list_users_iter
|
|
496
496
|
|
|
497
497
|
# Iterate all users (handles pagination automatically)
|
|
498
498
|
for user in list_users_iter():
|
|
499
499
|
print(user.name)
|
|
500
500
|
|
|
501
501
|
# Async variant
|
|
502
|
-
async for user in
|
|
502
|
+
async for user in async_list_users_iter():
|
|
503
503
|
print(user.name)
|
|
504
504
|
```
|
|
505
505
|
|
|
@@ -526,7 +526,7 @@ documents:
|
|
|
526
526
|
| Original | Pandas | Polars |
|
|
527
527
|
|----------|--------|--------|
|
|
528
528
|
| `get_users()` | `get_users_df()` | `get_users_pl()` |
|
|
529
|
-
| `
|
|
529
|
+
| `async_get_users()` | `async_get_users_df()` | `async_get_users_pl()` |
|
|
530
530
|
|
|
531
531
|
### Usage
|
|
532
532
|
|
|
@@ -696,8 +696,8 @@ response_unwrap:
|
|
|
696
696
|
```python
|
|
697
697
|
from client import get_user, create_user, list_orders
|
|
698
698
|
|
|
699
|
-
# Async versions are prefixed with '
|
|
700
|
-
from client import
|
|
699
|
+
# Async versions are prefixed with 'async_'
|
|
700
|
+
from client import async_get_user, async_create_user, async_list_orders
|
|
701
701
|
|
|
702
702
|
# Sync
|
|
703
703
|
user = get_user(user_id=123)
|
|
@@ -706,7 +706,7 @@ user = get_user(user_id=123)
|
|
|
706
706
|
import asyncio
|
|
707
707
|
|
|
708
708
|
async def main():
|
|
709
|
-
user = await
|
|
709
|
+
user = await async_get_user(user_id=123)
|
|
710
710
|
|
|
711
711
|
asyncio.run(main())
|
|
712
712
|
```
|
|
@@ -732,7 +732,7 @@ client = Client(
|
|
|
732
732
|
user = client.get_user(user_id=123)
|
|
733
733
|
|
|
734
734
|
async def main():
|
|
735
|
-
user = await client.
|
|
735
|
+
user = await client.async_get_user(user_id=123)
|
|
736
736
|
```
|
|
737
737
|
|
|
738
738
|
### Working with Models
|
|
@@ -15,12 +15,12 @@ Quick Start:
|
|
|
15
15
|
>>> codegen.generate()
|
|
16
16
|
|
|
17
17
|
CLI Usage:
|
|
18
|
-
$
|
|
19
|
-
$
|
|
20
|
-
$
|
|
18
|
+
$ otter generate --source ./api.yaml --output ./client
|
|
19
|
+
$ otter init # Create a configuration file interactively
|
|
20
|
+
$ otter validate ./api.yaml # Validate an OpenAPI spec
|
|
21
21
|
|
|
22
22
|
For more information, see the documentation at:
|
|
23
|
-
https://github.com/
|
|
23
|
+
https://github.com/danplischke/otter
|
|
24
24
|
"""
|
|
25
25
|
|
|
26
26
|
from otterapi.codegen.codegen import Codegen
|
|
@@ -8,7 +8,7 @@ import json
|
|
|
8
8
|
import logging
|
|
9
9
|
import traceback
|
|
10
10
|
from pathlib import Path
|
|
11
|
-
from typing import Annotated
|
|
11
|
+
from typing import Annotated, Any
|
|
12
12
|
|
|
13
13
|
import typer
|
|
14
14
|
import yaml
|
|
@@ -32,14 +32,14 @@ error_console = Console(stderr=True)
|
|
|
32
32
|
def _commented_optional_sections() -> str:
|
|
33
33
|
"""Return a YAML block of commented-out optional config sections.
|
|
34
34
|
|
|
35
|
-
Appended to ``otter.yml`` by ``
|
|
35
|
+
Appended to ``otter.yml`` by ``otter init`` so users discover the
|
|
36
36
|
pagination / dataframe / export / module_split / response_unwrap
|
|
37
37
|
knobs by editing rather than by hunting through the README.
|
|
38
38
|
"""
|
|
39
39
|
return """
|
|
40
40
|
# ----------------------------------------------------------------------
|
|
41
41
|
# Optional sections -- uncomment to enable. See the README for details:
|
|
42
|
-
# https://github.com/danplischke/
|
|
42
|
+
# https://github.com/danplischke/otter
|
|
43
43
|
# ----------------------------------------------------------------------
|
|
44
44
|
|
|
45
45
|
# documents:
|
|
@@ -155,7 +155,7 @@ def _resolve_codegen_config(
|
|
|
155
155
|
except FileNotFoundError as e:
|
|
156
156
|
error_console.print(f'[red]Error:[/red] {e}')
|
|
157
157
|
error_console.print(
|
|
158
|
-
'\n[dim]Hint: Run [bold]
|
|
158
|
+
'\n[dim]Hint: Run [bold]otter init[/bold] to create a configuration file,[/dim]'
|
|
159
159
|
)
|
|
160
160
|
error_console.print(
|
|
161
161
|
'[dim]or use [bold]--source[/bold] and [bold]--output[/bold] options.[/dim]'
|
|
@@ -241,12 +241,12 @@ def generate(
|
|
|
241
241
|
directly via command-line options.
|
|
242
242
|
|
|
243
243
|
Examples:
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
244
|
+
otter generate
|
|
245
|
+
otter generate --config my-config.yaml
|
|
246
|
+
otter generate -c config.json
|
|
247
|
+
otter generate --source https://api.example.com/openapi.json --output ./client
|
|
248
|
+
otter generate -s ./api.yaml -o ./generated
|
|
249
|
+
otter generate -s ./api.yaml -o ./generated --lenient
|
|
250
250
|
"""
|
|
251
251
|
setup_logging(verbose, debug)
|
|
252
252
|
|
|
@@ -292,9 +292,9 @@ def init(
|
|
|
292
292
|
with all the necessary settings.
|
|
293
293
|
|
|
294
294
|
Examples:
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
295
|
+
otter init
|
|
296
|
+
otter init otter.yaml
|
|
297
|
+
otter init config.json --force
|
|
298
298
|
"""
|
|
299
299
|
config_path = Path(path)
|
|
300
300
|
|
|
@@ -347,9 +347,8 @@ def init(
|
|
|
347
347
|
content = json.dumps(config_data, indent=2)
|
|
348
348
|
else:
|
|
349
349
|
content = yaml.dump(config_data, default_flow_style=False, sort_keys=False)
|
|
350
|
-
#
|
|
351
|
-
#
|
|
352
|
-
# cross-referencing the README.
|
|
350
|
+
# Append commented-out scaffolds for the optional sections so users can
|
|
351
|
+
# discover them by editing instead of cross-referencing the README.
|
|
353
352
|
content += _commented_optional_sections()
|
|
354
353
|
|
|
355
354
|
config_path.write_text(content)
|
|
@@ -360,7 +359,7 @@ def init(
|
|
|
360
359
|
console.print(syntax)
|
|
361
360
|
|
|
362
361
|
console.print(
|
|
363
|
-
f'\n[dim]Run [bold]
|
|
362
|
+
f'\n[dim]Run [bold]otter generate -c {path}[/bold] to generate code.[/dim]'
|
|
364
363
|
)
|
|
365
364
|
|
|
366
365
|
|
|
@@ -377,9 +376,9 @@ def _count_operations(paths) -> int:
|
|
|
377
376
|
return operations
|
|
378
377
|
|
|
379
378
|
|
|
380
|
-
def _summarize_schema(schema) -> dict[str,
|
|
379
|
+
def _summarize_schema(schema) -> dict[str, Any]:
|
|
381
380
|
"""Collect descriptive info (title, counts, ...) about a loaded schema."""
|
|
382
|
-
info: dict[str,
|
|
381
|
+
info: dict[str, Any] = {}
|
|
383
382
|
|
|
384
383
|
if schema.info:
|
|
385
384
|
info['title'] = schema.info.title
|
|
@@ -437,7 +436,7 @@ def _load_schema_for_validation(source: str, progress, task):
|
|
|
437
436
|
|
|
438
437
|
|
|
439
438
|
def _print_validation_report(
|
|
440
|
-
source: str, info: dict[str,
|
|
439
|
+
source: str, info: dict[str, Any], warnings: list[str], verbose: bool
|
|
441
440
|
) -> None:
|
|
442
441
|
"""Print the schema summary table and any operationId warnings."""
|
|
443
442
|
console.print(f'\n[green]✓[/green] Schema is valid: {source}\n')
|
|
@@ -473,9 +472,9 @@ def validate(
|
|
|
473
472
|
generating any code, reporting any errors or warnings found.
|
|
474
473
|
|
|
475
474
|
Examples:
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
475
|
+
otter validate ./api.yaml
|
|
476
|
+
otter validate https://api.example.com/openapi.json
|
|
477
|
+
otter validate ./api.yaml --verbose
|
|
479
478
|
"""
|
|
480
479
|
with Progress(
|
|
481
480
|
SpinnerColumn(),
|
|
@@ -10,8 +10,7 @@ requires touching every codegen file.
|
|
|
10
10
|
that exposes the *intent* of what codegen wants from the parser
|
|
11
11
|
("paths()", "components_schema(name)", "info_title()") rather than raw
|
|
12
12
|
attribute access. New call sites in codegen should reach for the adapter
|
|
13
|
-
first; existing direct uses can migrate incrementally as touched
|
|
14
|
-
and tracked in issue #3, item 10).
|
|
13
|
+
first; existing direct uses can migrate incrementally as touched.
|
|
15
14
|
|
|
16
15
|
Keeping this minimal on purpose: the goal is to *establish the seam*, not
|
|
17
16
|
to wholesale-translate every operation. Each method lands as a real
|
|
@@ -6,7 +6,8 @@ and utilities for collecting and organizing imports during code generation.
|
|
|
6
6
|
|
|
7
7
|
import ast
|
|
8
8
|
import sys
|
|
9
|
-
from collections.abc import Iterable
|
|
9
|
+
from collections.abc import Iterable, Sequence
|
|
10
|
+
from typing import cast
|
|
10
11
|
|
|
11
12
|
__all__ = [
|
|
12
13
|
# AST helpers
|
|
@@ -83,7 +84,12 @@ def _ann_assign(
|
|
|
83
84
|
"""Build ``target: annotation = value``."""
|
|
84
85
|
if isinstance(target, ast.Name):
|
|
85
86
|
target = ast.Name(id=target.id, ctx=ast.Store())
|
|
86
|
-
return ast.AnnAssign(
|
|
87
|
+
return ast.AnnAssign(
|
|
88
|
+
target=cast('ast.Name | ast.Attribute | ast.Subscript', target),
|
|
89
|
+
annotation=annotation,
|
|
90
|
+
value=value,
|
|
91
|
+
simple=1,
|
|
92
|
+
)
|
|
87
93
|
|
|
88
94
|
|
|
89
95
|
def _assign(target: ast.expr, value: ast.expr) -> ast.Assign:
|
|
@@ -124,9 +130,9 @@ def _func(
|
|
|
124
130
|
args: list[ast.arg],
|
|
125
131
|
body: list[ast.stmt],
|
|
126
132
|
returns: ast.expr | None = None,
|
|
127
|
-
kwargs: ast.arg = None,
|
|
128
|
-
kwonlyargs:
|
|
129
|
-
kw_defaults:
|
|
133
|
+
kwargs: ast.arg | None = None,
|
|
134
|
+
kwonlyargs: Sequence[ast.arg] | None = None,
|
|
135
|
+
kw_defaults: Sequence[ast.expr | None] | None = None,
|
|
130
136
|
) -> ast.FunctionDef:
|
|
131
137
|
return ast.FunctionDef(
|
|
132
138
|
name=name,
|
|
@@ -134,8 +140,8 @@ def _func(
|
|
|
134
140
|
posonlyargs=[],
|
|
135
141
|
args=args,
|
|
136
142
|
kwarg=kwargs,
|
|
137
|
-
kwonlyargs=kwonlyargs
|
|
138
|
-
kw_defaults=kw_defaults
|
|
143
|
+
kwonlyargs=list(kwonlyargs) if kwonlyargs else [],
|
|
144
|
+
kw_defaults=list(kw_defaults) if kw_defaults else [],
|
|
139
145
|
defaults=[],
|
|
140
146
|
),
|
|
141
147
|
body=body,
|
|
@@ -149,9 +155,9 @@ def _async_func(
|
|
|
149
155
|
args: list[ast.arg],
|
|
150
156
|
body: list[ast.stmt],
|
|
151
157
|
returns: ast.expr | None = None,
|
|
152
|
-
kwargs: ast.arg = None,
|
|
153
|
-
kwonlyargs:
|
|
154
|
-
kw_defaults:
|
|
158
|
+
kwargs: ast.arg | None = None,
|
|
159
|
+
kwonlyargs: Sequence[ast.arg] | None = None,
|
|
160
|
+
kw_defaults: Sequence[ast.expr | None] | None = None,
|
|
155
161
|
) -> ast.AsyncFunctionDef:
|
|
156
162
|
return ast.AsyncFunctionDef(
|
|
157
163
|
name=name,
|
|
@@ -159,8 +165,8 @@ def _async_func(
|
|
|
159
165
|
posonlyargs=[],
|
|
160
166
|
args=args,
|
|
161
167
|
kwarg=kwargs,
|
|
162
|
-
kwonlyargs=kwonlyargs
|
|
163
|
-
kw_defaults=kw_defaults
|
|
168
|
+
kwonlyargs=list(kwonlyargs) if kwonlyargs else [],
|
|
169
|
+
kw_defaults=list(kw_defaults) if kw_defaults else [],
|
|
164
170
|
defaults=[],
|
|
165
171
|
),
|
|
166
172
|
body=body,
|
|
@@ -6,9 +6,7 @@ HTTP client injection support.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
import ast
|
|
9
|
-
from dataclasses import dataclass, field
|
|
10
9
|
from importlib.resources import files
|
|
11
|
-
from typing import TYPE_CHECKING
|
|
12
10
|
|
|
13
11
|
from otterapi.codegen.ast_utils import (
|
|
14
12
|
ImportDict,
|
|
@@ -20,33 +18,11 @@ from otterapi.codegen.ast_utils import (
|
|
|
20
18
|
_subscript,
|
|
21
19
|
_union_expr,
|
|
22
20
|
)
|
|
23
|
-
from otterapi.codegen.dataframes import DataFrameMethodConfig
|
|
24
|
-
|
|
25
|
-
if TYPE_CHECKING:
|
|
26
|
-
from otterapi.codegen.types import Parameter, RequestBodyInfo, ResponseInfo, Type
|
|
27
21
|
|
|
28
22
|
# Prefix used when building `f'HTTP {status_code} ...'` error messages in generated code
|
|
29
23
|
_HTTP_ERROR_PREFIX = 'HTTP '
|
|
30
24
|
|
|
31
25
|
|
|
32
|
-
@dataclass
|
|
33
|
-
class EndpointInfo:
|
|
34
|
-
"""Information about an endpoint for client method generation."""
|
|
35
|
-
|
|
36
|
-
name: str
|
|
37
|
-
async_name: str
|
|
38
|
-
method: str
|
|
39
|
-
path: str
|
|
40
|
-
parameters: list['Parameter'] | None
|
|
41
|
-
request_body: 'RequestBodyInfo | None'
|
|
42
|
-
response_type: 'Type | None'
|
|
43
|
-
response_infos: list['ResponseInfo'] | None
|
|
44
|
-
description: str | None
|
|
45
|
-
dataframe_config: DataFrameMethodConfig = field(
|
|
46
|
-
default_factory=DataFrameMethodConfig
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
|
|
50
26
|
def generate_api_error_class() -> ast.ClassDef:
|
|
51
27
|
"""Generate the BaseAPIError exception class for detailed error handling.
|
|
52
28
|
|
|
@@ -914,7 +890,7 @@ def _build_lifecycle_methods() -> list[ast.stmt]:
|
|
|
914
890
|
body: list[ast.stmt],
|
|
915
891
|
extra_args: list | None = None,
|
|
916
892
|
is_async: bool = False,
|
|
917
|
-
) -> ast.
|
|
893
|
+
) -> ast.FunctionDef | ast.AsyncFunctionDef:
|
|
918
894
|
cls = ast.AsyncFunctionDef if is_async else ast.FunctionDef
|
|
919
895
|
args_list = [_argument('self')] + (extra_args or [])
|
|
920
896
|
return cls(
|
|
@@ -969,7 +945,7 @@ def _build_lifecycle_methods() -> list[ast.stmt]:
|
|
|
969
945
|
|
|
970
946
|
# __enter__(self): return self (no return annotation — inferred from body)
|
|
971
947
|
enter_method = _ctx_method('__enter__', [ast.Return(_name('self'))])
|
|
972
|
-
enter_method.returns = None
|
|
948
|
+
enter_method.returns = None
|
|
973
949
|
|
|
974
950
|
# __exit__(self, *args): self.close()
|
|
975
951
|
exit_method = _ctx_method(
|
|
@@ -986,7 +962,7 @@ def _build_lifecycle_methods() -> list[ast.stmt]:
|
|
|
986
962
|
aenter_method = _ctx_method(
|
|
987
963
|
'__aenter__', [ast.Return(_name('self'))], is_async=True
|
|
988
964
|
)
|
|
989
|
-
aenter_method.returns = None
|
|
965
|
+
aenter_method.returns = None
|
|
990
966
|
|
|
991
967
|
# __aexit__(self, *args): await self.aclose()
|
|
992
968
|
aexit_method = _ctx_method(
|
|
@@ -1358,7 +1334,7 @@ def _build_request_json_method(
|
|
|
1358
1334
|
)
|
|
1359
1335
|
|
|
1360
1336
|
# Build the request call with all parameters
|
|
1361
|
-
request_call = _call(
|
|
1337
|
+
request_call: ast.expr = _call(
|
|
1362
1338
|
func=_attr('self', request_method),
|
|
1363
1339
|
args=[_name('method'), _name('path')],
|
|
1364
1340
|
keywords=[
|