-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG][RUST] oneOf with multiple arrays produces invalid rust code #18527
Comments
ideally what's the correct/expected code look like? |
There is probably not a really nice way as there is just not much information. Maybe one could enumerate the enum fields: #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Option1OrOption2Options {
Array1(Vec<String>),
Array2(Vec<i32>),
} Those are not helpful variable names but at least it could be compiled. Maybe the generators for the other languages in this project have a nicer way to solve this? |
what about the following instead?
|
Theoretically, the following is also a valid OpenAPI spec: 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: string With your proposition, this would result in a name clash again. However, depending on whether you want to support all edge cases of OpenAPI, that might be okay because the semantics of the spec above are not clear (why even have a |
I found something similar to this today.
This should also generate distinct types. |
Any further plans on tackling this?
Your suggestion is the imo the most idiomatic solution. If someone could point me in the direction of where the |
Bug Report Checklist
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 aoneOf
with multiple arrays inside.The OpenAPI spec below produces the following enum:
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
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
):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
oneOf
generation for client #17915 solving [BUG][Rust] oneOf with array produces invalid code #17896.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.
The text was updated successfully, but these errors were encountered: