hybris自定义API的Swagger文档生成

时间:2018-10-26 01:07:53

标签: swagger hybris

嗨,我有一个自定义的Hybris API,我想为其生成svagger文档。@ https://help.hybris.com/1808/hcd/99783546e09949e2b4bf27795b889464.html给出的步骤尚不清楚,并且静态文档生成无法下载maven依赖项。

任何人都可以为我提供逐步生成此文档的过程

1 个答案:

答案 0 :(得分:0)

您必须添加一些库,更改basesitefilter映射,我尝试在下面进行解释:

  1. 在您的webservices扩展lib文件夹中添加了jar文件:
classmate-1.3.1.jar
kxml2-2.1.8.jar
spring-plugin-core-1.2.0.RELEASE.jar
spring-plugin-metadata-1.2.0.RELEASE.jar
springfox-core-2.6.0.jar
springfox-schema-2.6.0.jar
springfox-spi-2.6.0.jar
springfox-spring-web-2.6.0.jar
springfox-swagger-common-2.6.0.jar
springfox-swagger-ui-2.6.0.jar
springfox-swagger2-2.6.0.jar
swagger-annotations-1.5.10.jar
swagger-models-1.5.10.jar
  1. 覆盖此WebConfig类

    @ EnableSwagger2 @组态 @ImportResource({“ WEB-INF / config / v2 / springmvc-v2-servlet.xml”})

    公共类WebConfig扩展了WebMvcConfigurationSupport {

    @Resource
    private List<HttpMessageConverter<?>> messageConvertersV2;
    
    @Resource
    private List<HandlerExceptionResolver> exceptionResolversV2;
    
    private ApplicationContext applicationContext;
    
    @Override
    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        final CommerceHandlerMapping handlerMapping = new CommerceHandlerMapping("v2");
        handlerMapping.setOrder(0);
        handlerMapping.setDetectHandlerMethodsInAncestorContexts(true);
        handlerMapping.setInterceptors(getInterceptors());
        handlerMapping.setContentNegotiationManager(mvcContentNegotiationManager());
        return handlerMapping;
    }
    
    @Override
    protected void configureHandlerExceptionResolvers(final List<HandlerExceptionResolver> exceptionResolvers) {
        final ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver = new ExceptionHandlerExceptionResolver();
        exceptionHandlerExceptionResolver.setApplicationContext(applicationContext);
        exceptionHandlerExceptionResolver.setContentNegotiationManager(mvcContentNegotiationManager());
        exceptionHandlerExceptionResolver.setMessageConverters(getMessageConverters());
        exceptionHandlerExceptionResolver.afterPropertiesSet();
    
        exceptionResolvers.add(exceptionHandlerExceptionResolver);
        exceptionResolvers.addAll(exceptionResolversV2);
        exceptionResolvers.add(new ResponseStatusExceptionResolver());
        exceptionResolvers.add(new DefaultHandlerExceptionResolver());
    }
    
    @Override
    public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
        super.setApplicationContext(applicationContext);
        this.applicationContext = applicationContext;
    }
    
    @Override
    public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false).favorParameter(true);
    }
    
    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("**/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
    
    @Bean
    public Docket api() {
        final ApiInfo apiInfo = new ApiInfoBuilder().title("OCC API documentation")
                .description("This document contains the generated API documentation for Omni Commerce Connect v2.")
                .version("Version v2").build();
    
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any())
                .build().apiInfo(apiInfo);
    }
    

    }

  2. 您必须在filter-config-v2-spring.xml文件中更改基础站点过滤器映射。

<alias alias="baseSiteMatchingFilter" name="defaultBaseSiteMatchingFilter" />
<bean id="defaultBaseSiteMatchingFilter" class="com.yourbasesite.webservices.v2.filter.BaseSiteMatchingFilter">
    <property name="regexp" value="(?!.*swagger.*)(?!.*api-docs.*)^/([^(/)]+)" />
     <property name="baseSiteService" ref="baseSiteService" />
</bean>