title: Springfox swagger didn't show alternative type mapping properly on some model
body: <p>I have a bunch of entity that returned in controllers in many <code>forms</code>, <code>list</code>, <code>map</code>, <code>multimap</code>, etc... </p>
  
  <p>I have a solution where you define type mappings <code>(entity -&gt; dto, dto -&gt; entity)</code>where the entity is an actual <code>JPA</code> entity, and a <code>DTO</code> is representing the <code>JSON</code> form of the entity with a bunch of <code>swagger</code> annotation and stuff.</p>
  
  <p>I create 2 <code>jackson</code> module from these mappings which is basically a lot of <code>StdDelegatingDeserializer</code> and <code>StdDelegatingSerializer</code>. This modules then added to <code>jackson</code>, and they do their job just fine.</p>
  
  <p>When a controller returns an entity type, the actual <code>JSON</code> is created from the DTO, and the same when you want to receive an entity in the controller. </p>
  
  <p>In this application also have a swagger with <code>swagger</code> UI set up, and in the <code>swagger</code> configuration, I add all this mapping as alternative type mapping. Most of the models in the swagger docs are good, but in some cases the docs show the structure of the entity instead of the <code>DTO</code>. </p>
  
  <p>I store the mapping in a list of the following class</p>
  
  <pre><code>@Data
  @NoArgsConstructor
  @AllArgsConstructor
  public class ModelMapperKey&lt;E, D&gt; {
      @NonNull
      private Class&lt;E&gt; entityType;
  
      @NonNull
      private Class&lt;D&gt; dtoType;
  }
  
  </code></pre>
  
  <p>From this list, I create an <code>AlternateTypeRuleConvention</code> bean and <code>swagger</code> handles it automatically</p>
  
  <pre><code>    @Bean
      public AlternateTypeRuleConvention alternateTypeRuleConvention() {
          return new AlternateTypeRuleConvention() {
  
              @Override
              public int getOrder() {
                  return Ordered.HIGHEST_PRECEDENCE;
              }
  
              @Override
              public List&lt;AlternateTypeRule&gt; rules() {
                  return modelMapperService.getMapperKeys()
                          .stream()
                          .map(key -&gt; newRule(resolver.resolve(key.getEntityType()), resolver.resolve(key.getDtoType())))
                          .collect(Collectors.toList());
              }
          };
      }
  </code></pre>
  
  <p>As I mentioned it's work just fine and show the actual <code>DTO</code> in the <code>swagger</code> docs, expect some case don't. Currently, 11 times out of 60 the entity being shown instead of the <code>DTO</code> model. I checked many times, the alternative type rules are created for those <code>DTO</code>-s and added to context. When you execute the request in <code>swagger UI</code> I get the correct <code>json</code> response. </p>
  
  <p>I tried to play with rule precedence</p>
  
  <pre><code>newRule(resolver.resolve(key.getEntityType()), resolver.resolve(key.getDtoType()), Ordered.HIGHEST_PRECEDENCE)
  </code></pre>
  
  <p>Also tried <code>0</code> and <code>Ordered.LOWEST_PRECEDENCE</code> but non of them work. I have no idea what can cause this phenomenon.</p>