OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.81k stars 6.58k forks source link

[BUG][jaxrs-cxf] Wrong imports (io.swagger.annotations) #3668

Open davidkarlsen opened 5 years ago

davidkarlsen commented 5 years ago

Bug Report Checklist

Description

Generating code with <generatorName>jaxrs-cxf-extended</generatorName> or <generatorName>jaxrs-cxf</generatorName> create invalid imports: io.swagger.annotations, as the speclevel of my api is 3.0.0 it should use io.swagger.v3.oas.annotations

openapi-generator version

4.1.0

OpenAPI declaration file content or url

Cannot disclose

Command line used for generation
 <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>${openapi-generator-version}</version>
        <executions>
          <execution>
            <id>generate</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/src/main/resources/META-INF/resources/api-v1.yaml</inputSpec>
              <strictSpec>true</strictSpec>
              <generatorName>jaxrs-cxf-extended</generatorName>
              <generateSupportingFiles>false</generateSupportingFiles>
              <generateApiTests>false</generateApiTests>
              <generateModelDocumentation>false</generateModelDocumentation>
              <withXml>true</withXml>
              <!-- https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/jaxrs-cxf.md -->
              <configOptions>
                <!-- important to add this or else codegen is malfunctioning: -->
                <sourceFolder>src/gen/java/main</sourceFolder>
                <interfaceOnly>true</interfaceOnly>
                <useJackson>true</useJackson>
                <dateLibrary>java8</dateLibrary>
                <serializableModel>true</serializableModel>
                <java8>true</java8>
                <booleanGetterPrefix>is</booleanGetterPrefix>
                <useBeanValidation>true</useBeanValidation>
              </configOptions>
              <modelPackage>com.evry.fs.arch.icpautomate.api.v1.model</modelPackage>
              <apiPackage>com.evry.fs.arch.icpautomate.api.v1.api</apiPackage>
            </configuration>
          </execution>
        </executions>
      </plugin>
Steps to reproduce

Configure plugin as described, feeding it a speclevel 3 api description

Related issues/PRs
Suggest a fix

use the updated package path in the templates

jimschubert commented 5 years ago

I've updated the title as this isn't a Maven plugin concern but a concern of the specific generator.

I think this is a feature request rather than a bug. There's no expectation that generated code matches the OpenAPI spec version, but it sounds like this is the assumption being made. I don't disagree, I just wanted to clarify. I think it would make sense that if you're generating a server implementation from a 3.x version spec document, that you're implying you'd like a 3.x implementation generated.

I don't think the parser exposes the spec version to us, so making this work automatically might require a little finesse. It might make sense to add support for the 3.x annotations and default to those, with a fallback option to the 2.0 annotations. I'm not familiar with this specific generator, so I'll defer to the technical committee for Java.

mohanaraosv commented 4 years ago

So if we update the mustache templates does it work as expected relates to https://github.com/OpenAPITools/openapi-generator/pull/5556

dkellenb commented 4 years ago

We are generating our spring controllers based on openapi definitions (3.0.0). I would also expect, that the annotations used are from io.swagger.v3.oas. Without the change, a switch to springdoc is not possible, due to missing tags and security annotations.

mohanaraosv commented 4 years ago

We are generating our spring controllers based on openapi definitions (3.0.0). I would also expect, that the annotations used are from io.swagger.v3.oas. Without the change, a switch to springdoc is not possible, due to missing tags and security annotations.

But the original query was when we are using jaxrs-cxf not spring-mvc or webflux implementation.