[Python] Handle nullable list items (#17594)

* fix nullable elements

* update type info in docs

* update examples
This commit is contained in:
Huan-Cheng Chang
2024-01-13 04:29:22 +01:00
committed by GitHub
parent c6efe8810d
commit 968c6dc418
14 changed files with 49 additions and 16 deletions

View File

@@ -5,6 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**array_of_string** | **List[str]** | | [optional]
**array_of_nullable_float** | **List[float]** | | [optional]
**array_array_of_integer** | **List[List[int]]** | | [optional]
**array_array_of_model** | **List[List[ReadOnlyFirst]]** | | [optional]

View File

@@ -19,7 +19,7 @@ import json
from typing import Any, Dict, List, Optional
from pydantic import BaseModel, StrictInt, StrictStr, conlist
from pydantic import BaseModel, StrictFloat, StrictInt, StrictStr, conlist
from petstore_api.models.read_only_first import ReadOnlyFirst
class ArrayTest(BaseModel):
@@ -27,10 +27,11 @@ class ArrayTest(BaseModel):
ArrayTest
"""
array_of_string: Optional[conlist(StrictStr, max_items=3, min_items=0)] = None
array_of_nullable_float: Optional[conlist(StrictFloat)] = None
array_array_of_integer: Optional[conlist(conlist(StrictInt))] = None
array_array_of_model: Optional[conlist(conlist(ReadOnlyFirst))] = None
additional_properties: Dict[str, Any] = {}
__properties = ["array_of_string", "array_array_of_integer", "array_array_of_model"]
__properties = ["array_of_string", "array_of_nullable_float", "array_array_of_integer", "array_array_of_model"]
class Config:
"""Pydantic configuration"""
@@ -84,6 +85,7 @@ class ArrayTest(BaseModel):
_obj = ArrayTest.parse_obj({
"array_of_string": obj.get("array_of_string"),
"array_of_nullable_float": obj.get("array_of_nullable_float"),
"array_array_of_integer": obj.get("array_array_of_integer"),
"array_array_of_model": [
[ReadOnlyFirst.from_dict(_inner_item) for _inner_item in _item]