Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit 46a0707

Browse files
authored
Merge pull request #10 from starlite-api/refactor-remove-303
Removes the `v3_0_3` sub-package.
2 parents 4295bbd + d5558e4 commit 46a0707

40 files changed

+36
-2703
lines changed

CHANGELOG.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Changelog
22

3-
[v1.0.0]
3+
[v1.1.0]
44

5-
- initial release.
5+
- removes `v3_0_3`.
66

7-
[v1.0.1]
7+
[v1.0.3]
88

9-
- update handling of `email` to allow `str`.
9+
- update dependencies and docstrings.
1010

1111
[v1.0.2]
1212

1313
- update typing of `email`.
1414

15-
[v1.0.3]
15+
[v1.0.1]
1616

17-
- update dependencies and docstrings.
17+
- update handling of `email` to allow `str`.
18+
19+
[v1.0.0]
20+
21+
- initial release.

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ In comparison to the original library this library has:
3131
4. updated utilities
3232
5. updated export paths
3333
6. continuous maintenance
34+
7. dropped support for v3.0.3
3435

3536
Use is mostly identical to upstream package.
3637

poetry.lock

Lines changed: 11 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from . import v3_0_3, v3_1_0
1+
from . import v3_1_0
22
from .utils import construct_open_api_with_schema_class
33

44
__all__ = [
5-
"v3_0_3",
65
"v3_1_0",
76
"construct_open_api_with_schema_class",
87
]

pydantic_openapi_schema/utils/utils.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
from typing import TYPE_CHECKING, Any, List, Optional, Set, Type, TypeVar, Union, cast
1+
from typing import TYPE_CHECKING, Any, List, Optional, Set, Type, TypeVar, cast
22

33
from pydantic import BaseModel
44
from pydantic.schema import schema
55

6-
from pydantic_openapi_schema import v3_0_3, v3_1_0
6+
from pydantic_openapi_schema import v3_1_0
77

88
if TYPE_CHECKING:
99
from typing import Dict
1010

1111
REF_PREFIX = "#/components/schemas/"
1212

13-
T = TypeVar("T", bound=Union[v3_0_3.OpenAPI, v3_1_0.OpenAPI])
14-
15-
16-
class OpenAPI303PydanticSchema(v3_0_3.Schema):
17-
"""Special `Schema` class to indicate a reference from pydantic class."""
18-
19-
schema_class: Type[BaseModel]
20-
"""the class that is used for generate the schema"""
13+
T = TypeVar("T", bound=v3_1_0.OpenAPI)
2114

2215

2316
class OpenAPI310PydanticSchema(v3_1_0.Schema):
@@ -38,7 +31,7 @@ def construct_open_api_with_schema_class(
3831
3932
Args:
4033
open_api_schema: the base `OpenAPI` object
41-
schema_classes: pydanitic classes that their schema will be used "#/components/schemas" values
34+
schema_classes: pydantic classes that their schema will be used as "#/components/schemas" values
4235
scan_for_pydantic_schema_reference: flag to indicate if scanning for `PydanticSchemaReference`
4336
class is needed for "#/components/schemas" value updates
4437
by_alias: construct schema by alias (default is True)
@@ -47,13 +40,11 @@ class is needed for "#/components/schemas" value updates
4740
new OpenAPI object with "#/components/schemas" values updated. If there is no update in
4841
"#/components/schemas" values, the original `open_api` will be returned.
4942
"""
50-
specs = v3_1_0 if isinstance(open_api_schema, v3_1_0.OpenAPI) else v3_0_3
51-
5243
copied_schema = open_api_schema.copy(deep=True)
5344

5445
if scan_for_pydantic_schema_reference:
5546
extracted_schema_classes = extract_pydantic_types_to_openapi_components(
56-
obj=copied_schema, ref_class=specs.Reference
47+
obj=copied_schema, ref_class=v3_1_0.Reference
5748
)
5849
schema_classes = list(
5950
{*schema_classes, *extracted_schema_classes} if schema_classes else extracted_schema_classes
@@ -63,21 +54,19 @@ class is needed for "#/components/schemas" value updates
6354
return open_api_schema
6455

6556
if not copied_schema.components:
66-
copied_schema.components = specs.Components(schemas={})
57+
copied_schema.components = v3_1_0.Components(schemas={})
6758
elif not copied_schema.components.schemas:
6859
copied_schema.components.schemas = cast("Dict[str, Any]", {})
6960

7061
schema_classes.sort(key=lambda x: x.__name__)
7162
schema_definitions = schema(schema_classes, by_alias=by_alias, ref_prefix=REF_PREFIX)["definitions"]
7263
copied_schema.components.schemas.update( # type: ignore
73-
{key: specs.Schema.parse_obj(schema_dict) for key, schema_dict in schema_definitions.items()}
64+
{key: v3_1_0.Schema.parse_obj(schema_dict) for key, schema_dict in schema_definitions.items()}
7465
)
75-
return cast("T", copied_schema)
66+
return copied_schema
7667

7768

78-
def extract_pydantic_types_to_openapi_components(
79-
obj: Any, ref_class: Union[Type[v3_0_3.Reference], Type[v3_1_0.Reference]]
80-
) -> Set[Type[BaseModel]]:
69+
def extract_pydantic_types_to_openapi_components(obj: Any, ref_class: Type[v3_1_0.Reference]) -> Set[Type[BaseModel]]:
8170
"""Recursively traverses the OpenAPI document, replacing any found Pydantic
8271
Models with $references to the schema's components section and returning
8372
the pydantic models themselves.
@@ -94,21 +83,21 @@ def extract_pydantic_types_to_openapi_components(
9483
fields = obj.__fields_set__
9584
for field in fields:
9685
child_obj = getattr(obj, field)
97-
if isinstance(child_obj, (OpenAPI303PydanticSchema, OpenAPI310PydanticSchema)):
86+
if isinstance(child_obj, OpenAPI310PydanticSchema):
9887
setattr(obj, field, ref_class(ref=REF_PREFIX + child_obj.schema_class.__name__))
9988
pydantic_schemas.add(child_obj.schema_class)
10089
else:
10190
pydantic_schemas.update(extract_pydantic_types_to_openapi_components(child_obj, ref_class=ref_class))
10291
elif isinstance(obj, list):
10392
for index, elem in enumerate(obj):
104-
if isinstance(elem, (OpenAPI303PydanticSchema, OpenAPI310PydanticSchema)):
93+
if isinstance(elem, OpenAPI310PydanticSchema):
10594
obj[index] = ref_class(ref=REF_PREFIX + elem.schema_class.__name__)
10695
pydantic_schemas.add(elem.schema_class)
10796
else:
10897
pydantic_schemas.update(extract_pydantic_types_to_openapi_components(elem, ref_class=ref_class))
10998
elif isinstance(obj, dict):
11099
for key, value in obj.items():
111-
if isinstance(value, (OpenAPI303PydanticSchema, OpenAPI310PydanticSchema)):
100+
if isinstance(value, OpenAPI310PydanticSchema):
112101
obj[key] = ref_class(ref=REF_PREFIX + value.schema_class.__name__)
113102
pydantic_schemas.add(value.schema_class)
114103
else:

pydantic_openapi_schema/v3_0_3/__init__.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

pydantic_openapi_schema/v3_0_3/callback.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)