Skip to content

[BUG][RUST] oneOf with multiple arrays produces invalid rust code #18527

@felixauringer

Description

@felixauringer

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
Suggest a fix

I'm new to rust and to openapi-generator, so I am no help here, sorry.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions