Skip to content

Commit

Permalink
small fixes and run isort
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed May 6, 2024
1 parent 6f63396 commit 0fb9d4b
Show file tree
Hide file tree
Showing 29 changed files with 82 additions and 93 deletions.
2 changes: 1 addition & 1 deletion openapi_python_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from jinja2 import BaseLoader, ChoiceLoader, Environment, FileSystemLoader, PackageLoader

from openapi_python_client import utils

from .config import Config
from .parser.openapi_parser import OpenapiParser
from .typing import TEndpointFilter


log = logging.getLogger(__name__)

__version__ = version(__package__)
Expand Down
6 changes: 3 additions & 3 deletions openapi_python_client/cli.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import codecs
import pathlib
from typing import Optional
from distutils.dir_util import copy_tree
from typing import Optional

import typer

from openapi_python_client import MetaType
from openapi_python_client.config import Config

from openapi_python_client.cli_endpoint_selection import questionary_endpoint_selection
from openapi_python_client.config import Config

app = typer.Typer()

Expand Down
9 changes: 5 additions & 4 deletions openapi_python_client/detectors/base_detector.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"""
Basic detector class
"""
from typing import Tuple, TYPE_CHECKING, Dict, Optional
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Dict, Optional, Tuple

import openapi_schema_pydantic as osp

if TYPE_CHECKING:
from openapi_python_client.parser.pagination import Pagination
from openapi_python_client.parser.endpoints import Response
from openapi_python_client.parser.context import OpenapiContext
from openapi_python_client.parser.endpoints import Response
from openapi_python_client.parser.models import DataPropertyPath, SchemaWrapper
from openapi_python_client.parser.pagination import Pagination
from openapi_python_client.parser.parameters import Parameter
from openapi_python_client.parser.models import SchemaWrapper, DataPropertyPath


class BaseDetector(ABC):
Expand Down
11 changes: 6 additions & 5 deletions openapi_python_client/detectors/default/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"""
Default open source detector
"""
from typing import Tuple, Union, Optional, Dict, List
from typing import Dict, List, Optional, Tuple, Union

from openapi_python_client.detectors.base_detector import BaseDetector
import openapi_schema_pydantic as osp
from openapi_python_client.parser.pagination import Pagination

from openapi_python_client.detectors.base_detector import BaseDetector
from openapi_python_client.parser.endpoints import Response
from openapi_python_client.parser.models import SchemaWrapper, DataPropertyPath
from openapi_python_client.parser.models import DataPropertyPath, SchemaWrapper
from openapi_python_client.parser.pagination import Pagination
from openapi_python_client.parser.parameters import Parameter
from openapi_python_client.parser.paths import get_path_parts, is_var_part

from .const import RE_MATCH_ALL, RE_OFFSET_PARAM, RE_LIMIT_PARAM, RE_TOTAL_PROPERTY, RE_CURSOR_PARAM, RE_NEXT_PROPERTY
from .const import RE_CURSOR_PARAM, RE_LIMIT_PARAM, RE_MATCH_ALL, RE_NEXT_PROPERTY, RE_OFFSET_PARAM, RE_TOTAL_PROPERTY


class DefaultDetector(BaseDetector):
Expand Down
4 changes: 2 additions & 2 deletions openapi_python_client/parser/context.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Dict, Union, Tuple, Optional, Any
from dataclasses import dataclass
from typing import Any, Dict, Optional, Tuple, Union

import openapi_schema_pydantic as osp
import referencing
import referencing.jsonschema

from openapi_python_client.detectors.base_detector import BaseDetector
from openapi_python_client.parser.config import Config
from openapi_python_client.utils import ClassName
from openapi_python_client.detectors.base_detector import BaseDetector

