-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for external referenced discriminators (#1991)
Co-authored-by: Koudai Aono <[email protected]>
- Loading branch information
1 parent
e68629d
commit b1c0f22
Showing
6 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/data/expected/main/discriminator_with_external_reference/output.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# generated by datamodel-codegen: | ||
# filename: schema.json | ||
# timestamp: 2019-07-26T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Union | ||
|
||
from pydantic import BaseModel, Field | ||
from typing_extensions import Literal | ||
|
||
|
||
class Type1(BaseModel): | ||
type_: Literal['a'] = Field('a', title='Type ') | ||
|
||
|
||
class Type2(BaseModel): | ||
type_: Literal['b'] = Field('b', title='Type ') | ||
|
||
|
||
class Type3(BaseModel): | ||
type_: Literal['c'] = Field('c', title='Type ') | ||
|
||
|
||
class Response(BaseModel): | ||
inner: Union[Type1, Type2, Type3] = Field(..., discriminator='type_', title='Inner') |
11 changes: 11 additions & 0 deletions
11
tests/data/jsonschema/discriminator_with_external_reference/artificial_folder/type1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"properties": { | ||
"type_": { | ||
"const": "a", | ||
"default": "a", | ||
"title": "Type " | ||
} | ||
}, | ||
"title": "Type1", | ||
"type": "object" | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/data/jsonschema/discriminator_with_external_reference/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"$def": { | ||
"Type3": { | ||
"properties": { | ||
"type_": { | ||
"const": "c", | ||
"default": "c", | ||
"title": "Type " | ||
} | ||
}, | ||
"title": "Type3", | ||
"type": "object" | ||
} | ||
}, | ||
"properties": { | ||
"inner": { | ||
"discriminator": { | ||
"mapping": { | ||
"a": "./artificial_folder/type1.json", | ||
"b": "./type2.json", | ||
"c": "#/$def/Type3" | ||
}, | ||
"propertyName": "type_" | ||
}, | ||
"oneOf": [ | ||
{ | ||
"$ref": "./artificial_folder/type1.json" | ||
}, | ||
{ | ||
"$ref": "./type2.json" | ||
}, | ||
{ | ||
"$ref": "#/$def/Type3" | ||
} | ||
], | ||
"title": "Inner" | ||
} | ||
}, | ||
"required": [ | ||
"inner" | ||
], | ||
"title": "Response", | ||
"type": "object" | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/data/jsonschema/discriminator_with_external_reference/type2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"properties": { | ||
"type_": { | ||
"const": "b", | ||
"default": "b", | ||
"title": "Type " | ||
} | ||
}, | ||
"title": "Type2", | ||
"type": "object" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters