Bug Report Checklist
Description
It's nice that basic support of oneOf for rust has landed as part of #13970, but there are some issues.
It generates broken code if one of elements is "array", because it uses type-name as variant name for enum without normalization.
It leads to structures like this:
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OneOfWithArray {
SomeObject(Box<SomeObject>),
Vec<crate::models::SomeObject>(Box<Vec<crate::models::SomeObject>>), // invalid rust code
}
openapi-generator version
latest master:
openapi-generator-cli 7.4.0-SNAPSHOT
commit : 76d743b
OpenAPI declaration file content or url
Can be reproduced with existing modules/openapi-generator/src/test/resources/3_0/oneOfArrayMapImport.yaml
Or another MRE:
{
"openapi": "3.0.3",
"info": {
"title": "Omitted",
"description": "Omitted",
"license": {
"name": ""
},
"version": "0.1.0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Omitted"
}
],
"paths": {},
"components": {
"schemas": {
"OneOfWithArray": {
"type": "object",
"oneOf": [
{
"$ref": "#/components/schemas/SomeObject"
},
{
"type": "array",
"items": {
"$ref": "#/components/schemas/SomeObject"
}
}
]
},
"SomeObject": {
"type": "object",
"properties": {
"a": {
"type": "integer"
}
}
}
},
"responses": {}
}
}
Generation Details
Just
openapi-generator generate -i test-spec.json -g rust --package-name test-one-of --additional-properties=supportMiddleware=true -o ./test
Steps to reproduce
Just try to generate rust client for provided spec.
Related issues/PRs
#13970 - the behavior was introduced there, but it's initial version of oneOf support.
#17869 - related issue with mention of wrong String import
Suggest a fix
Instead of using type-name as enum variant name, for such cases it could be normalization. I.e replace special chars and paths, for example VecSomeObject instead of Vec<crate::models::SomeObject>(..) or even just SomeObjects. Not sure about complexity though.
And not really related to this case, but if there is a descriminator - its values can be used instead of type names
Bug Report Checklist
Description
It's nice that basic support of
oneOffor rust has landed as part of #13970, but there are some issues.It generates broken code if one of elements is "array", because it uses type-name as variant name for enum without normalization.
It leads to structures like this:
openapi-generator version
latest master:
OpenAPI declaration file content or url
Can be reproduced with existing
modules/openapi-generator/src/test/resources/3_0/oneOfArrayMapImport.yamlOr another MRE:
{ "openapi": "3.0.3", "info": { "title": "Omitted", "description": "Omitted", "license": { "name": "" }, "version": "0.1.0" }, "servers": [ { "url": "http://localhost:8080", "description": "Omitted" } ], "paths": {}, "components": { "schemas": { "OneOfWithArray": { "type": "object", "oneOf": [ { "$ref": "#/components/schemas/SomeObject" }, { "type": "array", "items": { "$ref": "#/components/schemas/SomeObject" } } ] }, "SomeObject": { "type": "object", "properties": { "a": { "type": "integer" } } } }, "responses": {} } }Generation Details
Just
openapi-generator generate -i test-spec.json -g rust --package-name test-one-of --additional-properties=supportMiddleware=true -o ./testSteps to reproduce
Just try to generate rust client for provided spec.
Related issues/PRs
#13970 - the behavior was introduced there, but it's initial version of oneOf support.
#17869 - related issue with mention of wrong
StringimportSuggest a fix
Instead of using type-name as enum variant name, for such cases it could be normalization. I.e replace special chars and paths, for example
VecSomeObjectinstead ofVec<crate::models::SomeObject>(..)or even justSomeObjects. Not sure about complexity though.And not really related to this case, but if there is a descriminator - its values can be used instead of type names