otterapi 0.0.3__py3-none-any.whl → 0.0.5__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.
- otterapi/__init__.py +0 -0
- otterapi/__main__.py +4 -0
- otterapi/cli.py +84 -0
- otterapi/codegen/__init__.py +0 -0
- otterapi/codegen/ast_utils.py +121 -0
- otterapi/codegen/endpoints.py +501 -0
- otterapi/codegen/generator.py +358 -0
- otterapi/codegen/openapi_processor.py +27 -0
- otterapi/codegen/type_generator.py +559 -0
- otterapi/codegen/utils.py +82 -0
- otterapi/config.py +74 -0
- {otterapi-0.0.3.dist-info → otterapi-0.0.5.dist-info}/METADATA +1 -1
- otterapi-0.0.5.dist-info/RECORD +16 -0
- otterapi-0.0.3.dist-info/RECORD +0 -5
- {otterapi-0.0.3.dist-info → otterapi-0.0.5.dist-info}/WHEEL +0 -0
- {otterapi-0.0.3.dist-info → otterapi-0.0.5.dist-info}/entry_points.txt +0 -0
otterapi/config.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
from pydantic_settings import BaseSettings
|
|
6
|
+
|
|
7
|
+
DEFAULT_FILENAMES = ['otter.yaml', 'otter.yml']
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DocumentConfig(BaseModel):
|
|
11
|
+
"""Represents a single document to be processed."""
|
|
12
|
+
|
|
13
|
+
source: str = Field(..., description='Path or URL to the OpenAPI document.')
|
|
14
|
+
|
|
15
|
+
base_url: str | None = Field(
|
|
16
|
+
None,
|
|
17
|
+
description='Optional base URL to resolve paths if no servers are defined in the OpenAPI document.',
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
output: str = Field(..., description='Output directory for the generated code.')
|
|
21
|
+
|
|
22
|
+
models_file: str | None = Field(
|
|
23
|
+
'models.py', description='Optional file name for generated models.'
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
models_import_path: str | None = Field(
|
|
27
|
+
None, description='Optional import path for generated models.'
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
endpoints_file: str | None = Field(
|
|
31
|
+
'endpoints.py', description='Optional file name for generated endpoints.'
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class CodegenConfig(BaseSettings):
|
|
36
|
+
documents: list[DocumentConfig] = Field(
|
|
37
|
+
..., description='List of OpenAPI documents to process.'
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
generate_endpoints: bool = Field(
|
|
41
|
+
True, description='Whether to generate models from the OpenAPI schemas.'
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def load_yaml(path: str | Path) -> dict:
|
|
46
|
+
import yaml
|
|
47
|
+
|
|
48
|
+
return yaml.load(Path(path).read_text(), Loader=yaml.FullLoader)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_config(path: str | None = None) -> CodegenConfig:
|
|
52
|
+
"""Load configuration from a file or return default config."""
|
|
53
|
+
if path:
|
|
54
|
+
return CodegenConfig.model_validate(load_yaml(path))
|
|
55
|
+
|
|
56
|
+
cwd = os.getcwd()
|
|
57
|
+
|
|
58
|
+
for filename in DEFAULT_FILENAMES:
|
|
59
|
+
path = Path(cwd) / filename
|
|
60
|
+
if path.exists():
|
|
61
|
+
return CodegenConfig.model_validate(load_yaml(path))
|
|
62
|
+
|
|
63
|
+
path = Path(os.getcwd()) / 'pyproject.toml'
|
|
64
|
+
|
|
65
|
+
if path.exists():
|
|
66
|
+
import tomllib
|
|
67
|
+
|
|
68
|
+
pyproject = tomllib.loads(path.read_text())
|
|
69
|
+
tools = pyproject.get('tool', {})
|
|
70
|
+
|
|
71
|
+
if 'otterapi' in tools:
|
|
72
|
+
return CodegenConfig.model_validate(tools['otterapi'])
|
|
73
|
+
|
|
74
|
+
raise FileNotFoundError('config not found')
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
README.md,sha256=ahWBisuW6qpU7SUSTe2gDZWTOVSFYqS2B4YYMjd0idM,625
|
|
2
|
+
otterapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
otterapi/__main__.py,sha256=jVpOa4WaSqM3912DD0GQ3gj7Jui_jgqo5zK7DnKUE58,67
|
|
4
|
+
otterapi/cli.py,sha256=dw-Pvcv5AqvJb8dWIg5-Wk4LBu6WRsxkkTYF3nxFUrA,2436
|
|
5
|
+
otterapi/config.py,sha256=eEVjHSJNDw1xsKicAySEOUdVHGxH9DEz5ZEoFEI2iEI,2098
|
|
6
|
+
otterapi/codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
otterapi/codegen/ast_utils.py,sha256=XYnu4WF-Ow1xjqVaeu_pKMKQ_FPOVBGPgUXrfPs-31o,2846
|
|
8
|
+
otterapi/codegen/endpoints.py,sha256=v4SseRv7bnMrzTJMbRf70wOCoI4ZOhItLW7F0iNg16M,15901
|
|
9
|
+
otterapi/codegen/generator.py,sha256=cRCWomte2zzShQfDuBeaAzsuFGPloYTWN4YU53-ct5g,13250
|
|
10
|
+
otterapi/codegen/openapi_processor.py,sha256=HtF4SGxmKor_vSRpN2zsjz3sAcj4oCHGJbZUBbOR3PM,1080
|
|
11
|
+
otterapi/codegen/type_generator.py,sha256=6U9OUBvBJ9lY2HjvAvJIRmsIpSu1V2D8DbZLpmIaigk,19997
|
|
12
|
+
otterapi/codegen/utils.py,sha256=s85oyOu9ZgDqDngoHWSpt5jQm_os2unZjx8TGi5fTpQ,2289
|
|
13
|
+
otterapi-0.0.5.dist-info/METADATA,sha256=P77pd8wmmmSX8kpISjSYRjeo5_dbLV4Z8JwugJqakFc,1686
|
|
14
|
+
otterapi-0.0.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
15
|
+
otterapi-0.0.5.dist-info/entry_points.txt,sha256=vRm02sAdS5QjrXjlKTIr7xKXw821MEQv2bRDp-gJuCE,48
|
|
16
|
+
otterapi-0.0.5.dist-info/RECORD,,
|
otterapi-0.0.3.dist-info/RECORD
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
README.md,sha256=ahWBisuW6qpU7SUSTe2gDZWTOVSFYqS2B4YYMjd0idM,625
|
|
2
|
-
otterapi-0.0.3.dist-info/METADATA,sha256=CFo7dPqzlvv9q0C0iMqnHRY2WGK5uITuurmphVZVIjI,1686
|
|
3
|
-
otterapi-0.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
-
otterapi-0.0.3.dist-info/entry_points.txt,sha256=vRm02sAdS5QjrXjlKTIr7xKXw821MEQv2bRDp-gJuCE,48
|
|
5
|
-
otterapi-0.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|