Skip to content

Commit c46f522

Browse files
committed
feat: Renaming and tox config.
1 parent 37c074d commit c46f522

17 files changed

+259
-110
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"containerEnv": {
1010
"POETRY_VIRTUALENVS_IN_PROJECT": "true"
1111
},
12-
"postCreateCommand": "poetry install",
12+
"postCreateCommand": "poetry install && pip install --upgrade tox",
1313
"customizations": {
1414
"vscode": {
1515
"extensions": [

.github/release.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
changelog:
2+
exclude:
3+
labels:
4+
- ignore-for-release
5+
categories:
6+
- title: Breaking 💥
7+
labels:
8+
- breaking
9+
- title: Added 🎉
10+
labels:
11+
- feature
12+
- title: Changed 🛠
13+
labels:
14+
- change
15+
- title: Fixed 🐛
16+
labels:
17+
- fix
18+
- bug
19+
- title: Dependencies 📦
20+
labels:
21+
- dependencies

.tox/py3.10/.tox-info.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ToxEnv": {
3+
"name": "py3.10",
4+
"type": "VirtualEnvRunner"
5+
}
6+
}

poetry.lock

Lines changed: 1 addition & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ include = ["openapi_pydantic/py.typed"]
2525
python = "^3.8"
2626
pydantic = "^1.8.2"
2727

28+
[tool.poetry.group.test.dependencies]
29+
pytest = "^7.3.0"
30+
pytest-cov = "^4.0.0"
31+
2832
[tool.poetry.group.dev.dependencies]
2933
black = "^23.3.0"
3034
mypy = "^1.2.0"
3135
pre-commit = "^2.16.0"
32-
pytest = "^7.3.0"
33-
pytest-cov = "^4.0.0"
3436
ruff = "^0.0.265"
3537

3638
[build-system]

tests/test_alias.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from openapi_schema_pydantic import (
1+
from openapi_pydantic import (
22
Header,
33
MediaType,
44
Parameter,
@@ -29,8 +29,12 @@ def test_media_type_alias() -> None:
2929
def test_parameter_alias() -> None:
3030
parameter_1 = Parameter(name="test", param_in="path", param_schema=Schema())
3131
parameter_2 = Parameter(name="test", param_in="path", schema=Schema())
32-
parameter_3 = Parameter.parse_obj({"name": "test", "param_in": "path", "param_schema": Schema()})
33-
parameter_4 = Parameter.parse_obj({"name": "test", "in": "path", "schema": Schema()})
32+
parameter_3 = Parameter.parse_obj(
33+
{"name": "test", "param_in": "path", "param_schema": Schema()}
34+
)
35+
parameter_4 = Parameter.parse_obj(
36+
{"name": "test", "in": "path", "schema": Schema()}
37+
)
3438
assert parameter_1 == parameter_2 == parameter_3 == parameter_4
3539

3640

@@ -50,7 +54,9 @@ def test_reference_alias() -> None:
5054

5155
def test_security_scheme() -> None:
5256
security_scheme_1 = SecurityScheme(type="apiKey", security_scheme_in="header")
53-
security_scheme_2 = SecurityScheme.parse_obj({"type": "apiKey", "security_scheme_in": "header"})
57+
security_scheme_2 = SecurityScheme.parse_obj(
58+
{"type": "apiKey", "security_scheme_in": "header"}
59+
)
5460
security_scheme_3 = SecurityScheme.parse_obj({"type": "apiKey", "in": "header"})
5561
assert security_scheme_1 == security_scheme_2 == security_scheme_3
5662

tests/test_config_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from openapi_schema_pydantic import (
1+
from openapi_pydantic import (
22
OpenAPI,
33
Info,
44
Contact,

tests/test_example.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from openapi_schema_pydantic import Info, OpenAPI, Operation, PathItem, Response
3+
from openapi_pydantic import Info, OpenAPI, Operation, PathItem, Response
44

55

66
def test_readme_example() -> None:
@@ -24,7 +24,11 @@ def readme_example_1() -> OpenAPI:
2424
title="My own API",
2525
version="v0.0.1",
2626
),
27-
paths={"/ping": PathItem(get=Operation(responses={"200": Response(description="pong")}))},
27+
paths={
28+
"/ping": PathItem(
29+
get=Operation(responses={"200": Response(description="pong")})
30+
)
31+
},
2832
)
2933

3034

@@ -33,7 +37,9 @@ def readme_example_2() -> OpenAPI:
3337
return OpenAPI.parse_obj(
3438
{
3539
"info": {"title": "My own API", "version": "v0.0.1"},
36-
"paths": {"/ping": {"get": {"responses": {"200": {"description": "pong"}}}}},
40+
"paths": {
41+
"/ping": {"get": {"responses": {"200": {"description": "pong"}}}}
42+
},
3743
}
3844
)
3945

@@ -43,6 +49,10 @@ def readme_example_3() -> OpenAPI:
4349
return OpenAPI.parse_obj(
4450
{
4551
"info": {"title": "My own API", "version": "v0.0.1"},
46-
"paths": {"/ping": PathItem(get={"responses": {"200": Response(description="pong")}})},
52+
"paths": {
53+
"/ping": PathItem(
54+
get={"responses": {"200": Response(description="pong")}}
55+
)
56+
},
4757
}
4858
)

tests/test_swagger_openapi_v3.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pydantic import Field
44

5-
from openapi_schema_pydantic import OpenAPI, Operation, PathItem
5+
from openapi_pydantic import OpenAPI, Operation, PathItem
66

77

88
def test_swagger_openapi_v3() -> None:
@@ -13,7 +13,9 @@ def test_swagger_openapi_v3() -> None:
1313
class ExtendedOperation(Operation):
1414
"""Override classes to use "x-codegen-request-body-name" in Operation"""
1515

16-
xCodegenRequestBodyName: Optional[str] = Field(default=None, alias="x-codegen-request-body-name")
16+
xCodegenRequestBodyName: Optional[str] = Field(
17+
default=None, alias="x-codegen-request-body-name"
18+
)
1719

1820
class Config:
1921
allow_population_by_field_name = True

tests/util/test_pydantic_field.py

Lines changed: 74 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,59 @@
1-
from typing_extensions import Literal
21
from typing import Union
32

43
from pydantic import BaseModel, Field
54
from pydantic.schema import schema
5+
from typing_extensions import Literal
66

7-
from openapi_schema_pydantic import (
8-
OpenAPI,
7+
from openapi_pydantic import (
8+
Discriminator,
99
Info,
10-
PathItem,
10+
MediaType,
11+
OpenAPI,
1112
Operation,
13+
PathItem,
14+
Reference,
1215
RequestBody,
13-
MediaType,
1416
Response,
1517
Schema,
16-
Reference,
17-
Discriminator,
1818
)
19-
from openapi_schema_pydantic.util import PydanticSchema, construct_open_api_with_schema_class
19+
from openapi_pydantic.util import PydanticSchema, construct_open_api_with_schema_class
20+
21+
22+
class DataAModel(BaseModel):
23+
kind: Literal["a"]
24+
25+
26+
class DataBModel(BaseModel):
27+
kind: Literal["b"]
28+
29+
30+
class RequestModel(BaseModel):
31+
data: Union[DataAModel, DataBModel] = Field(discriminator="kind")
32+
33+
34+
def construct_base_open_api() -> OpenAPI:
35+
return OpenAPI(
36+
info=Info(
37+
title="My own API",
38+
version="v0.0.1",
39+
),
40+
paths={
41+
"/ping": PathItem(
42+
post=Operation(
43+
requestBody=RequestBody(
44+
content={
45+
"application/json": MediaType(
46+
media_type_schema=PydanticSchema(
47+
schema_class=RequestModel
48+
)
49+
)
50+
}
51+
),
52+
responses={"200": Response(description="pong")},
53+
)
54+
)
55+
},
56+
)
2057

2158

2259
def test_pydantic_discriminator_schema_generation() -> None:
@@ -26,23 +63,33 @@ def test_pydantic_discriminator_schema_generation() -> None:
2663
assert json_schema == {
2764
"definitions": {
2865
"DataAModel": {
29-
"properties": {"kind": {"enum": ["a"], "title": "Kind", "type": "string"}},
66+
"properties": {
67+
"kind": {"enum": ["a"], "title": "Kind", "type": "string"}
68+
},
3069
"required": ["kind"],
3170
"title": "DataAModel",
3271
"type": "object",
3372
},
3473
"DataBModel": {
35-
"properties": {"kind": {"enum": ["b"], "title": "Kind", "type": "string"}},
74+
"properties": {
75+
"kind": {"enum": ["b"], "title": "Kind", "type": "string"}
76+
},
3677
"required": ["kind"],
3778
"title": "DataBModel",
3879
"type": "object",
3980
},
4081
"RequestModel": {
4182
"properties": {
4283
"data": {
43-
"anyOf": [{"$ref": "#/definitions/DataAModel"}, {"$ref": "#/definitions/DataBModel"}],
84+
"oneOf": [
85+
{"$ref": "#/definitions/DataAModel"},
86+
{"$ref": "#/definitions/DataBModel"},
87+
],
4488
"discriminator": {
45-
"mapping": {"a": "#/definitions/DataAModel", "b": "#/definitions/DataBModel"},
89+
"mapping": {
90+
"a": "#/definitions/DataAModel",
91+
"b": "#/definitions/DataBModel",
92+
},
4693
"propertyName": "kind",
4794
},
4895
"title": "Data",
@@ -65,47 +112,25 @@ def test_pydantic_discriminator_openapi_generation() -> None:
65112
json_schema = open_api.components.schemas["RequestModel"]
66113
assert json_schema.properties == {
67114
"data": Schema(
68-
anyOf=[
69-
Reference(ref="#/components/schemas/DataAModel", summary=None, description=None),
70-
Reference(ref="#/components/schemas/DataBModel", summary=None, description=None),
115+
oneOf=[
116+
Reference(
117+
ref="#/components/schemas/DataAModel",
118+
summary=None,
119+
description=None,
120+
),
121+
Reference(
122+
ref="#/components/schemas/DataBModel",
123+
summary=None,
124+
description=None,
125+
),
71126
],
72127
title="Data",
73128
discriminator=Discriminator(
74129
propertyName="kind",
75-
mapping={"a": "#/components/schemas/DataAModel", "b": "#/components/schemas/DataBModel"},
130+
mapping={
131+
"a": "#/components/schemas/DataAModel",
132+
"b": "#/components/schemas/DataBModel",
133+
},
76134
),
77135
)
78136
}
79-
80-
81-
def construct_base_open_api() -> OpenAPI:
82-
return OpenAPI(
83-
info=Info(
84-
title="My own API",
85-
version="v0.0.1",
86-
),
87-
paths={
88-
"/ping": PathItem(
89-
post=Operation(
90-
requestBody=RequestBody(
91-
content={
92-
"application/json": MediaType(media_type_schema=PydanticSchema(schema_class=RequestModel))
93-
}
94-
),
95-
responses={"200": Response(description="pong")},
96-
)
97-
)
98-
},
99-
)
100-
101-
102-
class DataAModel(BaseModel):
103-
kind: Literal["a"]
104-
105-
106-
class DataBModel(BaseModel):
107-
kind: Literal["b"]
108-
109-
110-
class RequestModel(BaseModel):
111-
data: Union[DataAModel, DataBModel] = Field(discriminator="kind")

0 commit comments

Comments
 (0)