diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java index 3c70fb2b73b2..fc9003e2ab47 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java @@ -783,6 +783,16 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List 0) { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java index d4bc7c1845ec..c919793dc5f6 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java @@ -293,6 +293,30 @@ public void testIntegerPropertyEnum() throws IOException { TestUtils.assertFileNotContains(outputPath, linearize("#[serde(rename = \"0\")]")); } + @Test + public void testFreeFormObjectQueryParam() throws IOException { + Path target = Files.createTempDirectory("test"); + target.toFile().deleteOnExit(); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("rust") + .setInputSpec("src/test/resources/3_0/rust/free-form-object-query-param.yaml") + .setSkipOverwrite(false) + .setOutputDir(target.toAbsolutePath().toString().replace("\\", "/")); + List files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + Path outputPath = Path.of(target.toString(), "/src/apis/default_api.rs"); + TestUtils.assertFileExists(outputPath); + // A free-form object query parameter maps to `serde_json::Value`, which lives + // outside of the `models` module. + TestUtils.assertFileContains(outputPath, "filter: Option"); + TestUtils.assertFileNotContains(outputPath, "models::serde_json"); + // A free-form object with additionalProperties stays a map. + TestUtils.assertFileContains(outputPath, "tags: Option>"); + TestUtils.assertFileContains(outputPath, "meta: Option>"); + // Maps keep their JSON serialization (`HashMap` does not implement `Display`). + TestUtils.assertFileContains(outputPath, "req_builder.query(&[(\"meta\", &serde_json::to_string(param_value)?)])"); + } + @Test public void testArrayWithObjectEnumValues() throws IOException { Path target = Files.createTempDirectory("test"); diff --git a/modules/openapi-generator/src/test/resources/3_0/rust/free-form-object-query-param.yaml b/modules/openapi-generator/src/test/resources/3_0/rust/free-form-object-query-param.yaml new file mode 100644 index 000000000000..789d2f46e94e --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/rust/free-form-object-query-param.yaml @@ -0,0 +1,36 @@ +openapi: 3.0.0 +info: + title: Free-form object query parameter + version: 1.0.0 +paths: + /things: + get: + operationId: listThings + parameters: + - name: filter + in: query + description: A free-form object query parameter. + schema: + type: object + - name: tags + in: query + description: A free-form object with typed additionalProperties (a map). + schema: + type: object + additionalProperties: + type: string + - name: meta + in: query + description: A free-form object with additionalProperties true (also a map). + schema: + type: object + additionalProperties: true + responses: + '200': + description: OK + content: + application/json: + schema: + type: array + items: + type: string