CXF Swagger2Feature添加全局参数

时间:2018-04-17 23:02:50

标签: cxf swagger

我在请求中有两个全局参数,我处理swagger2Feature,所以我尝试使用以下代码添加两个全局参数,但是失败了。我该怎么做?谢谢任何帮助。

@Bean
    public Server rsServer() {
        final JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
        endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new 
     InvokeFaultExceptionMapper()));
        endpoint.setBus(bus);
        endpoint.setAddress("/");
        endpoint.setServiceBeans(Arrays.<Object>asList(userController()));
        endpoint.setFeatures(Arrays.asList(new ExtendedSwagger2Feature()));
        return endpoint.create();
    }
    @Provider(value = Provider.Type.Feature, scope = Provider.Scope.Server)
    public static class ExtendedSwagger2Feature extends Swagger2Feature {
        @Override
        protected void addSwaggerResource(Server server, Bus bus) {
            super.addSwaggerResource(server, bus);

            BeanConfig config = (BeanConfig) ScannerFactory.getScanner();
            Swagger swagger = config.getSwagger();
            HeaderParameter headerParameter = new HeaderParameter();
            headerParameter.setName("apieui");
            headerParameter.setDefaultValue("123124141");
            swagger.addParameter("apieui", headerParameter);
            swagger.addParameter("tokens", new HeaderParameter());
        }
    }

@Bean public Server rsServer() { final JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new InvokeFaultExceptionMapper())); endpoint.setBus(bus); endpoint.setAddress("/"); endpoint.setServiceBeans(Arrays.<Object>asList(userController())); endpoint.setFeatures(Arrays.asList(new ExtendedSwagger2Feature())); return endpoint.create(); } @Provider(value = Provider.Type.Feature, scope = Provider.Scope.Server) public static class ExtendedSwagger2Feature extends Swagger2Feature { @Override protected void addSwaggerResource(Server server, Bus bus) { super.addSwaggerResource(server, bus); BeanConfig config = (BeanConfig) ScannerFactory.getScanner(); Swagger swagger = config.getSwagger(); HeaderParameter headerParameter = new HeaderParameter(); headerParameter.setName("apieui"); headerParameter.setDefaultValue("123124141"); swagger.addParameter("apieui", headerParameter); swagger.addParameter("tokens", new HeaderParameter()); } }

0 个答案:

没有答案