Skip to content

Commit 8638424

Browse files
authored
Merge pull request #4 from mike-oakley/bluetech-fix-mypy
Fix mypy
2 parents 65a6f2c + 4aea62d commit 8638424

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+184
-147
lines changed

openapi_schema_pydantic/util.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Any, List, Set, Type, TypeVar
2+
from typing import Any, Generic, List, Optional, Set, Type, TypeVar
33

44
from pydantic import BaseModel
55
from pydantic.schema import schema
@@ -12,16 +12,16 @@
1212
ref_prefix = "#/components/schemas/"
1313

1414

15-
class PydanticSchema(Schema):
15+
class PydanticSchema(Schema, Generic[PydanticType]):
1616
"""Special `Schema` class to indicate a reference from pydantic class"""
1717

18-
schema_class: Type[PydanticType] = ...
18+
schema_class: Type[PydanticType]
1919
"""the class that is used for generate the schema"""
2020

2121

2222
def construct_open_api_with_schema_class(
2323
open_api: OpenAPI,
24-
schema_classes: List[Type[PydanticType]] = None,
24+
schema_classes: Optional[List[Type[BaseModel]]] = None,
2525
scan_for_pydantic_schema_reference: bool = True,
2626
by_alias: bool = True,
2727
) -> OpenAPI:
@@ -56,22 +56,22 @@ def construct_open_api_with_schema_class(
5656
new_open_api.components = Components()
5757
if new_open_api.components.schemas:
5858
for existing_key in new_open_api.components.schemas:
59-
if existing_key in schema_definitions.get("definitions"):
59+
if existing_key in schema_definitions["definitions"]:
6060
logger.warning(
6161
f'"{existing_key}" already exists in {ref_prefix}. '
6262
f'The value of "{ref_prefix}{existing_key}" will be overwritten.'
6363
)
6464
new_open_api.components.schemas.update(
65-
{key: Schema.parse_obj(schema_dict) for key, schema_dict in schema_definitions.get("definitions").items()}
65+
{key: Schema.parse_obj(schema_dict) for key, schema_dict in schema_definitions["definitions"].items()}
6666
)
6767
else:
6868
new_open_api.components.schemas = {
69-
key: Schema.parse_obj(schema_dict) for key, schema_dict in schema_definitions.get("definitions").items()
69+
key: Schema.parse_obj(schema_dict) for key, schema_dict in schema_definitions["definitions"].items()
7070
}
7171
return new_open_api
7272

7373

74-
def _handle_pydantic_schema(open_api: OpenAPI) -> List[Type[PydanticType]]:
74+
def _handle_pydantic_schema(open_api: OpenAPI) -> List[Type[BaseModel]]:
7575
"""
7676
This function traverses the `OpenAPI` object and
7777
@@ -84,9 +84,9 @@ def _handle_pydantic_schema(open_api: OpenAPI) -> List[Type[PydanticType]]:
8484
:return: a list of schema classes extracted from `PydanticSchema` objects
8585
"""
8686

87-
pydantic_types: Set[Type[PydanticType]] = set()
87+
pydantic_types: Set[Type[BaseModel]] = set()
8888

89-
def _traverse(obj: Any):
89+
def _traverse(obj: Any) -> None:
9090
if isinstance(obj, BaseModel):
9191
fields = obj.__fields_set__
9292
for field in fields:
@@ -118,7 +118,7 @@ def _traverse(obj: Any):
118118
return list(pydantic_types)
119119

120120

121-
def _construct_ref_obj(pydantic_schema: PydanticSchema):
121+
def _construct_ref_obj(pydantic_schema: PydanticSchema[PydanticType]) -> Reference:
122122
ref_obj = Reference(ref=ref_prefix + pydantic_schema.schema_class.__name__)
123123
logger.debug(f"ref_obj={ref_obj}")
124124
return ref_obj

openapi_schema_pydantic/v3/v3_0_3/__init__.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#table-of-contents
77
"""
88

9-
from .open_api import OpenAPI
10-
from .info import Info
11-
from .contact import Contact
12-
from .license import License
13-
from .server import Server
14-
from .server_variable import ServerVariable
15-
from .components import Components
16-
from .paths import Paths
17-
from .path_item import PathItem
18-
from .operation import Operation
19-
from .external_documentation import ExternalDocumentation
20-
from .parameter import Parameter, ParameterLocation
21-
from .request_body import RequestBody
22-
from .media_type import MediaType
23-
from .encoding import Encoding
24-
from .responses import Responses
25-
from .response import Response
26-
from .callback import Callback
27-
from .example import Example
28-
from .link import Link
29-
from .header import Header
30-
from .tag import Tag
31-
from .reference import Reference
32-
from .schema import Schema
33-
from .discriminator import Discriminator
34-
from .xml import XML
35-
from .security_scheme import SecurityScheme
36-
from .oauth_flows import OAuthFlows
37-
from .oauth_flow import OAuthFlow
38-
from .security_requirement import SecurityRequirement
9+
from .open_api import OpenAPI as OpenAPI
10+
from .info import Info as Info
11+
from .contact import Contact as Contact
12+
from .license import License as License
13+
from .server import Server as Server
14+
from .server_variable import ServerVariable as ServerVariable
15+
from .components import Components as Components
16+
from .paths import Paths as Paths
17+
from .path_item import PathItem as PathItem
18+
from .operation import Operation as Operation
19+
from .external_documentation import ExternalDocumentation as ExternalDocumentation
20+
from .parameter import Parameter as Parameter, ParameterLocation as ParameterLocation
21+
from .request_body import RequestBody as RequestBody
22+
from .media_type import MediaType as MediaType
23+
from .encoding import Encoding as Encoding
24+
from .responses import Responses as Responses
25+
from .response import Response as Response
26+
from .callback import Callback as Callback
27+
from .example import Example as Example
28+
from .link import Link as Link
29+
from .header import Header as Header
30+
from .tag import Tag as Tag
31+
from .reference import Reference as Reference
32+
from .schema import Schema as Schema
33+
from .discriminator import Discriminator as Discriminator
34+
from .xml import XML as XML
35+
from .security_scheme import SecurityScheme as SecurityScheme
36+
from .oauth_flows import OAuthFlows as OAuthFlows
37+
from .oauth_flow import OAuthFlow as OAuthFlow
38+
from .security_requirement import SecurityRequirement as SecurityRequirement
3939

4040

4141
# resolve forward references

openapi_schema_pydantic/v3/v3_0_3/callback.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from typing import Dict
1+
from typing import Dict, TYPE_CHECKING
2+
3+
if TYPE_CHECKING:
4+
from .path_item import PathItem
25

36

47
Callback = Dict[str, "PathItem"]

openapi_schema_pydantic/v3/v3_0_3/discriminator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Discriminator(BaseModel):
1414
When using the discriminator, _inline_ schemas will not be considered.
1515
"""
1616

17-
propertyName: str = ...
17+
propertyName: str
1818
"""
1919
**REQUIRED**. The name of the property in the payload that will hold the discriminator value.
2020
"""

openapi_schema_pydantic/v3/v3_0_3/encoding.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
from typing import Dict, Optional, Union
1+
from typing import Dict, Optional, TYPE_CHECKING, Union
22

33
from pydantic import BaseModel, Extra
44

55
from .reference import Reference
66

7+
if TYPE_CHECKING:
8+
from .header import Header
9+
710

811
class Encoding(BaseModel):
912
"""A single encoding definition applied to a single schema property."""

openapi_schema_pydantic/v3/v3_0_3/external_documentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ExternalDocumentation(BaseModel):
1212
[CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
1313
"""
1414

15-
url: AnyUrl = ...
15+
url: AnyUrl
1616
"""
1717
**REQUIRED**. The URL for the target documentation.
1818
Value MUST be in the format of a URL.

openapi_schema_pydantic/v3/v3_0_3/info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Info(BaseModel):
1313
and MAY be presented in editing or documentation generation tools for convenience.
1414
"""
1515

16-
title: str = ...
16+
title: str
1717
"""
1818
**REQUIRED**. The title of the API.
1919
"""
@@ -40,7 +40,7 @@ class Info(BaseModel):
4040
The license information for the exposed API.
4141
"""
4242

43-
version: str = ...
43+
version: str
4444
"""
4545
**REQUIRED**. The version of the OpenAPI document
4646
(which is distinct from the [OpenAPI Specification version](#oasVersion) or the API implementation version).

openapi_schema_pydantic/v3/v3_0_3/license.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class License(BaseModel):
88
License information for the exposed API.
99
"""
1010

11-
name: str = ...
11+
name: str
1212
"""
1313
**REQUIRED**. The license name used for the API.
1414
"""

openapi_schema_pydantic/v3/v3_0_3/oauth_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class OAuthFlow(BaseModel):
2727
The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL.
2828
"""
2929

30-
scopes: Dict[str, str] = ...
30+
scopes: Dict[str, str]
3131
"""
3232
**REQUIRED**. The available scopes for the OAuth2 security scheme.
3333
A map between the scope name and a short description for it.

openapi_schema_pydantic/v3/v3_0_3/open_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class OpenAPI(BaseModel):
2222
This is *not* related to the API [`info.version`](#infoVersion) string.
2323
"""
2424

25-
info: Info = ...
25+
info: Info
2626
"""
2727
**REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.
2828
"""
@@ -34,7 +34,7 @@ class OpenAPI(BaseModel):
3434
the default value would be a [Server Object](#serverObject) with a [url](#serverUrl) value of `/`.
3535
"""
3636

37-
paths: Paths = ...
37+
paths: Paths
3838
"""
3939
**REQUIRED**. The available paths and operations for the API.
4040
"""

0 commit comments

Comments
 (0)