datamodel-code-generator
datamodel-code-generator copied to clipboard
mixing additionalProperties and required properties doesn't work with pydantic
with version 0.25.1 having a schema like
RCloneConfig:
type: object
description: Dictionary of rclone key:value pairs (based on schema from '/storage_schema')
properties:
type:
type: string
required:
- type
additionalProperties:
oneOf:
- type: number
- type: string
nullable: true
- type: boolean
- type: object
gives python code like
class RCloneConfig(BaseAPISpec):
type: str
which causes pydantic to ignore anything except type
.
without the required property no class is generated and parent classes refer directly to Optional[Dict[str, Union[float, Optional[str], bool, Dict[str, Any]]]]
I'm not even sure this can be properly modeled in pydantic, with both validating the required property and checking that the arbitrary types conform to the correct value types (Extra.allow wouldn't check the value types). But thought I'd report it anyways just in case.
@Panaetius I'm sorry for my late reply.
This is an issue that should be addressed. Just give me a few days as the implementation is a bit complicated.