title: Create Swagger Model from Class
body: <p>I'm working on documenting an API made with RESTeasy + Jackson in Java using Swagger/OpenAPI (jars are version swagger-[]-1.5.18.jar). I have an endpoint that can take in one of several objects as Strings. I found a way to add models using Swagger's <code>ReaderListener</code>; however, I want it to be able to generate the <code>Model</code>s automatically since they are still in flux. I found that I can use <code>ModelConverters</code> to generate the <code>Schema</code>s from a class; however, I have been unable to find a way to easily generate <code>Model</code> <code>Property</code>s from these <code>Schema</code>s. I did find this <a href="https://github.com/swagger-api/swagger-codegen/blob/7cad47dd399f149a50e028bffc41b6a886b3f96e/modules/swagger-codegen/src/main/java/io/swagger/codegen/InlineModelResolver.java#L47" rel="nofollow noreferrer">example</a>, but it involves adding a lot of extra code. </p>
  
  <p>Are there any functions that will do so and get all of the inner <code>Schema</code>s? Or is there a better way to go from a <code>Class</code> to a <code>Model</code>?</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>@SwaggerDefinition
  public class SwaggerModelDefinitionAdder implements ReaderListener {
      @Override
      public void afterScan(Reader arg0, Swagger swagger) {
      }
  
      @Override
      public void beforeScan(Reader arg0, Swagger swagger) {  
          ModelConverters mc = new ModelConverters();
          Map&lt;String, Schema&gt; class1Schemas = mc.read(Class1.class);
          Map&lt;String, Schema&gt; class2Schemas = mc.read(Class2[].class);
  
          final Model class1Model = new ModelImpl()
                  .name("Class1")
                  .type("Class1");
          class1Model.setReference("#/definitions/Class1");
  
          final Model class2Model = new ModelImpl()
                  .name("Class2")
                  .type("Class2");
          class2Model.setReference("#/definitions/Class2");
  
          Map&lt;String, Model&gt; definitions = new HashMap&lt;&gt;();
          definitions.put("Class1", class1Model);
          definitions.put("Class2", class2Model);
          swagger.setDefinitions(definitions);
      }
  }
  </code></pre>