TComponentClass = Union[
osp.Schema,
Expand Down
3 changes: 1 addition & 2 deletions openapi_python_client/parser/credentials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Optional

from dataclasses import dataclass
from typing import Optional

from openapi_python_client.parser.context import OpenapiContext, SecurityScheme

Expand Down
14 changes: 6 additions & 8 deletions openapi_python_client/parser/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from __future__ import annotations

from typing import Optional, Literal, cast, Union, List, Dict, Iterable, Set

from dataclasses import dataclass, field
from typing import Dict, Iterable, List, Literal, Optional, Set, Union, cast

import openapi_schema_pydantic as osp

from openapi_python_client.parser.context import OpenapiContext
from openapi_python_client.parser.paths import table_names_from_paths, get_path_parts, is_var_part
from openapi_python_client.parser.models import SchemaWrapper, DataPropertyPath
from openapi_python_client.utils import PythonIdentifier
from openapi_python_client.parser.models import DataPropertyPath, SchemaWrapper
from openapi_python_client.parser.pagination import Pagination
from openapi_python_client.parser.parameters import Parameter
from openapi_python_client.parser.paths import get_path_parts, is_var_part, table_names_from_paths
from openapi_python_client.utils import PythonIdentifier

TMethod = Literal["GET", "POST", "PUT", "PATCH"]
Tree = Dict[str, Union["Endpoint", "Tree"]]
Expand Down Expand Up @@ -97,8 +96,7 @@ def parent(self, value: Optional["Endpoint"]) -> None:

@property
def primary_key(self) -> Optional[str]:
payload = self.payload
return payload.schema.primary_key if payload else None
return self.payload.schema.primary_key if self.payload else None

@property
def path_parts(self) -> List[str]:
Expand Down Expand Up @@ -142,7 +140,7 @@ def table_name(self) -> str:

@property
def data_json_path(self) -> str:
return (self.payload.json_path if self.payload else "") or "$"
return self.payload.json_path if (self.payload and self.payload.json_path) else "$"

@property
def transformer(self) -> Optional[TransformerSetting]:
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/parser/info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Optional, List
from dataclasses import dataclass
from typing import List, Optional

import openapi_schema_pydantic as osp

Expand Down
27 changes: 14 additions & 13 deletions openapi_python_client/parser/models.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
from __future__ import annotations

import re
from dataclasses import dataclass, field
from itertools import chain
from typing import (
Literal,
TYPE_CHECKING,
Optional,
Union,
List,
TypeVar,
Any,
Dict,
Iterable,
Iterator,
List,
Literal,
Optional,
Sequence,
cast,
Tuple,
Dict,
Iterator,
TypeVar,
Union,
cast,
)
from itertools import chain
from dataclasses import dataclass, field
import re

import openapi_schema_pydantic as osp
from dlt.common.utils import digest128

import openapi_schema_pydantic as osp
from openapi_python_client.parser.types import DataType, TOpenApiType
from openapi_python_client.parser.properties.converter import convert
from openapi_python_client.parser.types import DataType, TOpenApiType
from openapi_python_client.utils import unique_list

if TYPE_CHECKING:
Expand Down
12 changes: 6 additions & 6 deletions openapi_python_client/parser/openapi_parser.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import json
import logging
import mimetypes
from pathlib import Path
from typing import Any, Dict, Iterator, Optional, Union
import httpcore
from urllib.parse import urlparse
import logging

import httpcore
import httpx
import openapi_schema_pydantic as osp
from yaml import BaseLoader
import yaml
from yaml import BaseLoader

from openapi_python_client.detectors.base_detector import BaseDetector
from openapi_python_client.parser.config import Config
from openapi_python_client.parser.context import OpenapiContext
from openapi_python_client.parser.credentials import CredentialsProperty
from openapi_python_client.parser.endpoints import EndpointCollection
from openapi_python_client.parser.config import Config
from openapi_python_client.parser.info import OpenApiInfo
from openapi_python_client.parser.credentials import CredentialsProperty
from openapi_python_client.detectors.base_detector import BaseDetector

log = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions openapi_python_client/parser/pagination.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, List, Dict, Union

from typing import TYPE_CHECKING, Dict, List, Union

if TYPE_CHECKING:
from openapi_python_client.parser.endpoints import Parameter
Expand Down
15 changes: 8 additions & 7 deletions openapi_python_client/parser/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import openapi_schema_pydantic as osp

from openapi_python_client.utils import PythonIdentifier
from openapi_python_client.parser.models import SchemaWrapper, TSchemaType, DataPropertyPath
from openapi_python_client.parser.types import DataType, compare_openapi_types
from openapi_python_client.parser.context import OpenapiContext
from openapi_python_client.parser.models import DataPropertyPath, SchemaWrapper, TSchemaType
from openapi_python_client.parser.types import compare_openapi_types
from openapi_python_client.utils import PythonIdentifier

TParamIn = Literal["query", "header", "path", "cookie"]

Expand Down Expand Up @@ -43,10 +43,6 @@ def nullable(self) -> bool:
def maximum(self) -> Optional[float]:
return self.schema.maximum

@property
def type_hint(self) -> str:
return DataType.from_schema(self.schema, required=self.required).type_hint

def _matches_type(self, schema: SchemaWrapper) -> bool:
return compare_openapi_types(self.types, self.type_format, schema.types, schema.type_format)

Expand All @@ -68,6 +64,11 @@ def find_input_property(self, schema: SchemaWrapper, fallback: Optional[str] = N
@classmethod
def from_reference(cls, param_ref: Union[osp.Reference, osp.Parameter], context: OpenapiContext) -> "Parameter":
osp_param = context.parameter_from_reference(param_ref)

# if there is no schema attached, fall back to string
if not osp_param.param_schema:
osp_param.param_schema = osp.Schema(type="string")

schema = SchemaWrapper.from_reference(osp_param.param_schema, context)
description = param_ref.description or osp_param.description or schema.description
location = osp_param.param_in
Expand Down
3 changes: 1 addition & 2 deletions openapi_python_client/parser/paths.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Iterable, Dict, Tuple, List

import os.path
from typing import Dict, Iterable, List, Tuple


def table_names_from_paths(paths: Iterable[str]) -> Dict[str, str]:
Expand Down
4 changes: 2 additions & 2 deletions openapi_python_client/parser/types.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Literal, TYPE_CHECKING, Dict, Optional, List
from typing import TYPE_CHECKING, Dict, List, Literal, Optional

if TYPE_CHECKING:
from openapi_python_client.parser.models import SchemaWrapper, Property
from openapi_python_client.parser.models import Property, SchemaWrapper


TOpenApiType = Literal["boolean", "object", "array", "number", "string", "integer"]
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/typing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Set, TYPE_CHECKING
from typing import TYPE_CHECKING, Callable, Set

if TYPE_CHECKING:
from openapi_python_client.parser.endpoints import EndpointCollection
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from email.message import Message
from keyword import iskeyword
from typing import Any, List, Sequence, Dict, Iterable, TypeVar
from typing import Any, Dict, Iterable, List, Sequence, TypeVar

DELIMITERS = r"\. _-"

Expand Down
1 change: 0 additions & 1 deletion tests/cases/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from typing import Iterable


ORIGINAL_SPECS_FOLDERS = "./tests/cases/original_specs"
TEST_SPECS_FOLDER = "./tests/cases/test_specs"
REPO_SPECS_FOLDER = "./tests/cases/specs_repo/Open-api-spec"
Expand Down
6 changes: 0 additions & 6 deletions tests/cases/test_specs/transformer_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ paths:
- name: collection_id
in: path
required: true
schema:
anyOf:
- type: string
format: uuid
- type: 'null'
title: Organization Id
responses:
'200':
description: "OK"
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/test_auth_cases.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tests.e2e.utils import get_dict_from_open_api, get_source_from_open_api
from tests.cases import get_auth_case_path
from tests.e2e.utils import get_dict_from_open_api, get_source_from_open_api


def test_bearer_auth() -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/test_json_paths.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Dict, Any
from typing import Any, Dict

import pytest

from tests.e2e.utils import get_source_from_open_api, get_dict_from_open_api
from tests.cases import get_test_case_path
from tests.e2e.utils import get_dict_from_open_api, get_source_from_open_api


@pytest.fixture(scope="module")
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/test_museums_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#
import pytest

from tests.e2e.utils import get_dict_from_open_api, get_source_from_open_api
from tests.cases import get_test_case_path
from tests.e2e.utils import get_dict_from_open_api, get_source_from_open_api


@pytest.mark.skip
Expand Down
5 changes: 1 addition & 4 deletions tests/e2e/test_original_specs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pytest


from tests.e2e.utils import get_source_from_open_api
from tests.cases import all_local_original_specs, all_repo_original_specs
from tests.e2e.utils import get_source_from_open_api


@pytest.mark.slow
Expand All @@ -21,8 +20,6 @@ def test_local_original_specs(case: str) -> None:
all_repo_original_specs(),
)
def test_repo_original_specs(case: str) -> None:
if "airport_web" in case:
pytest.skip("Fix later")
if "amazon_kenisis" in case:
pytest.skip("Fix later")
source = get_source_from_open_api(case)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/test_paginator_cases.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Dict, Any
from typing import Any, Dict

import pytest

from tests.e2e.utils import get_source_from_open_api, get_dict_from_open_api
from tests.cases import get_test_case_path
from tests.e2e.utils import get_dict_from_open_api, get_source_from_open_api


@pytest.fixture(scope="module")
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/test_pokemon_cases.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Test different iterations of pokemon
#
from tests.e2e.utils import get_dict_from_open_api, get_source_from_open_api
from tests.cases import get_test_case_path
from tests.e2e.utils import get_dict_from_open_api, get_source_from_open_api


def test_simple_poke_load() -> None:
Expand Down
Loading

0 comments on commit 0fb9d4b

Please sign in to comment.