Skip to content

Commit bcefd4a

Browse files
committed
update samples
1 parent 82aead0 commit bcefd4a

File tree

8 files changed

+78
-54
lines changed

8 files changed

+78
-54
lines changed

samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
)
2424

2525
from openapi_server.models.extra_models import TokenModel # noqa: F401
26+
from pydantic import Field, StrictStr
27+
from typing import Any, Optional
28+
from typing_extensions import Annotated
2629

2730

2831
router = APIRouter()
@@ -43,8 +46,8 @@
4346
response_model_by_alias=True,
4447
)
4548
async def fake_query_param_default(
46-
has_default: str = Query('Hello World', description="has default value", alias="hasDefault"),
47-
no_default: str = Query(None, description="no default value", alias="noDefault"),
49+
has_default: Annotated[Optional[StrictStr], Field(description="has default value")] = Query('Hello World', description="has default value", alias="hasDefault"),
50+
no_default: Annotated[Optional[StrictStr], Field(description="no default value")] = Query(None, description="no default value", alias="noDefault"),
4851
) -> None:
4952
""""""
5053
if not BaseFakeApi.subclasses:

samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api_base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from typing import ClassVar, Dict, List, Tuple # noqa: F401
44

5+
from pydantic import Field, StrictStr
6+
from typing import Any, Optional
7+
from typing_extensions import Annotated
58

69

710
class BaseFakeApi:
@@ -12,8 +15,8 @@ def __init_subclass__(cls, **kwargs):
1215
BaseFakeApi.subclasses = BaseFakeApi.subclasses + (cls,)
1316
async def fake_query_param_default(
1417
self,
15-
has_default: str,
16-
no_default: str,
18+
has_default: Annotated[Optional[StrictStr], Field(description="has default value")],
19+
no_default: Annotated[Optional[StrictStr], Field(description="no default value")],
1720
) -> None:
1821
""""""
1922
...

samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
)
2424

