Skip to content

Commit

Permalink
Fix type in anyof (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi authored Jan 31, 2021
1 parent 6b53335 commit c4a1852
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion datamodel_code_generator/parser/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,14 @@ def parse_list_item(
data_types=[self.get_data_type(item.items)], is_list=True,
)
)
else:
elif item.is_object:
data_types.append(
self.parse_object(
name, item, [*path, str(index)], singular_name=True,
)
)
else:
data_types.append(self.get_data_type(item))
return self.data_type(data_types=data_types)

def parse_any_of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import date
from typing import List, Optional, Union

from pydantic import BaseModel
from pydantic import BaseModel, constr


class Pet(BaseModel):
Expand All @@ -23,15 +23,15 @@ class AnyOfItemItem(BaseModel):


class AnyOfItem(BaseModel):
__root__: Union[Pet, Car, AnyOfItemItem]
__root__: Union[Pet, Car, AnyOfItemItem, constr(max_length=5000)]


class ItemItem(BaseModel):
name: Optional[str] = None


class AnyOfobj(BaseModel):
item: Optional[Union[Pet, Car, ItemItem]] = None
item: Optional[Union[Pet, Car, ItemItem, constr(max_length=5000)]] = None


class AnyOfArrayItem(BaseModel):
Expand All @@ -40,7 +40,7 @@ class AnyOfArrayItem(BaseModel):


class AnyOfArray(BaseModel):
__root__: List[Union[Pet, Car, AnyOfArrayItem]]
__root__: List[Union[Pet, Car, AnyOfArrayItem, constr(max_length=5000)]]


class Error(BaseModel):
Expand Down
7 changes: 6 additions & 1 deletion tests/data/openapi/anyof.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ components:
properties:
name:
type: string

- type: string
maxLength: 5000
AnyOfobj:
type: object
properties:
Expand All @@ -143,6 +144,8 @@ components:
properties:
name:
type: string
- type: string
maxLength: 5000
AnyOfArray:
type: array
items:
Expand All @@ -156,6 +159,8 @@ components:
birthday:
type: string
format: date
- type: string
maxLength: 5000
Error:
required:
- code
Expand Down

0 comments on commit c4a1852

Please sign in to comment.