Skip to content

Commit cc880bd

Browse files
committed
fix: Fixed regression with oneOf+discriminator
1 parent e0977a3 commit cc880bd

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

  • modules/openapi-generator/src/main/java/org/openapitools/codegen/utils
  • samples/client/others/rust
    • hyper/oneOf-reuseRef/src/models
    • reqwest/oneOf-reuseRef/src/models

modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,14 +2244,18 @@ public static Schema simplyOneOfAnyOfWithOnlyOneNonNullSubSchema(OpenAPI openAPI
22442244
}
22452245

22462246
/**
2247-
* Removes duplicate `oneOf` from a given schema
2247+
* Removes duplicate `oneOf` from a given schema if it does not also have a discriminator.
22482248
*
22492249
* @param schema Schema
22502250
*/
22512251
public static void deduplicateOneOfSchema(Schema<?> schema) {
22522252
if (schema.getOneOf() == null) {
22532253
return;
22542254
}
2255+
if (schema.getDiscriminator() != null) {
2256+
return; // Duplicate oneOf are allowed if there is a discriminator that can be used to separate them.
2257+
}
2258+
22552259
Set<Schema> deduplicated = new LinkedHashSet<>(schema.getOneOf());
22562260
schema.setOneOf(new ArrayList<>(deduplicated));
22572261
}

samples/client/others/rust/hyper/oneOf-reuseRef/src/models/fruit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use serde::{Deserialize, Serialize};
1616
pub enum Fruit {
1717
#[serde(rename="green_apple")]
1818
GreenApple(Box<models::Apple>),
19+
#[serde(rename="red_apple")]
20+
RedApple(Box<models::Apple>),
1921
#[serde(rename="banana")]
2022
Banana(Box<models::Banana>),
2123
}

samples/client/others/rust/reqwest/oneOf-reuseRef/src/models/fruit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use serde::{Deserialize, Serialize};
1616
pub enum Fruit {
1717
#[serde(rename="green_apple")]
1818
GreenApple(Box<models::Apple>),
19+
#[serde(rename="red_apple")]
20+
RedApple(Box<models::Apple>),
1921
#[serde(rename="banana")]
2022
Banana(Box<models::Banana>),
2123
}

0 commit comments

Comments
 (0)