openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [Spring] Generated test classes are marked as sources instead of test

Open mariusmanastireanu opened this issue 3 years ago • 9 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] [N/A] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating interfaces (invoker) for spring generator the generated test resources are marked as Sources instead of Test Sources. This will break the compilation if test resources are marked as test scope. Also see my response on this question: https://stackoverflow.com/questions/73450027/java-maven-openapi-3-0-codegen-is-generating-unwanted-test-file-how-to-remove

Workaround: run with <interfaceOnly>true</interfaceOnly> (avoid test generation).

openapi-generator version

6.2.0, 6.0.1

OpenAPI declaration file content or url

N/A - anything is sufficient

openapi: 3.0.3
info:
  title: test
  version: "1.0"
servers:
  - url: http://localhost:8080/
    description: Local
tags:
  - name: Target
    description: Targets related REST endpoints.
paths:
  /target:
    get:
      tags:
        - Target
      summary: Retrieves all targets
      description: Returns all targets
      operationId: getTargets
      responses:
        '200':
          description: successful operation
                    <plugin>
				<groupId>org.openapitools</groupId>
				<artifactId>openapi-generator-maven-plugin</artifactId>
				<version>${openapi-generator.version}</version>
				<executions>
					<execution>
						<goals>
							<goal>generate</goal>
						</goals>
						<id>generate-files-from-openapi</id>
						<configuration>
							<inputSpec>${project.basedir}/src/main/resources/static/api.yaml</inputSpec>
							<generatorName>spring</generatorName>
							<library>spring-boot</library>
							<configOptions>
<!--								<interfaceOnly>true</interfaceOnly>-->
							</configOptions>
						</configuration>
					</execution>
				</executions>
			</plugin>
Generation Details

spring

Steps to reproduce

Generate sources and check project strcture.

Related issues/PRs
Suggest a fix

mariusmanastireanu avatar Oct 12 '22 15:10 mariusmanastireanu

Same issue. The workaround is not great because it does not generate the clients which are nice/required.

nikimicallef avatar Nov 01 '22 15:11 nikimicallef

I am wondering:

  • testOutput seems correct and this file should be generated in generatedtest-sources instead of generated-source
  • As it's a test, why generateApiTests has no effect on this file generation?
  • Where is this F**** config that adds src/test/java in the sources while default maven config consider this file as a test-source

sebastianblesgen avatar Mar 08 '23 14:03 sebastianblesgen

Still in 6.4.0

sebastianblesgen avatar Mar 20 '23 02:03 sebastianblesgen

@sebastianblesgen did you find any workarounds for this?

navaneeth-spotnana avatar Mar 30 '23 09:03 navaneeth-spotnana

@sebastianblesgen did you find any workarounds for this?

The only thing I can do is to use the suggested workaround using interfaceOnly 🤷🏻‍♂️

sebastianblesgen avatar Mar 30 '23 09:03 sebastianblesgen

I just now got rid of the file by adding it to the ignore list:

<ignoreFileOverride>${project.basedir}/.openapi-generator-ignore</ignoreFileOverride>

.openapi-generator-ignore content:

**/OpenApiGeneratorApplicationTests.java

navaneeth-spotnana avatar Mar 30 '23 09:03 navaneeth-spotnana

Still present in v7.3.0 - but the workaround by @navaneeth-spotnana still works!

tofi86 avatar Feb 20 '24 10:02 tofi86

Still present in v7.3.0 - but the workaround by @navaneeth-spotnana still works!

Same in v7.5.0, testOutput configuration seems to be ignored.

martinboue avatar Apr 29 '24 17:04 martinboue

Still broke

patwakeem avatar Jun 21 '24 18:06 patwakeem