Skip to content

Commit

Permalink
fix formatting and python incompatibilty
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Apr 29, 2024
1 parent d9a73eb commit 1a08a4c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
14 changes: 7 additions & 7 deletions openapi_python_client/parser/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def location(self) -> str:

class OpenapiContext:
spec: osp.OpenAPI
spec_raw: dict[str, Any]
spec_raw: Dict[str, Any]

_component_cache: Dict[str, dict[str, Any]]
_component_cache: Dict[str, Dict[str, Any]]
security_schemes: Dict[str, SecurityScheme]

def __init__(self, config: Config, spec: osp.OpenAPI, spec_raw: dict[str, Any]) -> None:
def __init__(self, config: Config, spec: osp.OpenAPI, spec_raw: Dict[str, Any]) -> None:
self.config = config
self.spec = spec
self.spec_raw = spec_raw
Expand All @@ -62,14 +62,14 @@ def __init__(self, config: Config, spec: osp.OpenAPI, spec_raw: dict[str, Any])
registry = referencing.Registry().with_resource(resource=resource, uri="")
self._resolver = registry.resolver()

def _component_from_reference_url(self, url: str) -> dict[str, Any]:
def _component_from_reference_url(self, url: str) -> Dict[str, Any]:
if url in self._component_cache:
return self._component_cache[url]
obj = self._resolver.lookup(url).contents
self._component_cache[url] = obj
return obj

def _component_from_reference(self, ref: osp.Reference) -> dict[str, Any]:
def _component_from_reference(self, ref: osp.Reference) -> Dict[str, Any]:
url = ref.ref
return self._component_from_reference_url(url)

Expand All @@ -86,13 +86,13 @@ def schema_and_name_from_reference(self, ref: Union[osp.Reference, osp.Schema])
name = name or schema.title
return name, schema

def response_from_reference(self, ref: osp.Reference | osp.Response) -> osp.Response:
def response_from_reference(self, ref: Union[osp.Reference, osp.Response]) -> osp.Response:
if isinstance(ref, osp.Response):
return ref
return osp.Response.parse_obj(self._component_from_reference(ref))
# return cast(osp.Response, self._component_from_reference(ref))

def schema_from_reference(self, ref: osp.Reference | osp.Schema) -> osp.Schema:
def schema_from_reference(self, ref: Union[osp.Reference, osp.Schema]) -> osp.Schema:
if isinstance(ref, osp.Schema):
return ref
return osp.Schema.parse_obj(self._component_from_reference(ref))
Expand Down
4 changes: 2 additions & 2 deletions openapi_python_client/parser/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ def from_reference(
)


@dataclass(kw_only=True)
@dataclass()
class Endpoint:
method: TMethod
responses: dict[str, Response]
responses: Dict[str, Response]
path: str
parameters: Dict[str, Parameter]
path_table_name: str
Expand Down
24 changes: 12 additions & 12 deletions openapi_python_client/parser/prompts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Any
from typing import Any, Union

from openapi_python_client.parser.endpoints import Endpoint

Expand All @@ -9,11 +9,11 @@ class PropInfo:
json_path: str
is_optional: bool
types: list[str]
type_format: str | None
description: str | None
type_format: Union[str, None]
description: Union[str, None]
examples: list[Any]
maximum: float | None
default: Any | None
maximum: Union[float, None]
default: Union[Any, None]

def __str__(self) -> str:
ret = ""
Expand All @@ -37,8 +37,8 @@ def __str__(self) -> str:
@dataclass
class ResponseInfo:
status_code: str
description: str | None
schema_description: str | None
description: Union[str, None]
schema_description: Union[str, None]
properties: list[PropInfo]

def __str__(self) -> str:
Expand All @@ -60,11 +60,11 @@ class ParamInfo:
name: str
required: bool
types: list[str]
type_format: str | None
description: str | None
type_format: Union[str, None]
description: Union[str, None]
examples: list[Any]
maximum: float | None
default: Any | None
maximum: Union[float, None]
default: Union[Any, None]
location: str

def __str__(self) -> str:
Expand All @@ -91,7 +91,7 @@ def __str__(self) -> str:
class EndpointInfo:
path: str
method: str
description: str | None
description: Union[str, None]
response: ResponseInfo
parameters: list[ParamInfo]

Expand Down
6 changes: 3 additions & 3 deletions tests/parser/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest

from typing import Tuple
from openapi_python_client.parser.openapi_parser import OpenapiParser
from openapi_python_client.parser.models import SchemaWrapper
import openapi_schema_pydantic as osp
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_new_releases_list_property(spotify_parser: OpenapiParser) -> None:
],
)
def test_extract_payload_spotify(
endpoint_path: str, payload_path: tuple[str], payload_name: str, spotify_parser: OpenapiParser
endpoint_path: str, payload_path: Tuple[str], payload_name: str, spotify_parser: OpenapiParser
) -> None:
endpoints = spotify_parser.endpoints

Expand All @@ -81,7 +81,7 @@ def test_extract_payload_spotify(
],
)
def test_extract_payload_pokeapi(
endpoint_path: str, payload_path: tuple[str], payload_name: str, pokemon_parser: OpenapiParser
endpoint_path: str, payload_path: Tuple[str], payload_name: str, pokemon_parser: OpenapiParser
) -> None:
endpoints = pokemon_parser.endpoints

Expand Down
3 changes: 2 additions & 1 deletion tests/parser/test_paths.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from typing import List, Tuple
from openapi_python_client.parser.paths import table_names_from_paths, find_longest_common_prefix


Expand Down Expand Up @@ -68,6 +69,6 @@ def test_table_names_from_paths_no_prefix() -> None:
),
],
)
def test_find_longest_common_prefix(paths: list[tuple[str, ...]], expected: tuple[str, ...]) -> None:
def test_find_longest_common_prefix(paths: List[Tuple[str, ...]], expected: Tuple[str, ...]) -> None:
result = find_longest_common_prefix(paths)
assert result == expected
1 change: 1 addition & 0 deletions tests/test___main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# type: ignore


def test_main(mocker):
app = mocker.patch("openapi_python_client.cli.app")

Expand Down

0 comments on commit 1a08a4c

Please sign in to comment.