title: How can I change the type of a property with NJsonSchema
body: <p>I have a series of generic response objects that are being returned with a property that is an abstract class.  The NSwag and NJsonSchema generate the schema with an abstract class, which creates problems.  The concrete class is easily determined via reflection, however, there does not seem to be a clean way to get NJsonSchema to replace the abstract type with the appropriate concrete one.  What is the correct way to do this?</p>
  
  <pre><code>public abstract class AppRequest&lt;TData&gt; {
      public Guid RequestId { get; set; }
  }
  
  public class AppResponse&lt;TData&gt; {
      public TData Data { get; set; }
      public AppRequest&lt;TData&gt; OriginalRequest { get; set; }
  }
  
  public class User {
  ....
  }
  
  public class UserRequest: AppRequest&lt;User&gt; {
      public Guid UserId { get; set; }
  }
  </code></pre>
  
  <p>NSwag generates response object as <code>AppResponseOfUser</code> which is fine, however, it says that the <code>OriginalRequest</code> property is AppRequestOfUser and that it is abstract.  I want to create a SchemaProcessor that remaps this AppRequestOfUser to UserRequest.  Something like this:</p>
  
  <pre><code>public class MySchemaProcessor
      : ISchemaProcessor
  {
      public async Task ProcessAsync(SchemaProcessorContext context)
      {
          if (context.Type.IsGenericOf(typeof(AppResponse&lt;&gt;)))
          {
              var modelType = context.Type.GenericTypeArguments[0];
              var abstractRequestType = typeof(AppRequest&lt;&gt;).MakeGenericType(modelType);
  
              var actualRequestType = modelType.Assembly.GetTypes()
                  .Single(t =&gt; t.IsClass &amp;&amp; t.BaseType == abstractRequestType);
  
              var requestSchema = await JsonSchema4.FromTypeAsync(actualRequestType);
  
              var originalRequestProperty = context.Schema.Properties["originalRequest"];
              originalRequestProperty.IsReadOnly = true;
              originalRequestProperty.IsAbstract = false;
  
              // CHANGE PROPERTY TYPE HERE!!!
          }
      }
  }
  </code></pre>
  
  <p>Unfortunately, NJsonSchema doesn't seem to be very flexible and there is no clear way on how to do this.  I do not want to use a discriminator property.  I want to remap to the appropriate concrete type.</p>