OpenAPITools / OpenAPITools/openapi-generator
[BUG] Inaccurate generation for Rust
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied testcase.yaml and Docker generation command, then compare the generated Rust model with the expected output. Start by tracing the Rust generator data passed to the custom template, especially the reported isNullable flag for each field. Done means required and optional nullable/non-nullable properties produce the expected Rust types and serde attributes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100