File tree Expand file tree Collapse file tree
modules/openapi-generator/src/main/java/org/openapitools/codegen Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1009,6 +1009,14 @@ public void postProcessParameter(CodegenParameter parameter) {
10091009 @ Override
10101010 @ SuppressWarnings ("unused" )
10111011 public void preprocessOpenAPI (OpenAPI openAPI ) {
1012+ if (openAPI .getComponents () != null ) {
1013+ // Remove duplicate oneOf
1014+ Map <String , Schema > schemas = new HashMap <>(openAPI .getComponents ().getSchemas ());
1015+ for (var schema : schemas .values ()) {
1016+ ModelUtils .deduplicateOneOfSchema (schema );
1017+ }
1018+ }
1019+
10121020 if (useOneOfInterfaces && openAPI .getComponents () != null ) {
10131021 // we process the openapi schema here to find oneOf schemas and create interface models for them
10141022 Map <String , Schema > schemas = new HashMap <>(openAPI .getComponents ().getSchemas ());
Original file line number Diff line number Diff line change @@ -2243,6 +2243,19 @@ public static Schema simplyOneOfAnyOfWithOnlyOneNonNullSubSchema(OpenAPI openAPI
22432243 return schema ;
22442244 }
22452245
2246+ /**
2247+ * Removes duplicate `oneOf` from a given schema
2248+ *
2249+ * @param schema Schema
2250+ */
2251+ public static void deduplicateOneOfSchema (Schema <?> schema ) {
2252+ if (schema .getOneOf () == null ) {
2253+ return ;
2254+ }
2255+ Set <Schema > deduplicated = new LinkedHashSet <>(schema .getOneOf ());
2256+ schema .setOneOf (new ArrayList <>(deduplicated ));
2257+ }
2258+
22462259 /**
22472260 * Check if the schema is of type 'null' or schema itself is pointing to null
22482261 * <p>
You can’t perform that action at this time.
0 commit comments