-
-
Notifications
You must be signed in to change notification settings - Fork 228
Don't generate extra models for allOf
, oneOf
, or anyOf
of one model
#361
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e2b86a
Prevent union of one model from generating new model
forest-benchling 1bd832b
Regen with nullable
forest-benchling 48b9de9
Add unit test
forest-benchling 30f69bc
Lint
forest-benchling f0fed56
Remove golden-record-custom
forest-benchling da5c8a9
Use suggestion
forest-benchling 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
154 changes: 154 additions & 0 deletions
154
end_to_end_tests/golden-record-custom/custom_e2e/api/tests/defaults_tests_defaults_post.py
This file contains hidden or 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,154 @@ | ||
from typing import Optional | ||
|
||
import httpx | ||
|
||
from ...types import Response | ||
|
||
Client = httpx.Client | ||
|
||
import datetime | ||
from typing import Dict, List, Optional, Union | ||
|
||
from dateutil.parser import isoparse | ||
|
||
from ...models.an_enum import AnEnum | ||
from ...models.http_validation_error import HTTPValidationError | ||
from ...models.model_with_union_property import ModelWithUnionProperty | ||
from ...types import UNSET, Unset | ||
|
||
|
||
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]: | ||
if response.status_code == 200: | ||
response_200 = None | ||
|
||
return response_200 | ||
if response.status_code == 422: | ||
response_422 = HTTPValidationError.from_dict(response.json()) | ||
|
||
return response_422 | ||
return None | ||
|
||
|
||
def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]: | ||
return Response( | ||
status_code=response.status_code, | ||
content=response.content, | ||
headers=response.headers, | ||
parsed=_parse_response(response=response), | ||
) | ||
|
||
|
||
def httpx_request( | ||
*, | ||
client: Client, | ||
string_prop: Union[Unset, str] = "the default string", | ||
not_required_not_nullable_datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
not_required_nullable_datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
required_not_nullable_datetime_prop: datetime.datetime = isoparse("1010-10-10T00:00:00"), | ||
required_nullable_datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Union[Unset, float] = 3.14, | ||
int_prop: Union[Unset, int] = 7, | ||
boolean_prop: Union[Unset, bool] = False, | ||
list_prop: Union[Unset, List[AnEnum]] = UNSET, | ||
union_prop: Union[Unset, float, str] = "not a float", | ||
union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, | ||
enum_prop: Union[Unset, AnEnum] = UNSET, | ||
model_prop: Union[Unset, ModelWithUnionProperty] = UNSET, | ||
required_model_prop: ModelWithUnionProperty, | ||
nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, | ||
nullable_required_model_prop: Optional[ModelWithUnionProperty], | ||
) -> Response[Union[None, HTTPValidationError]]: | ||
|
||
json_not_required_not_nullable_datetime_prop: Union[Unset, str] = UNSET | ||
if not isinstance(not_required_not_nullable_datetime_prop, Unset): | ||
json_not_required_not_nullable_datetime_prop = not_required_not_nullable_datetime_prop.isoformat() | ||
|
||
json_not_required_nullable_datetime_prop: Union[Unset, None, str] = UNSET | ||
if not isinstance(not_required_nullable_datetime_prop, Unset): | ||
json_not_required_nullable_datetime_prop = ( | ||
not_required_nullable_datetime_prop.isoformat() if not_required_nullable_datetime_prop else None | ||
) | ||
|
||
json_required_not_nullable_datetime_prop = required_not_nullable_datetime_prop.isoformat() | ||
|
||
json_required_nullable_datetime_prop = ( | ||
required_nullable_datetime_prop.isoformat() if required_nullable_datetime_prop else None | ||
) | ||
|
||
json_date_prop: Union[Unset, str] = UNSET | ||
if not isinstance(date_prop, Unset): | ||
json_date_prop = date_prop.isoformat() | ||
|
||
json_list_prop: Union[Unset, List[str]] = UNSET | ||
if not isinstance(list_prop, Unset): | ||
json_list_prop = [] | ||
for list_prop_item_data in list_prop: | ||
list_prop_item = list_prop_item_data.value | ||
|
||
json_list_prop.append(list_prop_item) | ||
|
||
json_union_prop: Union[Unset, float, str] | ||
if isinstance(union_prop, Unset): | ||
json_union_prop = UNSET | ||
else: | ||
json_union_prop = union_prop | ||
|
||
json_union_prop_with_ref: Union[Unset, float, str] | ||
if isinstance(union_prop_with_ref, Unset): | ||
json_union_prop_with_ref = UNSET | ||
elif isinstance(union_prop_with_ref, AnEnum): | ||
json_union_prop_with_ref = UNSET | ||
if not isinstance(union_prop_with_ref, Unset): | ||
json_union_prop_with_ref = union_prop_with_ref.value | ||
|
||
else: | ||
json_union_prop_with_ref = union_prop_with_ref | ||
|
||
json_enum_prop: Union[Unset, str] = UNSET | ||
if not isinstance(enum_prop, Unset): | ||
json_enum_prop = enum_prop.value | ||
|
||
json_model_prop: Union[Unset, Dict[str, Any]] = UNSET | ||
if not isinstance(model_prop, Unset): | ||
json_model_prop = model_prop.to_dict() | ||
|
||
json_required_model_prop = required_model_prop.to_dict() | ||
|
||
json_nullable_model_prop: Union[Unset, None, Dict[str, Any]] = UNSET | ||
if not isinstance(nullable_model_prop, Unset): | ||
json_nullable_model_prop = nullable_model_prop.to_dict() if nullable_model_prop else None | ||
|
||
json_nullable_required_model_prop = nullable_required_model_prop.to_dict() if nullable_required_model_prop else None | ||
|
||
params: Dict[str, Any] = { | ||
"string_prop": string_prop, | ||
"not_required_not_nullable_datetime_prop": json_not_required_not_nullable_datetime_prop, | ||
"not_required_nullable_datetime_prop": json_not_required_nullable_datetime_prop, | ||
"required_not_nullable_datetime_prop": json_required_not_nullable_datetime_prop, | ||
"required_nullable_datetime_prop": json_required_nullable_datetime_prop, | ||
"date_prop": json_date_prop, | ||
"float_prop": float_prop, | ||
"int_prop": int_prop, | ||
"boolean_prop": boolean_prop, | ||
"list_prop": json_list_prop, | ||
"union_prop": json_union_prop, | ||
"union_prop_with_ref": json_union_prop_with_ref, | ||
"enum_prop": json_enum_prop, | ||
} | ||
if not isinstance(json_model_prop, Unset): | ||
params.update(json_model_prop) | ||
params.update(json_required_model_prop) | ||
if not isinstance(json_nullable_model_prop, Unset) and json_nullable_model_prop is not None: | ||
params.update(json_nullable_model_prop) | ||
if json_nullable_required_model_prop is not None: | ||
params.update(json_nullable_required_model_prop) | ||
params = {k: v for k, v in params.items() if v is not UNSET and v is not None} | ||
|
||
response = client.request( | ||
"post", | ||
"/tests/defaults", | ||
params=params, | ||
) | ||
|
||
return _build_response(response=response) |
28 changes: 28 additions & 0 deletions
28
end_to_end_tests/golden-record-custom/custom_e2e/models/__init__.py
This file contains hidden or 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,28 @@ | ||
""" Contains all the data models used in inputs/outputs """ | ||
|
||
from .a_model import AModel | ||
from .all_of_sub_model import AllOfSubModel | ||
from .an_enum import AnEnum | ||
from .an_int_enum import AnIntEnum | ||
from .another_all_of_sub_model import AnotherAllOfSubModel | ||
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost | ||
from .different_enum import DifferentEnum | ||
from .free_form_model import FreeFormModel | ||
from .http_validation_error import HTTPValidationError | ||
from .model_from_all_of import ModelFromAllOf | ||
from .model_with_additional_properties_inlined import ModelWithAdditionalPropertiesInlined | ||
from .model_with_additional_properties_inlined_additional_property import ( | ||
ModelWithAdditionalPropertiesInlinedAdditionalProperty, | ||
) | ||
from .model_with_additional_properties_refed import ModelWithAdditionalPropertiesRefed | ||
from .model_with_any_json_properties import ModelWithAnyJsonProperties | ||
from .model_with_any_json_properties_additional_property_type0 import ModelWithAnyJsonPropertiesAdditionalPropertyType0 | ||
from .model_with_primitive_additional_properties import ModelWithPrimitiveAdditionalProperties | ||
from .model_with_primitive_additional_properties_a_date_holder import ModelWithPrimitiveAdditionalPropertiesADateHolder | ||
from .model_with_union_property import ModelWithUnionProperty | ||
from .model_with_union_property_inlined import ModelWithUnionPropertyInlined | ||
from .model_with_union_property_inlined_fruit_type0 import ModelWithUnionPropertyInlinedFruitType0 | ||
from .model_with_union_property_inlined_fruit_type1 import ModelWithUnionPropertyInlinedFruitType1 | ||
from .test_inline_objects_json_body import TestInlineObjectsJsonBody | ||
from .test_inline_objects_response_200 import TestInlineObjectsResponse_200 | ||
from .validation_error import ValidationError |
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 main branch no longer has
golden-record-custom
. I removed the full generation there since it was redundant and we really just needed to test that a custom template would be applied. So these files can be removed