-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
If there is no title
, the rust generator tries to derive a meaningful name from the type (see #17896). However, this fails in some cases, for example if there is a oneOf
with multiple arrays inside.
The OpenAPI spec below produces the following enum:
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Option1OrOption2Options {
Array(Vec<String>),
Array(Vec<i32>),
}
This cannot be compiled, the error message is error[E0428]: the name 'Array' is defined multiple times
. I would expect that all code generated from a valid OpenAPI spec generates compilable rust code.
openapi-generator version
I tested with version 06ed7c8 (the current main).
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: oneOf with arrays
description: Ensure different names for kinds in enum when using oneOf with arrays.
version: 1.0.0
paths: {}
components:
schemas:
Option1OrOption2:
type: object
properties:
Options:
oneOf:
- type: array
items:
type: string
- type: array
items:
type: integer
Steps to reproduce
I'll provide the steps to create a failing test using the valid OpenAPI spec above.
-
Add the snippet above to the test resources (e.g.
modules/openapi-generator/src/test/resources/3_0/rust/oneof-with-arrays.yaml
). -
Create a config for the test (e.g.
bin/configs/rust-reqwest-oneOf-with-arrays.yaml
):generatorName: rust outputDir: samples/client/others/rust/reqwest/oneOf-with-arrays library: reqwest inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/oneof-with-arrays.yaml templateDir: modules/openapi-generator/src/main/resources/rust additionalProperties: supportAsync: false packageName: oneof-with-arrays-reqwest
-
Generate the rust samples with
./bin/generate-samples.sh ./bin/configs/rust-*
. -
Execute the tests with
mvn integration-test -f samples/client/others/rust/pom.xml
.
Related issues/PRs
- Not long ago, the rust type was directly used as the enum kind, see [BUG][Rust] oneOf with array produces invalid code #17896.
- This was changed in fix(rust):
oneOf
generation for client #17915 solving [BUG][Rust] oneOf with array produces invalid code #17896. - [BUG] Code generation is broken for
oneOf
types (Rust Server) #17210 is a follow up issue but it's different from the issue I am opening here.
Suggest a fix
I'm new to rust and to openapi-generator, so I am no help here, sorry.