-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: external references to parent folder (#1999)
* Add support for external referenced discriminators * Fix discriminator reference in parent folder * Extend test case * post-fork-sync fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix formatting * add test case for whole folder * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ruff format --------- Co-authored-by: Koudai Aono <koxudaxi@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b1c0f22
commit 5727116
Showing
17 changed files
with
180 additions
and
14 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
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
3 changes: 3 additions & 0 deletions
3
tests/data/expected/main/discriminator_with_external_references_folder/__init__.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,3 @@ | ||
# generated by datamodel-codegen: | ||
# filename: discriminator_with_external_reference | ||
# timestamp: 2019-07-26T00:00:00+00:00 |
3 changes: 3 additions & 0 deletions
3
...data/expected/main/discriminator_with_external_references_folder/inner_folder/__init__.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,3 @@ | ||
# generated by datamodel-codegen: | ||
# filename: discriminator_with_external_reference | ||
# timestamp: 2019-07-26T00:00:00+00:00 |
3 changes: 3 additions & 0 deletions
3
.../discriminator_with_external_references_folder/inner_folder/artificial_folder/__init__.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,3 @@ | ||
# generated by datamodel-codegen: | ||
# filename: discriminator_with_external_reference | ||
# timestamp: 2019-07-26T00:00:00+00:00 |
12 changes: 12 additions & 0 deletions
12
...in/discriminator_with_external_references_folder/inner_folder/artificial_folder/type_1.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,12 @@ | ||
# generated by datamodel-codegen: | ||
# filename: inner_folder/artificial_folder/type-1.json | ||
# timestamp: 2019-07-26T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from pydantic import BaseModel, Field | ||
from typing_extensions import Literal | ||
|
||
|
||
class Type1(BaseModel): | ||
type_: Literal['a'] = Field(..., const=True, title='Type ') |
25 changes: 25 additions & 0 deletions
25
...s/data/expected/main/discriminator_with_external_references_folder/inner_folder/schema.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,25 @@ | ||
# generated by datamodel-codegen: | ||
# filename: inner_folder/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 | ||
|
||
from .. import type_4 | ||
from ..subfolder import type_5 | ||
from . import type_2 | ||
from .artificial_folder import type_1 | ||
|
||
|
||
class Type3(BaseModel): | ||
type_: Literal['c'] = Field(..., const=True, title='Type ') | ||
|
||
|
||
class Response(BaseModel): | ||
inner: Union[type_1.Type1, type_2.Type2, Type3, type_4.Type4, type_5.Type5] = Field( | ||
..., discriminator='type_', title='Inner' | ||
) |
16 changes: 16 additions & 0 deletions
16
...s/data/expected/main/discriminator_with_external_references_folder/inner_folder/type_2.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,16 @@ | ||
# generated by datamodel-codegen: | ||
# filename: inner_folder/type-2.json | ||
# timestamp: 2019-07-26T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from .artificial_folder import type_1 | ||
|
||
|
||
class Type2(BaseModel): | ||
type_: Literal['b'] = Field(..., const=True, title='Type ') | ||
ref_type: Optional[type_1.Type1] = Field(None, description='A referenced type.') |
3 changes: 3 additions & 0 deletions
3
tests/data/expected/main/discriminator_with_external_references_folder/subfolder/__init__.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,3 @@ | ||
# generated by datamodel-codegen: | ||
# filename: discriminator_with_external_reference | ||
# timestamp: 2019-07-26T00:00:00+00:00 |
11 changes: 11 additions & 0 deletions
11
tests/data/expected/main/discriminator_with_external_references_folder/subfolder/type_5.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,11 @@ | ||
# generated by datamodel-codegen: | ||
# filename: subfolder/type-5.json | ||
# timestamp: 2019-07-26T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class Type5(BaseModel): | ||
type_: Literal['e'] = Field(..., const=True, title='Type ') |
11 changes: 11 additions & 0 deletions
11
tests/data/expected/main/discriminator_with_external_references_folder/type_4.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,11 @@ | ||
# generated by datamodel-codegen: | ||
# filename: type-4.json | ||
# timestamp: 2019-07-26T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class Type4(BaseModel): | ||
type_: Literal['d'] = Field(..., const=True, title='Type ') |
File renamed without changes.
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
15 changes: 15 additions & 0 deletions
15
tests/data/jsonschema/discriminator_with_external_reference/inner_folder/type-2.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,15 @@ | ||
{ | ||
"properties": { | ||
"type_": { | ||
"const": "b", | ||
"default": "b", | ||
"title": "Type " | ||
}, | ||
"ref_type": { | ||
"$ref": "./artificial_folder/type-1.json", | ||
"description": "A referenced type." | ||
} | ||
}, | ||
"title": "Type2", | ||
"type": "object" | ||
} |
6 changes: 3 additions & 3 deletions
6
...inator_with_external_reference/type2.json → ..._external_reference/subfolder/type-5.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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"properties": { | ||
"type_": { | ||
"const": "b", | ||
"default": "b", | ||
"const": "e", | ||
"default": "e", | ||
"title": "Type " | ||
} | ||
}, | ||
"title": "Type2", | ||
"title": "Type5", | ||
"type": "object" | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/data/jsonschema/discriminator_with_external_reference/type-4.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": "d", | ||
"default": "d", | ||
"title": "Type " | ||
} | ||
}, | ||
"title": "Type4", | ||
"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