Skip to content
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

[RUST] Excess structs generated when using descriminators #10089

Open
denumerate opened this issue Aug 3, 2021 · 0 comments
Open

[RUST] Excess structs generated when using descriminators #10089

denumerate opened this issue Aug 3, 2021 · 0 comments

Comments

@denumerate
Copy link

Description

When generating rust code based on an openapi spec that uses discriminators and mapped objects, excess structs are created that are confusing to the user.

openapi-generator version

Version 5.1.0

OpenAPI declaration file content or url

The openapi spec below

components:
  schemas:
    Data:
      description: The event payload.
      type: object
      discriminator:
        propertyName: type_name
        mapping:
          UserAuthentication: UserAuthentication

    UserAuthentication:
      required:
        - type_name
      description: User's authentication data.
      type: object
      properties:
        type_name:
          description: The name of this type.
          type: string
          example: UserAuthentication
        certificate:
          type: string

results in both of the following files
data.rs:

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "typename")]
pub enum Data {
  rename="UserAuthentication")]
    UserAuthentication {
        #[serde(rename = "certificate", skip_serializing_if = "Option::is_none")]
        certificate: Option<String>,
    },
}

user_authentication.rs:

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct UserAuthentication {
    /// The name of this type.
    #[serde(rename = "type_name")]
    pub type_name: String,
    #[serde(rename = "certificate", skip_serializing_if = "Option::is_none")]
    pub certificate: Option<String>,
}
Command line used for generation
	docker run --rm \
		-v ".:." \
		openapitools/openapi-generator-cli:v5.1.0 generate \
		-i api/openapi.yaml \
		-g rust \
		-p packageName=dataexport-models \
		-p packageVersion='0.1.0' \
		-o crates/dataexport-models \
		--ignore-file-override=openapi-generator-ignore-rust
Steps to reproduce
  • Put the open api spec in an api directory
  • mkdir crates
  • run the above docker run command.
Related issues/PRs

This spec is based on the work in #3895.

Suggest a fix/enhancement

If either the structs were not generated or used inside the enums the resulting code would be much easier to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant