forked from loafle/openapi-generator-original
python: generate Pydantic v2 + typing complete code (#16624)
* python: improve type generation with more specific typing * Annotate function parameters * Remove unused imports * remove unused files * remove temporary hack * remove lock file * fix Annotated import * support Python 3.7 * Regenerate code with typing-extensions * Fix setup.py * More Pydantic v2 compatibility * depend on pydantic v2 * fix client_echo tests * fix JSON serialization * Fix references * Skip circular dependency tests for now * Temporarily hide the "float" property The "float" property aliases the "float" type and completely breaks the model: all the properties that were "float" now become the type of the "float" property instead. * Fix errors * Import Literal from typing_extensions * Fix GitHub Action workflows * Fix Python 3.7 failure * Fix quotes * Apply suggestions from code review * Fix tests * split model imports from other modules imports * fix workflow * Comment the array unique items convertion, remove set translation * Replace alias usage
This commit is contained in:
@@ -8,7 +8,6 @@ Name | Type | Description | Notes
|
||||
**int32** | **int** | | [optional]
|
||||
**int64** | **int** | | [optional]
|
||||
**number** | **float** | |
|
||||
**float** | **float** | | [optional]
|
||||
**double** | **float** | | [optional]
|
||||
**decimal** | **decimal.Decimal** | | [optional]
|
||||
**string** | **str** | | [optional]
|
||||
|
||||
@@ -29,7 +29,6 @@ class FormatTest(BaseModel):
|
||||
int32: Optional[conint(strict=True, le=200, ge=20)] = None
|
||||
int64: Optional[StrictInt] = None
|
||||
number: confloat(le=543.2, ge=32.1, strict=True) = Field(...)
|
||||
float: Optional[confloat(le=987.6, ge=54.3, strict=True)] = None
|
||||
double: Optional[confloat(le=123.4, ge=67.8, strict=True)] = None
|
||||
decimal: Optional[condecimal()] = None
|
||||
string: Optional[constr(strict=True)] = None
|
||||
@@ -43,7 +42,7 @@ class FormatTest(BaseModel):
|
||||
pattern_with_digits: Optional[constr(strict=True)] = Field(None, description="A string that is a 10 digit number. Can have leading zeros.")
|
||||
pattern_with_digits_and_delimiter: Optional[constr(strict=True)] = Field(None, description="A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01.")
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["integer", "int32", "int64", "number", "float", "double", "decimal", "string", "string_with_double_quote_pattern", "byte", "binary", "date", "dateTime", "uuid", "password", "pattern_with_digits", "pattern_with_digits_and_delimiter"]
|
||||
__properties = ["integer", "int32", "int64", "number", "double", "decimal", "string", "string_with_double_quote_pattern", "byte", "binary", "date", "dateTime", "uuid", "password", "pattern_with_digits", "pattern_with_digits_and_delimiter"]
|
||||
|
||||
@validator('string')
|
||||
def string_validate_regular_expression(cls, value):
|
||||
@@ -131,7 +130,6 @@ class FormatTest(BaseModel):
|
||||
"int32": obj.get("int32"),
|
||||
"int64": obj.get("int64"),
|
||||
"number": obj.get("number"),
|
||||
"float": obj.get("float"),
|
||||
"double": obj.get("double"),
|
||||
"decimal": obj.get("decimal"),
|
||||
"string": obj.get("string"),
|
||||
|
||||
@@ -40,7 +40,8 @@ class TestFormatTest(unittest.TestCase):
|
||||
int32 = 20,
|
||||
int64 = 56,
|
||||
number = 132.1,
|
||||
float = 54.3,
|
||||
# TODO: pydantic v2: the "float" property aliases the "float" type in the pydantic v2 generator
|
||||
# float = 54.3,
|
||||
double = 67.8,
|
||||
decimal = 1,
|
||||
string = 'a',
|
||||
|
||||
Reference in New Issue
Block a user