How to properly use the server stubs generated from a swagger specification?

别说谁变了你拦得住时间么 提交于 2019-12-01 04:46:01
karthik thiru

There are two steps to the solution here.

  1. Add **/*Controller.java or **/*Impl.java to .swagger-codegen-ignore file. Depending on the language used the default implementation is provided in a *Controller.java or *Impl.java file. Once the default implementation is excluded from generation, you can implement the generated interfaces in your own class. The code in your own class will not get refreshed on mvn clean.

  2. .swagger-codegen-ignore file itself is an auto-generated file hence whatever you add in step 1 gets refreshed when you do a mvn clean. To avoid this keep your version of .swagger-codegen-ignore in your resources folder and add the below plugin to your pom, to copy the file at the start of the Maven lifecycle:

    <plugin>
    	<groupId>org.apache.maven.plugins</groupId>
    	<artifactId>maven-resources-plugin</artifactId>
    	<executions>
    		<execution>
    			<id>copy-resources</id>
    			<phase>initialize</phase>
    			<goals>
    				<goal>copy-resources</goal>
    			</goals>
    			<configuration>
    				<outputDirectory>${project.build.directory}/generated/swagger</outputDirectory>
    				<resources>
    					<resource>
    						<directory>${basedir}/src/main/resources</directory>
    						<includes>
    							<include>.swagger-codegen-ignore</include>
    						</includes>
    					</resource>
    				</resources>
    			</configuration>
    		</execution>
    	</executions>
    </plugin>

I believe you will need to update the Impl classes, e.g. PetApiServiceImpl.

If you want to skip certain files (e.g. Impl classes) during code regeneration, you can add the files to .swagger-codegen-ignore.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!