From 4d03450d9b67b7c34834c7bc976e20302405c642 Mon Sep 17 00:00:00 2001 From: Kevin Zou <17015060+nkzou@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:10:15 -0500 Subject: [PATCH] Fix example primitive oneOf variants getting option wrapped (#427) --- .generator/src/generator/formatter.py | 5 ++--- .generator/src/generator/openapi.py | 2 +- generate.sh | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.generator/src/generator/formatter.py b/.generator/src/generator/formatter.py index bfe2f37df..cab051f12 100644 --- a/.generator/src/generator/formatter.py +++ b/.generator/src/generator/formatter.py @@ -360,7 +360,7 @@ def _format_oneof(schema, data, name, replace_values, imports, **kwargs): one_of_schema_name = schema_name(one_of_schema) if not one_of_schema_name: - one_of_schema_name = simple_type(one_of_schema).title() + one_of_schema_name = simple_type(one_of_schema, render_option=False).title() if not is_primitive(one_of_schema) and one_of_schema.get("type") != "array": # TODO: revisit possibility of removing all boxes @@ -491,7 +491,6 @@ def open_file(x): parameters = f"{parameters}" return parameters, imports - if (not required or schema.get("nullable")) and schema.get("type") is not None: imports.update(extra_imports) return reference_to_value(schema, parameters, print_nullable=True, **kwargs), imports @@ -500,7 +499,7 @@ def open_file(x): if default_name and schema_name(schema) is None: return _format_oneof(schema, data, default_name+"Item", replace_values, imports, **kwargs) return _format_oneof(schema, data, schema_name(schema), replace_values, imports, **kwargs) - + imports.update(extra_imports) return parameters, imports diff --git a/.generator/src/generator/openapi.py b/.generator/src/generator/openapi.py index c0a43e288..e868afc5e 100644 --- a/.generator/src/generator/openapi.py +++ b/.generator/src/generator/openapi.py @@ -64,7 +64,7 @@ def type_to_rust(schema, alternative_name=None, render_nullable=False, render_op else: type_ = "object" warnings.warn(f"Unknown type for schema: {schema} ({name or alternative_name})") - return option_wrapper(f"serde_json::Value", render_option, render_nullable) + return option_wrapper("serde_json::Value", render_option, render_nullable) if type_ == "array": if name or alternative_name: diff --git a/generate.sh b/generate.sh index 6b3ba321a..003e58ab5 100755 --- a/generate.sh +++ b/generate.sh @@ -23,7 +23,7 @@ pre_commit_wrapper () { echo "command 'pre-commit run --all-files --hook-stage=manual ${1}' success" } -cargo install --git https://github.com/skarimo/genemichaels.git --rev 82e25fc0f70acb4bd7568ff803f643996d629727 +cargo install genemichaels@0.5.11 cargo install dd-rust-license-tool --quiet rm -rf src/*