@@ -219,11 +219,13 @@ public CodegenModel fromModel(String name, Schema model) {
219
219
throw new RuntimeException ("oneOf size does not match the model" );
220
220
}
221
221
222
- Map <String , String > mappedNameByRef = Optional .ofNullable (model .getDiscriminator ())
222
+ // Reverse mapped references to use as baseName for oneOF, but different keys may point to the same $ref.
223
+ // Thus, we group them by the value
224
+ Map <String , List <String >> mappedNamesByRef = Optional .ofNullable (model .getDiscriminator ())
223
225
.map (Discriminator ::getMapping )
224
- .map (mapping -> mapping .entrySet ()
225
- .stream ()
226
- . collect ( Collectors .toMap (Map .Entry ::getValue , Map . Entry :: getKey ))
226
+ .map (mapping -> mapping .entrySet (). stream ()
227
+ .collect ( Collectors . groupingBy ( Map . Entry :: getValue ,
228
+ Collectors .mapping (Map .Entry ::getKey , Collectors . toList ()) ))
227
229
)
228
230
.orElse (Collections .emptyMap ());
229
231
@@ -234,8 +236,8 @@ public CodegenModel fromModel(String name, Schema model) {
234
236
if (aliasName != null ) {
235
237
oneOf .setName (toModelName (aliasName ));
236
238
}
237
- if (oneOf .getRef () != null ) {
238
- oneOf .setBaseName (mappedNameByRef .get (oneOf .getRef ()));
239
+ if (oneOf .getRef () != null && ! mappedNamesByRef . isEmpty () ) {
240
+ oneOf .setBaseName (mappedNamesByRef .get (oneOf .getRef ()). removeFirst ( ));
239
241
}
240
242
241
243
}
0 commit comments