2525
from openapi_server.models.extra_models import TokenModel # noqa: F401
26+
from pydantic import Field, StrictBytes, StrictInt, StrictStr, field_validator
27+
from typing import Any, List, Optional, Tuple, Union
28+
from typing_extensions import Annotated
2629
from openapi_server.models.api_response import ApiResponse
2730
from openapi_server.models.pet import Pet
2831
from openapi_server.security_api import get_token_petstore_auth, get_token_api_key
@@ -45,7 +48,7 @@
4548
response_model_by_alias=True,
4649
)
4750
async def add_pet(
48-
pet: Pet = Body(None, description="Pet object that needs to be added to the store"),
51+
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(None, description="Pet object that needs to be added to the store"),
4952
token_petstore_auth: TokenModel = Security(
5053
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
5154
),
@@ -66,8 +69,8 @@ async def add_pet(
6669
response_model_by_alias=True,
6770
)
6871
async def delete_pet(
69-
petId: int = Path(..., description="Pet id to delete"),
70-
api_key: str = Header(None, description=""),
72+
petId: Annotated[StrictInt, Field(description="Pet id to delete")] = Path(..., description="Pet id to delete"),
73+
api_key: Optional[StrictStr] = Header(None, description=""),
7174
token_petstore_auth: TokenModel = Security(
7275
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
7376
),
@@ -89,7 +92,7 @@ async def delete_pet(
8992
response_model_by_alias=True,
9093
)
9194
async def find_pets_by_status(
92-
status: List[str] = Query(None, description="Status values that need to be considered for filter", alias="status"),
95+
status: Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")] = Query(None, description="Status values that need to be considered for filter", alias="status"),
9396
token_petstore_auth: TokenModel = Security(
9497
get_token_petstore_auth, scopes=["read:pets"]
9598
),
@@ -111,7 +114,7 @@ async def find_pets_by_status(
111114
response_model_by_alias=True,
112115
)
113116
async def find_pets_by_tags(
114-
tags: List[str] = Query(None, description="Tags to filter by", alias="tags"),
117+
tags: Annotated[List[StrictStr], Field(description="Tags to filter by")] = Query(None, description="Tags to filter by", alias="tags"),
115118
token_petstore_auth: TokenModel = Security(
116119
get_token_petstore_auth, scopes=["read:pets"]
117120
),
@@ -134,7 +137,7 @@ async def find_pets_by_tags(
134137
response_model_by_alias=True,
135138
)
136139
async def get_pet_by_id(
137-
petId: int = Path(..., description="ID of pet to return"),
140+
petId: Annotated[StrictInt, Field(description="ID of pet to return")] = Path(..., description="ID of pet to return"),
138141
token_api_key: TokenModel = Security(
139142
get_token_api_key
140143
),
@@ -158,7 +161,7 @@ async def get_pet_by_id(
158161
response_model_by_alias=True,
159162
)
160163
async def update_pet(
161-
pet: Pet = Body(None, description="Pet object that needs to be added to the store"),
164+
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(None, description="Pet object that needs to be added to the store"),
162165
token_petstore_auth: TokenModel = Security(
163166
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
164167
),
@@ -179,9 +182,9 @@ async def update_pet(
179182
response_model_by_alias=True,
180183
)
181184
async def update_pet_with_form(
182-
petId: int = Path(..., description="ID of pet that needs to be updated"),
183-
name: str = Form(None, description="Updated name of the pet"),
184-
status: str = Form(None, description="Updated status of the pet"),
185+
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")] = Path(..., description="ID of pet that needs to be updated"),
186+
name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")] = Form(None, description="Updated name of the pet"),
187+
status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")] = Form(None, description="Updated status of the pet"),
185188
token_petstore_auth: TokenModel = Security(
186189
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
187190
),
@@ -202,9 +205,9 @@ async def update_pet_with_form(
202205
response_model_by_alias=True,
203206
)
204207
async def upload_file(
205-
petId: int = Path(..., description="ID of pet to update"),
206-
additional_metadata: str = Form(None, description="Additional data to pass to server"),
207-
file: str = Form(None, description="file to upload"),
208+
petId: Annotated[StrictInt, Field(description="ID of pet to update")] = Path(..., description="ID of pet to update"),
209+
additional_metadata: Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = Form(None, description="Additional data to pass to server"),
210+
file: Annotated[Optional[Union[StrictBytes, StrictStr, Tuple[StrictStr, StrictBytes]]], Field(description="file to upload")] = Form(None, description="file to upload"),
208211
token_petstore_auth: TokenModel = Security(
209212
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
210213
),

samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api_base.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from typing import ClassVar, Dict, List, Tuple # noqa: F401
44

5+
from pydantic import Field, StrictBytes, StrictInt, StrictStr, field_validator
6+
from typing import Any, List, Optional, Tuple, Union
7+
from typing_extensions import Annotated
58
from openapi_server.models.api_response import ApiResponse
69
from openapi_server.models.pet import Pet
710
from openapi_server.security_api import get_token_petstore_auth, get_token_api_key
@@ -14,68 +17,68 @@ def __init_subclass__(cls, **kwargs):
1417
BasePetApi.subclasses = BasePetApi.subclasses + (cls,)
1518
async def add_pet(
1619
self,
17-
pet: Pet,
20+
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
1821
) -> Pet:
1922
""""""
2023
...
2124

2225

2326
async def delete_pet(
2427
self,
25-
petId: int,
26-
api_key: str,
28+
petId: Annotated[StrictInt, Field(description="Pet id to delete")],
29+
api_key: Optional[StrictStr],
2730
) -> None:
2831
""""""
2932
...
3033

3134

3235
async def find_pets_by_status(
3336
self,
34-
status: List[str],
37+
status: Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")],
3538
) -> List[Pet]:
3639
"""Multiple status values can be provided with comma separated strings"""
3740
...
3841

3942

4043
async def find_pets_by_tags(
4144
self,
42-
tags: List[str],
45+
tags: Annotated[List[StrictStr], Field(description="Tags to filter by")],
4346
) -> List[Pet]:
4447
"""Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."""
4548
...
4649

4750

4851
async def get_pet_by_id(
4952
self,
50-
petId: int,
53+
petId: Annotated[StrictInt, Field(description="ID of pet to return")],
5154
) -> Pet:
5255
"""Returns a single pet"""
5356
...
5457

5558

5659
async def update_pet(
5760
self,
58-
pet: Pet,
61+
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
5962
) -> Pet:
6063
""""""
6164
...
6265

6366

6467
async def update_pet_with_form(
6568
self,
66-
petId: int,
67-
name: str,
68-
status: str,
69+
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")],
70+
name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")],
71+
status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")],
6972
) -> None:
7073
""""""
7174
...
7275

7376

7477
async def upload_file(
7578
self,
76-
petId: int,
77-
additional_metadata: str,
78-
file: str,
79+
petId: Annotated[StrictInt, Field(description="ID of pet to update")],
80+
additional_metadata: Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")],
81+
file: Annotated[Optional[Union[StrictBytes, StrictStr, Tuple[StrictStr, StrictBytes]]], Field(description="file to upload")],
7982
) -> ApiResponse:
8083
""""""
8184
...

samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
)
2424

2525
from openapi_server.models.extra_models import TokenModel # noqa: F401
26+
from pydantic import Field, StrictInt, StrictStr
27+
from typing import Any, Dict
28+
from typing_extensions import Annotated
2629
from openapi_server.models.order import Order
2730
from openapi_server.security_api import get_token_api_key
2831

@@ -44,7 +47,7 @@
4447
response_model_by_alias=True,
4548
)
4649
async def delete_order(
47-
orderId: str = Path(..., description="ID of the order that needs to be deleted"),
50+
orderId: Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")] = Path(..., description="ID of the order that needs to be deleted"),
4851
) -> None:
4952
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
5053
if not BaseStoreApi.subclasses:
@@ -84,7 +87,7 @@ async def get_inventory(
8487
response_model_by_alias=True,
8588
)
8689
async def get_order_by_id(
87-
orderId: int = Path(..., description="ID of pet that needs to be fetched", ge=1, le=5),
90+
orderId: Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")] = Path(..., description="ID of pet that needs to be fetched", ge=1, le=5),
8891
) -> Order:
8992
"""For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions"""
9093
if not BaseStoreApi.subclasses:
@@ -103,7 +106,7 @@ async def get_order_by_id(
103106
response_model_by_alias=True,
104107
)
105108
async def place_order(
106-
order: Order = Body(None, description="order placed for purchasing the pet"),
109+
order: Annotated[Order, Field(description="order placed for purchasing the pet")] = Body(None, description="order placed for purchasing the pet"),
107110
) -> Order:
108111
""""""
109112
if not BaseStoreApi.subclasses:

samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api_base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from typing import ClassVar, Dict, List, Tuple # noqa: F401
44

5+
from pydantic import Field, StrictInt, StrictStr
6+
from typing import Any, Dict
7+
from typing_extensions import Annotated
58
from openapi_server.models.order import Order
69
from openapi_server.security_api import get_token_api_key
710

@@ -13,7 +16,7 @@ def __init_subclass__(cls, **kwargs):
1316
BaseStoreApi.subclasses = BaseStoreApi.subclasses + (cls,)
1417
async def delete_order(
1518
self,
16-
orderId: str,
19+
orderId: Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")],
1720
) -> None:
1821
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
1922
...
@@ -28,15 +31,15 @@ async def get_inventory(
2831

2932
async def get_order_by_id(
3033
self,
31-
orderId: int,
34+
orderId: Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")],
3235
) -> Order:
3336
"""For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions"""
3437
...
3538

3639

3740
async def place_order(
3841
self,
39-
order: Order,
42+
order: Annotated[Order, Field(description="order placed for purchasing the pet")],
4043
) -> Order:
4144
""""""
4245
...

samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
)
2424

2525
from openapi_server.models.extra_models import TokenModel # noqa: F401
26+
from pydantic import Field, StrictStr, field_validator
27+
from typing import Any, List
28+
from typing_extensions import Annotated
2629
from openapi_server.models.user import User
2730
from openapi_server.security_api import get_token_api_key
2831

@@ -43,7 +46,7 @@
4346
response_model_by_alias=True,
4447
)
4548
async def create_user(
46-
user: User = Body(None, description="Created user object"),
49+
user: Annotated[User, Field(description="Created user object")] = Body(None, description="Created user object"),
4750
token_api_key: TokenModel = Security(
4851
get_token_api_key
4952
),
@@ -64,7 +67,7 @@ async def create_user(
6467
response_model_by_alias=True,
6568
)
6669
async def create_users_with_array_input(
67-
user: List[User] = Body(None, description="List of user object"),
70+
user: Annotated[List[User], Field(description="List of user object")] = Body(None, description="List of user object"),
6871
token_api_key: TokenModel = Security(
6972
get_token_api_key
7073
),
@@ -85,7 +88,7 @@ async def create_users_with_array_input(
8588
response_model_by_alias=True,
8689
)
8790
async def create_users_with_list_input(
88-
user: List[User] = Body(None, description="List of user object"),
91+
user: Annotated[List[User], Field(description="List of user object")] = Body(None, description="List of user object"),
8992
token_api_key: TokenModel = Security(
9093
get_token_api_key
9194
),
@@ -107,7 +110,7 @@ async def create_users_with_list_input(
107110
response_model_by_alias=True,
108111
)
109112
async def delete_user(
110-
username: str = Path(..., description="The name that needs to be deleted"),
113+
username: Annotated[StrictStr, Field(description="The name that needs to be deleted")] = Path(..., description="The name that needs to be deleted"),
111114
token_api_key: TokenModel = Security(
112115
get_token_api_key
113116
),
@@ -130,7 +133,7 @@ async def delete_user(
130133
response_model_by_alias=True,
131134
)
132135
async def get_user_by_name(
133-
username: str = Path(..., description="The name that needs to be fetched. Use user1 for testing."),
136+
username: Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")] = Path(..., description="The name that needs to be fetched. Use user1 for testing."),
134137
) -> User:
135138
""""""
136139
if not BaseUserApi.subclasses:
@@ -149,8 +152,8 @@ async def get_user_by_name(
149152
response_model_by_alias=True,
150153
)
151154
async def login_user(
152-
username: str = Query(None, description="The user name for login", alias="username", regex=r"/^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$/"),
153-
password: str = Query(None, description="The password for login in clear text", alias="password"),
155+
username: Annotated[str, Field(strict=True, description="The user name for login")] = Query(None, description="The user name for login", alias="username", regex=r"/^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$/"),
156+
password: Annotated[StrictStr, Field(description="The password for login in clear text")] = Query(None, description="The password for login in clear text", alias="password"),
154157
) -> str:
155158
""""""
156159
if not BaseUserApi.subclasses:
@@ -189,8 +192,8 @@ async def logout_user(
189192
response_model_by_alias=True,
190193
)
191194
async def update_user(
192-
username: str = Path(..., description="name that need to be deleted"),
193-
user: User = Body(None, description="Updated user object"),
195+
username: Annotated[StrictStr, Field(description="name that need to be deleted")] = Path(..., description="name that need to be deleted"),
196+
user: Annotated[User, Field(description="Updated user object")] = Body(None, description="Updated user object"),
194197
token_api_key: TokenModel = Security(
195198
get_token_api_key
196199
),

0 commit comments

Comments
 (0)