title: Using Java annotations, is there a way to specify Swagger/OpenAPI schemas inside other schemas?
body: <p>I'm trying to use Swagger UI to create and deploy my documentation along with the API I've written using Spring Boot. I know Swagger provides some annotations to assist with writing documentation in the actual controller classes, but I'm having trouble trying to get them to do what I need.</p>
  <p>My problem is that I have a generic DTO class that gets returned by every call to my API. This DTO has a <code>contents</code> field for generic objects. If I were using the objects directly, I know I could use something like</p>
  <pre><code>@ApiResponse(responseCode = &quot;200&quot;, description = &quot;Customer found&quot;,
      content = @Content(
          schema = @Schema(implementation = Customer.class)))
  </code></pre>
  <p>in order to give a specification of what the JSON representation of the object should look like. However, because I'm wrapping everything in a specific <code>ResponseDTO</code> class, I need a way to specify what the <code>contents</code> field should look like, and I'm not sure which annotations I can use to accomplish this. I feel like there should definitely be something like</p>
  <pre><code>@ApiResponse(responseCode = &quot;200&quot;, description = &quot;Customer found&quot;,
      content = @Content(
          schema = @Schema(implementation = DTO.class, 
                           fields = { &quot;contents&quot; = @Schema(implementation = Customer.class)})))
  </code></pre>
  <p>or something similar. I haven't been able to find an explanation of how to really accomplish this. My intuition suggests there should be a way to put a schema inside a schema, but maybe there's another solution I haven't considered. Any help or direction in which to look would be hugely appreciated. Thanks in advance.</p>