Skip to content

Commit 98fd57d

Browse files
committed
Updated
1 parent a4ea424 commit 98fd57d

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ format:
1717

1818
# all tests excluding the checks on e2e tests
1919
test:
20-
poetry run python dlt_init_openapi/utils/update_rest_api.py
2120
poetry run pytest tests --ignore=tests/e2e
2221

2322
# test without running all the specs through a source

dlt_init_openapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Generate modern Python clients from OpenAPI """
1+
"""Generate modern Python clients from OpenAPI"""
22

33
from enum import Enum
44
from importlib.metadata import version

dlt_init_openapi/parser/properties/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Utils for converting default values into valid Python """
1+
"""Utils for converting default values into valid Python"""
22

33
__all__ = ["convert", "convert_chain"]
44

dlt_init_openapi/renderer/default/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Default renderer
33
"""
44

5+
import pathlib
56
import shutil
67
import subprocess
78

@@ -13,6 +14,10 @@
1314
from dlt_init_openapi.renderer.base_renderer import BaseRenderer
1415
from dlt_init_openapi.utils import misc
1516

17+
# Import REST_API_SOURCE_LOCATION separately to avoid mypy issues
18+
REST_API_SOURCE_LOCATION = str(pathlib.Path(__file__).parent.parent.parent.resolve() / "rest_api")
19+
20+
1621
FILE_ENCODING = "utf-8"
1722
TEMPLATE_FILTERS = {
1823
"snakecase": misc.snake_case,
@@ -67,6 +72,9 @@ def run(self, openapi: OpenapiParser, dry: bool = False) -> None:
6772
self._build_meta_files()
6873
self._run_post_hooks()
6974

75+
# copy rest api source into project dir
76+
shutil.copytree(REST_API_SOURCE_LOCATION, str(self.config.project_dir / "rest_api"))
77+
7078
def _build_meta_files(self) -> None:
7179
requirements_template = self.env.get_template("requirements.txt.j2")
7280
req_path = self.config.project_dir / "requirements.txt"

dlt_init_openapi/utils/paths.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os.path
21
from typing import Dict, Iterable, List, Optional, Tuple
32

43

@@ -15,12 +14,23 @@ def table_names_from_paths(paths: Iterable[str]) -> Dict[str, str]:
1514
# Remove common prefix for endpoints. For example all paths might
1615
# start with /api/v2 and we don't want this to be part of the name
1716
paths = list(paths)
18-
if not (paths := list(paths)):
17+
if not paths:
1918
return {}
2019

21-
# normalize paths
22-
api_prefix = os.path.commonpath(paths)
23-
norm_paths = [p.removeprefix(api_prefix) for p in paths]
20+
# Get path parts for all paths
21+
path_parts = [tuple(get_path_parts(path)) for path in paths]
22+
# Find the longest common prefix
23+
common_prefix = find_longest_common_prefix(path_parts)
24+
# Remove the common prefix from each path
25+
norm_paths = []
26+
for path, parts in zip(paths, path_parts):
27+
if common_prefix:
28+
# Remove the common prefix parts
29+
remaining_parts = parts[len(common_prefix) :]
30+
norm_path = "/" + "/".join(remaining_parts) if remaining_parts else "/"
31+
else:
32+
norm_path = path
33+
norm_paths.append(norm_path)
2434

2535
# Get all path components without slashes and without {parameters}
2636
split_paths = [get_non_var_path_parts(path) for path in norm_paths]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jinja2 = "^3.0.0"
2929
typer = "^0.12.3"
3030
black = ">=23"
3131
isort = "^5.0.5"
32-
pydantic = "^1.6.1"
32+
pydantic = "^1.6.1, <2.0"
3333
httpx = ">=0.15.4,<0.25.0"
3434
autoflake = "^1.4 || ^2.0.0"
3535
requests = "^2.30.0"

tests/integration/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def get_source_or_dict_from_open_api(
4343
dict for further inspection
4444
"""
4545

46-
TOP = """
47-
# type: ignore
46+
TOP = """# type: ignore
4847
# flake8: noqa
4948
from typing import Any
5049
Oauth20Credentials = Any
@@ -64,6 +63,9 @@ def get_source_or_dict_from_open_api(
6463

6564
basename = os.path.basename(case).split(".")[0] + "_" + rt
6665

66+
# Ensure the LOCAL_DIR exists
67+
os.makedirs(LOCAL_DIR, exist_ok=True)
68+
6769
local = LOCAL_DIR + basename
6870
with open(LOCAL_DIR + "__init__.py", "w") as f:
6971
f.write("")

0 commit comments

Comments
 (0)