title: Does the openapi springboot server generator have a broken threading model?
body: <p>So we're trying to use the OpenAPI generator and so far we've had mixed results.</p>
  
  <p>Steps to reproduce:</p>
  
  <ol>
  <li>Download openapi generator jar: <code>wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator/4.0.3/openapi-generator-4.0.3.jar</code></li>
  <li>Generate springboot server for the petstore example: <code>java -jar openapi-generator-cli-4.0.3.jar generate -g spring   -i https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml</code></li>
  </ol>
  
  <p>You'll end up with controller classes that look like this:</p>
  
  <pre><code>package org.openapitools.api;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.context.request.NativeWebRequest;
  import java.util.Optional;
  @javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2019-08-06T15:08:49.070+01:00[Europe/London]")
  
  @Controller
  @RequestMapping("${openapi.swaggerPetstore.base-path:/v1}")
  public class PetsApiController implements PetsApi {
  
      private final NativeWebRequest request;
  
      @org.springframework.beans.factory.annotation.Autowired
      public PetsApiController(NativeWebRequest request) {
          this.request = request;
      }
  
      @Override
      public Optional&lt;NativeWebRequest&gt; getRequest() {
          return Optional.ofNullable(request);
      }
  
  }
  </code></pre>
  
  <pre><code>/**
   * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (4.0.3).
   * https://openapi-generator.tech
   * Do not edit the class manually.
   */
  package org.openapitools.api;
  
  import org.openapitools.model.Error;
  import org.openapitools.model.Pet;
  import io.swagger.annotations.*;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.MediaType;
  import org.springframework.http.ResponseEntity;
  import org.springframework.validation.annotation.Validated;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestHeader;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.RequestPart;
  import org.springframework.web.context.request.NativeWebRequest;
  import org.springframework.web.multipart.MultipartFile;
  
  import javax.validation.Valid;
  import javax.validation.constraints.*;
  import java.util.List;
  import java.util.Map;
  import java.util.Optional;
  @javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2019-08-06T15:08:49.070+01:00[Europe/London]")
  
  @Validated
  @Api(value = "pets", description = "the pets API")
  public interface PetsApi {
  
      default Optional&lt;NativeWebRequest&gt; getRequest() {
          return Optional.empty();
      }
  
      @ApiOperation(value = "Create a pet", nickname = "createPets", notes = "", tags={ "pets", })
      @ApiResponses(value = { 
          @ApiResponse(code = 201, message = "Null response"),
          @ApiResponse(code = 200, message = "unexpected error", response = Error.class) })
      @RequestMapping(value = "/pets",
          produces = { "application/json" }, 
          method = RequestMethod.POST)
      default ResponseEntity&lt;Void&gt; createPets() {
          return new ResponseEntity&lt;&gt;(HttpStatus.NOT_IMPLEMENTED);
  
      }
  
  
      @ApiOperation(value = "List all pets", nickname = "listPets", notes = "", response = Pet.class, responseContainer = "List", tags={ "pets", })
      @ApiResponses(value = { 
          @ApiResponse(code = 200, message = "A paged array of pets", response = Pet.class, responseContainer = "List"),
          @ApiResponse(code = 200, message = "unexpected error", response = Error.class) })
      @RequestMapping(value = "/pets",
          produces = { "application/json" }, 
          method = RequestMethod.GET)
      default ResponseEntity&lt;List&lt;Pet&gt;&gt; listPets(@ApiParam(value = "How many items to return at one time (max 100)") @Valid @RequestParam(value = "limit", required = false) Integer limit) {
          getRequest().ifPresent(request -&gt; {
              for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
                  if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
                      ApiUtil.setExampleResponse(request, "application/json", "null");
                      break;
                  }
              }
          });
          return new ResponseEntity&lt;&gt;(HttpStatus.NOT_IMPLEMENTED);
  
      }
  
  
      @ApiOperation(value = "Info for a specific pet", nickname = "showPetById", notes = "", response = Pet.class, tags={ "pets", })
      @ApiResponses(value = { 
          @ApiResponse(code = 200, message = "Expected response to a valid request", response = Pet.class),
          @ApiResponse(code = 200, message = "unexpected error", response = Error.class) })
      @RequestMapping(value = "/pets/{petId}",
          produces = { "application/json" }, 
          method = RequestMethod.GET)
      default ResponseEntity&lt;Pet&gt; showPetById(@ApiParam(value = "The id of the pet to retrieve",required=true) @PathVariable("petId") String petId) {
          getRequest().ifPresent(request -&gt; {
              for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
                  if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
                      ApiUtil.setExampleResponse(request, "application/json", "null");
                      break;
                  }
              }
          });
          return new ResponseEntity&lt;&gt;(HttpStatus.NOT_IMPLEMENTED);
  
      }
  
  }
  </code></pre>
  
  <p>So my question is this: everything I can find implies that Spring Controllers are multi-threaded and may handle multiple requests at once. Is the code generator broken? Am I interpreting this completely wrong?</p>
  
  <p>The constructor for <code>PetsApiController</code> gives me pause. If it's being autowired once per request then that implies that there's only one per request?</p>
  
  <pre><code>    @org.springframework.beans.factory.annotation.Autowired
      public PetsApiController(NativeWebRequest request) {
          this.request = request;
      }
  </code></pre>