-
-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change ordering of actions #1961
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
81e1e89
Change ordering of actions
prmshepherd 42760dc
Merge branch 'main' into main
koxudaxi 57a519f
Merge branch 'main' into main
koxudaxi 77af397
Merge branch 'koxudaxi:main' into main
prmshepherd ffd6451
Add test case
prmshepherd bdf17c4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ad0bf1f
Add test data
prmshepherd d9562e4
Remove breakpoint
prmshepherd 8bd40ef
Remove unused arguments
prmshepherd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 32 additions & 0 deletions
32
tests/data/expected/main/openapi/discriminator/enum_one_literal_as_default.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,32 @@ | ||
# generated by datamodel-codegen: | ||
# filename: discriminator_enum.yaml | ||
# timestamp: 2019-07-26T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from typing import Literal, Union | ||
|
||
from pydantic import BaseModel, Field, RootModel | ||
|
||
|
||
class RequestVersionEnum(Enum): | ||
v1 = 'v1' | ||
v2 = 'v2' | ||
|
||
|
||
class RequestBase(BaseModel): | ||
version: RequestVersionEnum | ||
|
||
|
||
class RequestV1(RequestBase): | ||
request_id: str = Field(..., description='there is description', title='test title') | ||
version: Literal['v1'] = 'v1' | ||
|
||
|
||
class RequestV2(RequestBase): | ||
version: Literal['v2'] = 'v2' | ||
|
||
|
||
class Request(RootModel[Union[RequestV1, RequestV2]]): | ||
root: Union[RequestV1, RequestV2] = Field(..., discriminator='version') |
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 |
---|---|---|
|
@@ -2798,3 +2798,31 @@ def test_main_openapi_msgspec_use_annotated_with_field_constraints(): | |
/ 'msgspec_use_annotated_with_field_constraints.py' | ||
).read_text() | ||
) | ||
|
||
|
||
@freeze_time('2019-07-26') | ||
def test_main_openapi_discriminator_one_literal_as_default(input, output): | ||
with TemporaryDirectory() as output_dir: | ||
output_file: Path = Path(output_dir) / 'output.py' | ||
return_code: Exit = main( | ||
[ | ||
'--input', | ||
str(OPEN_API_DATA_PATH / 'discriminator_enum.yaml'), | ||
'--output', | ||
str(output_file), | ||
'--input-file-type', | ||
'openapi', | ||
'--output-model-type', | ||
'pydantic_v2.BaseModel', | ||
'--use-one-literal-as-default', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting --use-one-literal-as-default in the test |
||
] | ||
) | ||
assert return_code == Exit.OK | ||
assert ( | ||
output_file.read_text() | ||
== ( | ||
EXPECTED_OPENAPI_PATH | ||
/ 'discriminator' | ||
/ 'enum_one_literal_as_default.py' | ||
).read_text() | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generator now correctly adds the default for the literal