-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Description
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: stringresults 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-rustSteps to reproduce
- Put the open api spec in an api directory
mkdir crates- run the above
docker runcommand.
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels