Skip to content

Commit

Permalink
Revert "(fix): inline discriminated union props" (#3408)
Browse files Browse the repository at this point in the history
* Revert "(fix, python): inline discriminated union props (#3404)"

This reverts commit f5b73f6.

* Update VERSION
  • Loading branch information
dsinghvi authored Apr 19, 2024
1 parent 2e0f42d commit 0f48c5a
Show file tree
Hide file tree
Showing 93 changed files with 518 additions and 862 deletions.
26 changes: 0 additions & 26 deletions generators/python/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.0-rc1] - 2024-04-04

- Fix: Discriminated union variants that are objects now have inlined properties instead of
extending a base type.

```python

Circle_Shape(pydantic_v1.BaseModel):
type: typing.Literal["circle"]
radius: integer

Square_Shape(pydantic_v1.BaseModel):
type: typing.Literal["circle"]
side: integer
```

instead of

```python
Circle_Shape(Circle):
type: typing.Literal["circle"]

Square_Shape(Square):
type: typing.Literal["circle"]
```

## [1.2.0-rc0] - 2024-04-04

- Feature: The generator now depends on v38 of Intermediate Representation which requires the latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ def generate(self) -> None:
)

for single_union_type in self._union.types:
single_union_type_base = single_union_type.shape.visit(
same_properties_as_object=lambda type_name: type_name,
single_property=lambda property_: None,
no_properties=lambda: None,
)
base_models = []
if single_union_type_base is not None:
base_models.append(self._context.get_class_reference_for_type_id(single_union_type_base.type_id))
all_referenced_types.append(ir_types.TypeReference.factory.named(single_union_type_base))

if class_reference_for_base is not None:
base_models.append(class_reference_for_base)
Expand Down Expand Up @@ -117,19 +125,6 @@ def generate(self) -> None:
)
)
all_referenced_types.append(shape.type)
elif shape.properties_type == "samePropertiesAsObject":
object_properties = self._context.get_all_properties_including_extensions(shape.type_id)
for object_property in object_properties:
internal_pydantic_model_for_single_union_type.add_field(
PydanticField(
name=object_property.name.name.snake_case.unsafe_name,
pascal_case_field_name=object_property.name.name.pascal_case.unsafe_name,
json_field_name=object_property.name.wire_value,
type_hint=self._context.get_type_hint_for_type_reference(
type_reference=object_property.value_type
),
)
)

# if any of our fields are forward refs, we need to call
# update_forwards_refs()
Expand Down
2 changes: 1 addition & 1 deletion seed/fastapi/seed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ allowedFailures:
- literal
- websocket
- enum
- server-sent-events
- server-sent-events.
75 changes: 1 addition & 74 deletions seed/fastapi/server-sent-events/.inputs/ir.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions seed/fastapi/streaming/.inputs/ir.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0f48c5a

Please sign in to comment.