oneOf is not treated the same as anyOf
See original GitHub issueDescribe the bug
The docs indicate that they are both treated as typing.Union
To Reproduce
Example schema:
components:
schemas:
Config:
properties:
setting:
type: object
additionalProperties:
oneOf: # anyOf
- type: string
- type: array
items:
type: string
Used commandline:
$ datamodel-codegen --input-file-type openapi --strip-default-none --input test.yaml --output model.py
oneOf
:
from __future__ import annotations
from typing import Any, Dict, Optional
from pydantic import BaseModel, Extra
class Setting(BaseModel):
class Config:
extra = Extra.allow
__root__: Any
class Config(BaseModel):
setting: Optional[Dict[str, Setting]]
anyOf
:
from __future__ import annotations
from typing import Dict, List, Optional, Union
from pydantic import BaseModel, Extra
class Setting(BaseModel):
class Config:
extra = Extra.allow
__root__: Union[str, List[str]]
class Config(BaseModel):
setting: Optional[Dict[str, Setting]]
Version:
- OS: Windows 10
- Python version: 3.8
- datamodel-code-generator version: 0.7.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
oneOf, anyOf, allOf, not - Swagger
Use the oneOf keyword to ensure the given data is valid against one of the specified ... Note the inline or referenced schema...
Read more >Components are not referenced when combined with oneOf ...
When combining multiple schemas with oneOf, anyOf, allOf or not that where previously added to components, they will not get referenced.
Read more >Best Match for Validation error with oneof or anyof
I am trying to get proper validation error from oneof or anyof pattern. I have json schema with two or more ...
Read more >Frequently Asked Questions - Ajv JSON schema validator
Why don't "additionalProperties": false errors display the property name? Additional properties inside compound keywords anyOf, oneOf, etc. Why the keyword ...
Read more >Understanding JSON Schema
JSON Schema is a powerful tool for validating the structure of JSON data. However, learning to use it by reading its.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed!!! 🙇
@ofek I have released a fixed version
0.7.3