Skip to content

Commit

Permalink
fix, python: just use jsonable_encoder and remove .value from enum re…
Browse files Browse the repository at this point in the history
…ferences (#3044)

* just use jsonable_encoder

* bump version

* run lint

* ignore enum too
  • Loading branch information
armandobelardo authored Feb 23, 2024
1 parent d22f7e1 commit d97c5cc
Show file tree
Hide file tree
Showing 115 changed files with 4,701 additions and 734 deletions.
3 changes: 3 additions & 0 deletions generators/python/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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).

## [0.11.4] - 2024-02-23

- Fix: We now grab enum values appropriately when enums are within unions.

## [0.11.3] - 2024-02-22

Expand Down
2 changes: 1 addition & 1 deletion generators/python/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.3
0.11.4
Original file line number Diff line number Diff line change
Expand Up @@ -532,19 +532,18 @@ def write(writer: AST.NodeWriter) -> None:
writer.write_node(AST.Expression(f"{possible_path_part_literal}"))
else:
writer.write("{")
if self._context.resolved_schema_is_enum(reference=parameter_obj.value_type):
writer.write(f"{get_parameter_name(parameter_obj.name)}.value")
elif self._context.resolved_schema_is_optional_enum(reference=parameter_obj.value_type):
writer.write(f"{get_parameter_name(parameter_obj.name)}.value")
else:
writer.write(
get_parameter_name(
self._get_path_parameter_from_name(
endpoint=endpoint,
path_parameter_name=part.path_parameter,
).name,
writer.write_node(
self._context.core_utilities.jsonable_encoder(
AST.Expression(
get_parameter_name(
self._get_path_parameter_from_name(
endpoint=endpoint,
path_parameter_name=part.path_parameter,
).name,
)
)
)
)
writer.write("}")
writer.write(part.tail)
writer.write('"')
Expand Down Expand Up @@ -644,12 +643,6 @@ def write_ternary(writer: AST.NodeWriter) -> None:

reference = AST.Expression(AST.CodeWriter(write_ternary))

elif self._context.resolved_schema_is_enum(reference=query_parameter.value_type):
return AST.Expression(f"{parameter_name}.value")

elif self._context.resolved_schema_is_optional_enum(reference=query_parameter.value_type):
return AST.Expression(f"{parameter_name}.value if {parameter_name} is not None else None")

elif not self._is_httpx_primitive_data(query_parameter.value_type, allow_optional=True):
reference = self._context.core_utilities.jsonable_encoder(reference)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ def write(writer: AST.NodeWriter) -> None:
with writer.indent():
for required_property in required_properties:
literal_value = self._context.get_literal_value(reference=required_property.value_type)
if self._context.resolved_schema_is_enum(reference=required_property.value_type):
writer.write_line(
f'"{required_property.name.wire_value}": {self._get_property_name(required_property)}.value,'
)
elif literal_value is not None and type(literal_value) is str:
if literal_value is not None and type(literal_value) is str:
writer.write_line(f'"{required_property.name.wire_value}": "{literal_value}",')
elif literal_value is not None and type(literal_value) is bool:
writer.write_line(f'"{required_property.name.wire_value}": {literal_value},')
Expand Down
Loading

0 comments on commit d97c5cc

Please sign in to comment.