Skip to content

Commit cf1cd19

Browse files
committed
rm openapi-core
1 parent b7284e6 commit cf1cd19

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
from functools import lru_cache
21
from pathlib import Path
32

4-
import openapi_core # type: ignore[import-untyped]
5-
import yaml
6-
from openapi_core.schema.specs.models import ( # type: ignore[import-untyped]
7-
Spec as OpenApiSpecs,
8-
)
9-
103
from .._meta import api_version_prefix
114
from .._resources import webserver_resources
125

@@ -17,15 +10,3 @@ def get_openapi_specs_path(api_version_dir: str | None = None) -> Path:
1710

1811
oas_path: Path = webserver_resources.get_path(f"api/{api_version_dir}/openapi.yaml")
1912
return oas_path
20-
21-
22-
@lru_cache # required to boost tests speed, gains 3.5s per test
23-
def load_openapi_specs(spec_path: Path | None = None) -> OpenApiSpecs:
24-
if spec_path is None:
25-
spec_path = get_openapi_specs_path()
26-
27-
with spec_path.open() as fh:
28-
spec_dict = yaml.safe_load(fh)
29-
specs: OpenApiSpecs = openapi_core.create_spec(spec_dict, spec_path.as_uri())
30-
31-
return specs

services/web/server/tests/unit/conftest.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@
88
import json
99
import sys
1010
from collections.abc import Callable, Iterable
11+
from functools import lru_cache
1112
from pathlib import Path
1213
from typing import Any
1314
from unittest.mock import MagicMock
1415

16+
import jsonref
1517
import pytest
1618
import yaml
17-
from openapi_core.schema.specs.models import Spec as OpenApiSpecs
1819
from pytest_simcore.helpers.dict_tools import ConfigDict
1920
from pytest_simcore.helpers.webserver_projects import empty_project_data
20-
from simcore_service_webserver.rest._utils import (
21-
get_openapi_specs_path,
22-
load_openapi_specs,
23-
)
21+
from simcore_service_webserver.rest._utils import get_openapi_specs_path
2422

2523
CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
2624

@@ -83,7 +81,23 @@ def disable_gc_manual_guest_users(mocker):
8381
)
8482

8583

84+
@lru_cache # ANE: required to boost tests speed, gains 3.5s per test
85+
def _load_openapi_specs(spec_path: Path | None = None) -> dict:
86+
if spec_path is None:
87+
spec_path = get_openapi_specs_path()
88+
89+
with spec_path.open() as fh:
90+
spec_dict = yaml.safe_load(fh)
91+
92+
# SEE https://jsonref.readthedocs.io/en/latest/#lazy-load-and-load-on-repr
93+
openapi: dict = jsonref.replace_refs(
94+
spec_dict, base_uri=spec_path.as_uri(), lazy_load=True, merge_props=False
95+
)
96+
return openapi
97+
98+
8699
@pytest.fixture
87-
def openapi_specs(api_version_prefix) -> OpenApiSpecs:
100+
def openapi_specs(api_version_prefix) -> dict:
101+
88102
spec_path = get_openapi_specs_path(api_version_prefix)
89-
return load_openapi_specs(spec_path)
103+
return _load_openapi_specs(spec_path)

services/web/server/tests/unit/with_dbs/03/test__openapi_specs.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pytest
99
from aiohttp import web
1010
from faker import Faker
11-
from openapi_core.schema.specs.models import Spec as OpenApiSpecs
1211
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
1312
from pytest_simcore.helpers.typing_env import EnvVarsDict
1413
from simcore_service_webserver.application import create_application
@@ -61,17 +60,17 @@ def app(app_environment: EnvVarsDict) -> web.Application:
6160

6261

6362
@pytest.fixture
64-
def expected_openapi_entrypoints(openapi_specs: OpenApiSpecs) -> set[Entrypoint]:
63+
def expected_openapi_entrypoints(openapi_specs: dict) -> set[Entrypoint]:
6564
entrypoints: set[Entrypoint] = set()
6665

6766
# openapi-specifications, i.e. "contract"
68-
for path, path_obj in openapi_specs.paths.items():
69-
for operation, operation_obj in path_obj.operations.items():
67+
for path, path_obj in openapi_specs["paths"].items():
68+
for operation, operation_obj in path_obj.items():
7069
entrypoints.add(
7170
Entrypoint(
7271
method=operation.upper(),
7372
path=path,
74-
name=operation_obj.operation_id,
73+
name=operation_obj["operationId"],
7574
)
7675
)
7776
return entrypoints

0 commit comments

Comments
 (0)