title: Is there a way to automatically generate the java test code using swagger codegen?
body: <p>I've been playing with swagger codegen for a springboot project. I am now able to automatically generate the client code in java, ignore the generation of the data models (importing my own in the swagger-codegen-maven-plugin via importMapping).
  Furthermore, I am also able to:</p>
  
  <ul>
  <li>specify tags directly in the springboot code to help organize the openapi contract, </li>
  <li>use the @Operation annotation to specify method names,</li>
  <li>use the @ApiResponses annotation to detail the expected response codes and descriptions,etc. </li>
  </ul>
  
  <p>Example below:</p>
  
  <pre class="lang-java prettyprint-override"><code>@RestController
  @RequestMapping(value="/api/external/")
  @Tag(name = "addResources", description = "The Add Resources API")
  public class ControllerAddResources {
  
      private final ServiceInterAddResources externalSources;
  
      public ControllerAddResources(
              ServiceInterAddResources externalSources){
          this.externalSources = externalSources;
      }
  
      @Operation(operationId="importDataV3", summary = "Import Data V3", description = "Import a Data V3 file from source", tags = { "addResources" })
      @PostMapping(path="/{source}/datav3", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
      public @ResponseBody String importDataV3(
              @PathVariable String source,
              MultipartFile file) throws  ExceptionInvalidDataV3, IOException{
  
  
          return externalSources.importDataV3(source, file);
      }
  </code></pre>
  
  <p>All of this is built into the openapi contract which is then used by codegen to generate the client library (in this case, I'm using resttemplate), such as the one below:</p>
  
  <pre><code>@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2020-03-05T12:15:11.537Z[Europe/Lisbon]")@Component("com.xxx.connector.api.AddResourcesApi")
  public class AddResourcesApi {
      private ApiClient apiClient;
  
      public AddResourcesApi() {
          this(new ApiClient());
      }
  
      @Autowired
      public AddResourcesApi(ApiClient apiClient) {
          this.apiClient = apiClient;
      }
  
      public ApiClient getApiClient() {
          return apiClient;
      }
  
      public void setApiClient(ApiClient apiClient) {
          this.apiClient = apiClient;
      }
  
      /**
       * Import Data V3
       * Import a Data V3 file from source
       * &lt;p&gt;&lt;b&gt;412&lt;/b&gt; - default response
       * &lt;p&gt;&lt;b&gt;409&lt;/b&gt; - default response
       * &lt;p&gt;&lt;b&gt;200&lt;/b&gt; - default response
       * @param source The source parameter
       * @param file The file parameter
       * @return String
       * @throws RestClientException if an error occurs while attempting to invoke the API
       */
      public String importDataV3(String source, File file) throws RestClientException {
          Object postBody = null;
          // verify the required parameter 'source' is set
          if (source == null) {
              throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'source' when calling importDataV3");
          }
          // create path and map variables
          final Map&lt;String, Object&gt; uriVariables = new HashMap&lt;String, Object&gt;();
          uriVariables.put("source", source);
          String path = UriComponentsBuilder.fromPath("/api/external/{source}/datav3").buildAndExpand(uriVariables).toUriString();
  
          final MultiValueMap&lt;String, String&gt; queryParams = new LinkedMultiValueMap&lt;String, String&gt;();
          final HttpHeaders headerParams = new HttpHeaders();
          final MultiValueMap&lt;String, Object&gt; formParams = new LinkedMultiValueMap&lt;String, Object&gt;();
          if (file != null)
              formParams.add("file", new FileSystemResource(file));
  
          final String[] accepts = { 
              "*/*", "application/json"
           };
          final List&lt;MediaType&gt; accept = apiClient.selectHeaderAccept(accepts);
          final String[] contentTypes = { 
              "multipart/form-data"
           };
          final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
  
          String[] authNames = new String[] {  };
  
          ParameterizedTypeReference&lt;String&gt; returnType = new ParameterizedTypeReference&lt;String&gt;() {};
          return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
      }
  </code></pre>
  
  <p>In the generated sources, codegen also includes scaffolds for junit tests, like the one below:</p>
  
  <pre class="lang-java prettyprint-override"><code>    /**
       * API tests for AddResourcesApi
       */
      @Ignore
      public class AddResourcesApiTest {
  
          private final AddResourcesApi api = new AddResourcesApi();
  
          /**
           * Import Data V2
           *
           * Import an Data V2 file from source
           *
           * @throws ApiException
           *          if the Api call fails
           */
          @Test
          public void imporDataV2Test() {
              String source = null;
              File file = null;
              String response = api.importDataV2(source, file);
  
              // TODO: test validations
          }
          /**
           * Import Data V3
           *
           * Import an Data V3 file from source [%source%]
           *
           * @throws ApiException
           *          if the Api call fails
           */
          @Test
          public void importDataV3Test() {
              String source = null;
              File file = null;
              String response = api.importDataV3(source, file);
  
              // TODO: test validations
          }
      }
  </code></pre>
  
  <p>However, the validation code is empty, as expected. Since the client is being continuously generated in a CI/CD environment and being deployed to a dependency management system that I'm running internally (Artifactory), this defeats the purpose of manually writing the tests each time I execute codegen.</p>
  
  <p>Is there a way of specifying the validation code (or validation requisites) directly using java annotations (or a templating mechanism) at the springboot project level? This would allow for fully automated client library generation with testing included.</p>