如何在类控制器中从api swagger实现spring注释? [英] How to implement spring annotations from an api swagger in a class controller?

查看:380
本文介绍了如何在类控制器中从api swagger实现spring注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个RESTfull Web服务,该服务将swagger与swagger-codegen-maven-plugin一起使用来创建模型,控件和api类(这是带有Spring注释的接口).

I am develop a RESTfull web service which uses swagger with swagger-codegen-maven-pluginto create the models, controles and the api class (which is an interface with spring annotatios).

接下来是pom.xml中的插件:

The plugin in the pom.xml is the next:

     <plugin>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.2.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>C:\API.yaml</inputSpec>
                        <language>spring</language>
                        <configOptions>
                            <dateLibrary>java8</dateLibrary>
                            <useTags>true</useTags>
                            <sourceFolder>/</sourceFolder>
                        </configOptions>
                    </configuration>
                </execution>
            </executions>           
    </plugin>

当我想创建一个新的控制器类(与Swagger创建的控制器类不同)时,它将实现api类和方法的签名,但是,该类未在方法的参数中写入注释(例如:@ RequestParam,@ RequestHeader等)

When I want to create a new controller class (it is different from the one created by Swagger) this implements the api class and the signing of the methods, however, this class does not write annotations in the parameters of the methods (Example: @RequestParam, @RequestHeader, etc.)

Api接口;

public interface Api{

    @RequestMapping(value = "/class-services",
        method = RequestMethod.GET)
    default ResponseEntity<XXXType> getClass(@ApiParam(value = "id" ,required=true) @RequestHeader(value="Id", required=true) String id) {
        // do some magic!
        return new ResponseEntity<XXXType>(HttpStatus.OK);
    }

}

控制器类:

@Controller
public class controller implements Api {

    public ResponseEntity<XXXType> getClass(String id) {
        // do some magic!
       return new ResponseEntity<XXXType>(HttpStatus.OK);
    }

}

swagger-ui中的此结果定义了每个参数,例如"query". Swagger不能区分标头参数类型.

This result in swagger-ui defines every parameters like 'query'. Swagger does not distinguish the header parameter type.

当我实现Api类时,我想知道是否存在某种扩展接口旁注解的方法(我想知道复制并粘贴sign方法).

I want to know if exist some way to extend the annotatios next to interface when I implement the Api class, (I want to know copy and paste the sign methods).

注意:我将Java 8用于LocalTime和LocalDate类.

Note: I am using Java 8 for the LocalTime and LocalDate class.

关于.

推荐答案

swagger-codegen-maven-plugin的<configOptions>内的<delegatePattern>true</delegatePattern>参数帮助我解决了类似的问题.

The <delegatePattern>true</delegatePattern> parameter inside the <configOptions> of swagger-codegen-maven-plugin helped me to resolve the similar problem.

这篇关于如何在类控制器中从api swagger实现spring注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