forked from loafle/openapi-generator-original
Fix python-fastapi free-form objects mapping and forward ref type hints (#9723)
* map free-form objects to Dict[str, Any] * support Forward Type References Forward type references will be supported by default from Python 3.10 on only. Until then (and starting with Python 3.7), we can opt in by a __future__ import, cf. https://docs.python.org/3.9/whatsnew/3.7.html?highlight=forward#pep-563-postponed-evaluation-of-annotations * re-created pet-store sample * bump required Python version to 3.7 for generated FastAPI projects * make pydantic modell classes process forward type references
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import annotations
|
||||
from datetime import date, datetime # noqa: F401
|
||||
|
||||
import re # noqa: F401
|
||||
from typing import Dict, List, Optional # noqa: F401
|
||||
from typing import Any, Dict, List, Optional # noqa: F401
|
||||
|
||||
from pydantic import AnyUrl, BaseModel, EmailStr, validator # noqa: F401
|
||||
|
||||
@@ -23,3 +24,5 @@ class ApiResponse(BaseModel):
|
||||
code: Optional[int] = None
|
||||
type: Optional[str] = None
|
||||
message: Optional[str] = None
|
||||
|
||||
ApiResponse.update_forward_refs()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import annotations
|
||||
from datetime import date, datetime # noqa: F401
|
||||
|
||||
import re # noqa: F401
|
||||
from typing import Dict, List, Optional # noqa: F401
|
||||
from typing import Any, Dict, List, Optional # noqa: F401
|
||||
|
||||
from pydantic import AnyUrl, BaseModel, EmailStr, validator # noqa: F401
|
||||
|
||||
@@ -26,3 +27,5 @@ class Category(BaseModel):
|
||||
def name_pattern(cls, value):
|
||||
assert value is not None and re.match(r"^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$", value)
|
||||
return value
|
||||
|
||||
Category.update_forward_refs()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import annotations
|
||||
from datetime import date, datetime # noqa: F401
|
||||
|
||||
import re # noqa: F401
|
||||
from typing import Dict, List, Optional # noqa: F401
|
||||
from typing import Any, Dict, List, Optional # noqa: F401
|
||||
|
||||
from pydantic import AnyUrl, BaseModel, EmailStr, validator # noqa: F401
|
||||
|
||||
@@ -29,3 +30,5 @@ class Order(BaseModel):
|
||||
ship_date: Optional[datetime] = None
|
||||
status: Optional[str] = None
|
||||
complete: Optional[bool] = None
|
||||
|
||||
Order.update_forward_refs()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import annotations
|
||||
from datetime import date, datetime # noqa: F401
|
||||
|
||||
import re # noqa: F401
|
||||
from typing import Dict, List, Optional # noqa: F401
|
||||
from typing import Any, Dict, List, Optional # noqa: F401
|
||||
|
||||
from pydantic import AnyUrl, BaseModel, EmailStr, validator # noqa: F401
|
||||
from openapi_server.models.category import Category
|
||||
@@ -31,3 +32,5 @@ class Pet(BaseModel):
|
||||
photo_urls: List[str]
|
||||
tags: Optional[List[Tag]] = None
|
||||
status: Optional[str] = None
|
||||
|
||||
Pet.update_forward_refs()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import annotations
|
||||
from datetime import date, datetime # noqa: F401
|
||||
|
||||
import re # noqa: F401
|
||||
from typing import Dict, List, Optional # noqa: F401
|
||||
from typing import Any, Dict, List, Optional # noqa: F401
|
||||
|
||||
from pydantic import AnyUrl, BaseModel, EmailStr, validator # noqa: F401
|
||||
|
||||
@@ -21,3 +22,5 @@ class Tag(BaseModel):
|
||||
|
||||
id: Optional[int] = None
|
||||
name: Optional[str] = None
|
||||
|
||||
Tag.update_forward_refs()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import annotations
|
||||
from datetime import date, datetime # noqa: F401
|
||||
|
||||
import re # noqa: F401
|
||||
from typing import Dict, List, Optional # noqa: F401
|
||||
from typing import Any, Dict, List, Optional # noqa: F401
|
||||
|
||||
from pydantic import AnyUrl, BaseModel, EmailStr, validator # noqa: F401
|
||||
|
||||
@@ -33,3 +34,5 @@ class User(BaseModel):
|
||||
password: Optional[str] = None
|
||||
phone: Optional[str] = None
|
||||
user_status: Optional[int] = None
|
||||
|
||||
User.update_forward_refs()
|
||||
|
||||
Reference in New Issue
Block a user