OpenAPITools / OpenAPITools/openapi-generator
Integrating generated stubs to existing Spring MVC application - runtime error
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hi, I am using openapi-generator-maven-plugin v4.2.3 to generate stubs and having issues integrating it to my existing Spring MVC application. My issue is identical to the stackoverflow thread: https://stackoverflow.com/questions/36742362/adding-swagger-server-stubs-into-existing-spring-application. I am also getting java.lang.ClassNotFoundException: org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer during runtime in weblogic 12.2.1.3. In addition, I have commented on that same stackoverflow thread (with the alias 'Bass') but no responses. Currently, I am generating the stubs on a separate maven project for which I have tried both war/jar formats, and integrating it to my Spring-mvc application, as a dependency/classifier. Below is my pom.xml. On another note, as I use the delegate pattern to generate the interface, the interface cannot reference the implementation class if I create it in the same openapi project/submodule. But my ideal goal would be to create this implementation in a separate spring-mvc submodule/project. Raising this issue here, as stackoverflow is not showing any pointers, and I can assist others with any solution that comes up. Great tool but no progress, and about to abandon.
Here is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>xxx</version>
</parent>
<properties>
<package-name>xxx</package-name>
<generated-namespace>${package-name}.generated</generated-namespace>
<yaml-path>${project.basedir}/src/main/resources/yaml/rpa-api-1.1.2.yaml</yaml-path>
<generated-sources-path>${project.build.directory}/generated-sources/openapi</generated-sources-path>
<api-folder>api</api-folder>
<config-folder>configuration</config-folder>
<model-folder>model</model-folder>
<sources-path>src/main/java</sources-path>
</properties>
<artifactId>RPAApi</artifactId>
<packaging>jar</packaging>
<name>RPAApi</name>
<description>Code Generated APIs for RPA</description>
<build>
<resources>
<resource>
<directory>${generated-sources-path}/src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged>
<inputSpec>${yaml-path}</inputSpec>
<output>${generated-sources-path}</output>
<generatorName>spring</generatorName>
<library>spring-mvc</library>
<packageName>${package-name}</packageName>
<apiPackage>${generated-namespace}.${api-folder}</apiPackage>
<modelPackage>${generated-namespace}.${model-folder}</modelPackage>
<generateApis>true</generateApis>
<generateApiDocumentation>true</generateApiDocumentation>
<generateApiTests>true</generateApiTests>
<generateModels>true</generateModels>
<generateModelDocumentation>true</generateModelDocumentation>
<generateModelTests>true</generateModelTests>
<generateSupportingFiles>true</generateSupportingFiles>
<configOptions>
<sourceFolder>${sources-path}</sourceFolder>
<java8>true</java8> <!-- To enable 'default' interface -->
<dateLibrary>java8</dateLibrary>
<useTags>true</useTags> <!-- Relevant if the yaml has tag(s) -->
<configPackage>${generated-namespace}.${config-folder}</configPackage>
<interfaceOnly>false</interfaceOnly>
<delegatePattern>true</delegatePattern>
<performBeanValidation>true</performBeanValidation>
<useBeanValidation>true</useBeanValidation>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<!-- Add source folder of generated java source code to the maven source directory for compilation -->
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
====
More properties:
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.framework.version>5.1.1.RELEASE</spring.framework.version>
<springfox-version>2.9.2</springfox-version>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied pom.xml and the runtime ClassNotFoundException for AbstractAnnotationConfigDispatcherServletInitializer. Review how the generated spring-mvc stubs and their dependencies are integrated into the existing WebLogic application, including the separate module and delegate pattern. Done means the stubs run without the runtime error and the implementation can be placed in the intended separate Spring MVC project.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100