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

[BUG] Inaccurate generation for Rust #16283

Open
magniff opened this issue Aug 8, 2023 · 0 comments
Open

[BUG] Inaccurate generation for Rust #16283

magniff opened this issue Aug 8, 2023 · 0 comments

Comments

@magniff
Copy link

magniff commented Aug 8, 2023

Version: 7.0.0-SNAPSHOT
Command: docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -g rust -i /local/openapi/testcase.yaml -o /local/out/rust

Spec:

openapi: 3.1.0
info:
  version: '1.0'
  title: "testy test"
paths: {}
components:
  schemas:
    TestObject:
      type: object
      title: UpdateRequest
      required:
        - required_nonnull
        - required_nullable
      properties:
        optional_nonnull:
          type: string
          nullable: false
        required_nonnull:
          type: string
          nullable: false
        optional_nullable:
          type: string
          nullable: true
        required_nullable:
          type: string
          nullable: true

Reality:

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct TestObject {
    #[serde(rename = "optional_nonnull", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub optional_nonnull: Option<Option<serde_json::Value>>,
    #[serde(rename = "required_nonnull", deserialize_with = "Option::deserialize")]
    pub required_nonnull: Option<serde_json::Value>,
    #[serde(rename = "optional_nullable", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub optional_nullable: Option<Option<serde_json::Value>>,
    #[serde(rename = "required_nullable", deserialize_with = "Option::deserialize")]
    pub required_nullable: Option<serde_json::Value>,
}

Expected:

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct TestObject {
    #[serde(rename = "optional_nonnull", skip_serializing_if = "Option::is_none")]
    pub optional_nonnull: Option<String>,
    #[serde(rename = "required_nonnull")]
    pub required_nonnull: String,
    #[serde(rename = "optional_nullable", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub optional_nullable: Option<Option<String>>,
    #[serde(rename = "required_nullable")]
    pub required_nullable: Option<String>,
}

Thoughts

I dont see how I can turn reality into expected using configuration keys from here. Overall, why is reality so off?

Update

After messing around with a custom template I found out that for each field the flag isNullable=true is passed to the template, which seem to be a bug somewhere in generator.

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

No branches or pull requests

1 participant