@@ -967,22 +967,28 @@ public ModelsMap postProcessModels(ModelsMap objs) {
967967 public Map <String , ModelsMap > postProcessAllModels (Map <String , ModelsMap > objs ) {
968968 objs = super .postProcessAllModels (objs );
969969 if (getSerializationLibrary () == SERIALIZATION_LIBRARY_TYPE .kotlinx_serialization ) {
970+ // The loop removes unneeded variables so commas are handled correctly in the related templates
970971 for (Map .Entry <String , ModelsMap > modelsMap : objs .entrySet ()) {
971972 for (ModelMap mo : modelsMap .getValue ().getModels ()) {
972973 CodegenModel cm = mo .getModel ();
973974 CodegenDiscriminator discriminator = cm .getDiscriminator ();
974975 if (discriminator == null ) {
975976 continue ;
976977 }
978+ // Remove discriminator property from the base class, it is not needed in the generated code
977979 getAllVarProperties (cm ).forEach (list -> list .removeIf (var -> var .name == discriminator .getPropertyName ()));
978980
979981 for (CodegenDiscriminator .MappedModel mappedModel : discriminator .getMappedModels ()) {
982+ // Add the mapping name to additionalProperties.disciminatorValue
983+ // The mapping name is used to define SerializedName, which in result makes derived classes
984+ // found by kotlinx-serialization during deserialization
980985 CodegenProperty additionalProperties = mappedModel .getModel ().getAdditionalProperties ();
981986 if (additionalProperties == null ) {
982987 additionalProperties = new CodegenProperty ();
983988 mappedModel .getModel ().setAdditionalProperties (additionalProperties );
984989 }
985990 additionalProperties .discriminatorValue = mappedModel .getMappingName ();
991+ // Remove the discriminator property from the derived class, it is not needed in the generated code
986992 getAllVarProperties (mappedModel .getModel ()).forEach (list -> list .removeIf (prop -> prop .name == discriminator .getPropertyName ()));
987993 }
988994
0 commit comments