forked from loafle/openapi-generator-original
use Field(...) for required properties in python-nextgen (#15290)
This commit is contained in:
parent
98c2794b5d
commit
52417f0597
@ -1289,6 +1289,12 @@ public class PythonNextgenClientCodegen extends AbstractPythonCodegen implements
|
||||
fieldCustomization = String.format(Locale.ROOT, "Field(%s)", StringUtils.join(fields, ", "));
|
||||
}
|
||||
|
||||
if ("...".equals(fieldCustomization)) {
|
||||
// use Field() to avoid pylint warnings
|
||||
pydanticImports.add("Field");
|
||||
fieldCustomization = "Field(...)";
|
||||
}
|
||||
|
||||
cp.vendorExtensions.put("x-py-typing", typing + " = " + fieldCustomization);
|
||||
|
||||
// setup x-py-name for each oneOf/anyOf schema
|
||||
|
@ -30,7 +30,7 @@ class Pet(BaseModel):
|
||||
Pet
|
||||
"""
|
||||
id: Optional[StrictInt] = None
|
||||
name: StrictStr = ...
|
||||
name: StrictStr = Field(...)
|
||||
category: Optional[Category] = None
|
||||
photo_urls: conlist(StrictStr) = Field(..., alias="photoUrls")
|
||||
tags: Optional[conlist(Tag)] = None
|
||||
|
@ -27,7 +27,7 @@ class BasquePig(BaseModel):
|
||||
BasquePig
|
||||
"""
|
||||
class_name: StrictStr = Field(..., alias="className")
|
||||
color: StrictStr = ...
|
||||
color: StrictStr = Field(...)
|
||||
__properties = ["className", "color"]
|
||||
|
||||
class Config:
|
||||
|
@ -20,14 +20,14 @@ import json
|
||||
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from pydantic import BaseModel, Field, StrictInt, StrictStr
|
||||
|
||||
class Category(BaseModel):
|
||||
"""
|
||||
Category
|
||||
"""
|
||||
id: Optional[StrictInt] = None
|
||||
name: StrictStr = ...
|
||||
name: StrictStr = Field(...)
|
||||
__properties = ["id", "name"]
|
||||
|
||||
class Config:
|
||||
|
@ -27,7 +27,7 @@ class DanishPig(BaseModel):
|
||||
DanishPig
|
||||
"""
|
||||
class_name: StrictStr = Field(..., alias="className")
|
||||
size: StrictInt = ...
|
||||
size: StrictInt = Field(...)
|
||||
__properties = ["className", "size"]
|
||||
|
||||
class Config:
|
||||
|
@ -31,7 +31,7 @@ class EnumTest(BaseModel):
|
||||
EnumTest
|
||||
"""
|
||||
enum_string: Optional[StrictStr] = None
|
||||
enum_string_required: StrictStr = ...
|
||||
enum_string_required: StrictStr = Field(...)
|
||||
enum_integer_default: Optional[StrictInt] = 5
|
||||
enum_integer: Optional[StrictInt] = None
|
||||
enum_number: Optional[float] = None
|
||||
|
@ -29,7 +29,7 @@ class FormatTest(BaseModel):
|
||||
integer: Optional[conint(strict=True, le=100, ge=10)] = None
|
||||
int32: Optional[conint(strict=True, le=200, ge=20)] = None
|
||||
int64: Optional[StrictInt] = None
|
||||
number: confloat(le=543.2, ge=32.1) = ...
|
||||
number: confloat(le=543.2, ge=32.1) = Field(...)
|
||||
float: Optional[confloat(le=987.6, ge=54.3)] = None
|
||||
double: Optional[confloat(le=123.4, ge=67.8)] = None
|
||||
decimal: Optional[condecimal()] = None
|
||||
@ -40,7 +40,7 @@ class FormatTest(BaseModel):
|
||||
var_date: date = Field(..., alias="date")
|
||||
date_time: Optional[datetime] = Field(None, alias="dateTime")
|
||||
uuid: Optional[StrictStr] = None
|
||||
password: constr(strict=True, max_length=64, min_length=10) = ...
|
||||
password: constr(strict=True, max_length=64, min_length=10) = Field(...)
|
||||
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.")
|
||||
__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"]
|
||||
|
@ -26,7 +26,7 @@ class Name(BaseModel):
|
||||
"""
|
||||
Model for testing model name same as property name
|
||||
"""
|
||||
name: StrictInt = ...
|
||||
name: StrictInt = Field(...)
|
||||
snake_case: Optional[StrictInt] = None
|
||||
var_property: Optional[StrictStr] = Field(None, alias="property")
|
||||
var_123_number: Optional[StrictInt] = Field(None, alias="123Number")
|
||||
|
@ -20,13 +20,13 @@ import json
|
||||
|
||||
from datetime import date, datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
from pydantic import BaseModel, StrictBool, StrictInt, StrictStr, conlist
|
||||
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr, conlist
|
||||
|
||||
class NullableClass(BaseModel):
|
||||
"""
|
||||
NullableClass
|
||||
"""
|
||||
required_integer_prop: Optional[StrictInt] = ...
|
||||
required_integer_prop: Optional[StrictInt] = Field(...)
|
||||
integer_prop: Optional[StrictInt] = None
|
||||
number_prop: Optional[float] = None
|
||||
boolean_prop: Optional[StrictBool] = None
|
||||
|
@ -20,7 +20,7 @@ import json
|
||||
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from petstore_api.models.outer_enum import OuterEnum
|
||||
from petstore_api.models.outer_enum_integer import OuterEnumInteger
|
||||
|
||||
@ -29,7 +29,7 @@ class OuterObjectWithEnumProperty(BaseModel):
|
||||
OuterObjectWithEnumProperty
|
||||
"""
|
||||
str_value: Optional[OuterEnum] = None
|
||||
value: OuterEnumInteger = ...
|
||||
value: OuterEnumInteger = Field(...)
|
||||
__properties = ["str_value", "value"]
|
||||
|
||||
class Config:
|
||||
|
@ -30,7 +30,7 @@ class Pet(BaseModel):
|
||||
"""
|
||||
id: Optional[StrictInt] = None
|
||||
category: Optional[Category] = None
|
||||
name: StrictStr = ...
|
||||
name: StrictStr = Field(...)
|
||||
photo_urls: conlist(StrictStr, min_items=0, unique_items=True) = Field(..., alias="photoUrls")
|
||||
tags: Optional[conlist(Tag)] = None
|
||||
status: Optional[StrictStr] = Field(None, description="pet status in the store")
|
||||
|
@ -27,7 +27,7 @@ class BasquePig(BaseModel):
|
||||
BasquePig
|
||||
"""
|
||||
class_name: StrictStr = Field(..., alias="className")
|
||||
color: StrictStr = ...
|
||||
color: StrictStr = Field(...)
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["className", "color"]
|
||||
|
||||
|
@ -20,14 +20,14 @@ import json
|
||||
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, StrictInt, StrictStr
|
||||
from pydantic import BaseModel, Field, StrictInt, StrictStr
|
||||
|
||||
class Category(BaseModel):
|
||||
"""
|
||||
Category
|
||||
"""
|
||||
id: Optional[StrictInt] = None
|
||||
name: StrictStr = ...
|
||||
name: StrictStr = Field(...)
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["id", "name"]
|
||||
|
||||
|
@ -27,7 +27,7 @@ class DanishPig(BaseModel):
|
||||
DanishPig
|
||||
"""
|
||||
class_name: StrictStr = Field(..., alias="className")
|
||||
size: StrictInt = ...
|
||||
size: StrictInt = Field(...)
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["className", "size"]
|
||||
|
||||
|
@ -31,7 +31,7 @@ class EnumTest(BaseModel):
|
||||
EnumTest
|
||||
"""
|
||||
enum_string: Optional[StrictStr] = None
|
||||
enum_string_required: StrictStr = ...
|
||||
enum_string_required: StrictStr = Field(...)
|
||||
enum_integer_default: Optional[StrictInt] = 5
|
||||
enum_integer: Optional[StrictInt] = None
|
||||
enum_number: Optional[StrictFloat] = None
|
||||
|
@ -29,7 +29,7 @@ class FormatTest(BaseModel):
|
||||
integer: Optional[conint(strict=True, le=100, ge=10)] = None
|
||||
int32: Optional[conint(strict=True, le=200, ge=20)] = None
|
||||
int64: Optional[StrictInt] = None
|
||||
number: confloat(le=543.2, ge=32.1, strict=True) = ...
|
||||
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
|
||||
@ -40,7 +40,7 @@ class FormatTest(BaseModel):
|
||||
var_date: date = Field(..., alias="date")
|
||||
date_time: Optional[datetime] = Field(None, alias="dateTime")
|
||||
uuid: Optional[StrictStr] = None
|
||||
password: constr(strict=True, max_length=64, min_length=10) = ...
|
||||
password: constr(strict=True, max_length=64, min_length=10) = Field(...)
|
||||
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] = {}
|
||||
|
@ -26,7 +26,7 @@ class Name(BaseModel):
|
||||
"""
|
||||
Model for testing model name same as property name
|
||||
"""
|
||||
name: StrictInt = ...
|
||||
name: StrictInt = Field(...)
|
||||
snake_case: Optional[StrictInt] = None
|
||||
var_property: Optional[StrictStr] = Field(None, alias="property")
|
||||
var_123_number: Optional[StrictInt] = Field(None, alias="123Number")
|
||||
|
@ -20,13 +20,13 @@ import json
|
||||
|
||||
from datetime import date, datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
from pydantic import BaseModel, StrictBool, StrictFloat, StrictInt, StrictStr, conlist
|
||||
from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr, conlist
|
||||
|
||||
class NullableClass(BaseModel):
|
||||
"""
|
||||
NullableClass
|
||||
"""
|
||||
required_integer_prop: Optional[StrictInt] = ...
|
||||
required_integer_prop: Optional[StrictInt] = Field(...)
|
||||
integer_prop: Optional[StrictInt] = None
|
||||
number_prop: Optional[StrictFloat] = None
|
||||
boolean_prop: Optional[StrictBool] = None
|
||||
|
@ -20,7 +20,7 @@ import json
|
||||
|
||||
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from petstore_api.models.outer_enum import OuterEnum
|
||||
from petstore_api.models.outer_enum_integer import OuterEnumInteger
|
||||
|
||||
@ -29,7 +29,7 @@ class OuterObjectWithEnumProperty(BaseModel):
|
||||
OuterObjectWithEnumProperty
|
||||
"""
|
||||
str_value: Optional[OuterEnum] = None
|
||||
value: OuterEnumInteger = ...
|
||||
value: OuterEnumInteger = Field(...)
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["str_value", "value"]
|
||||
|
||||
|
@ -30,7 +30,7 @@ class Pet(BaseModel):
|
||||
"""
|
||||
id: Optional[StrictInt] = None
|
||||
category: Optional[Category] = None
|
||||
name: StrictStr = ...
|
||||
name: StrictStr = Field(...)
|
||||
photo_urls: conlist(StrictStr, min_items=0, unique_items=True) = Field(..., alias="photoUrls")
|
||||
tags: Optional[conlist(Tag)] = None
|
||||
status: Optional[StrictStr] = Field(None, description="pet status in the store")
|
||||
|
Loading…
x
Reference in New Issue
Block a user