首页 > 解决方案 > 古巴平台自定义控制器未在 Swagger 中显示

问题描述

我在 cuba 平台中创建了一个自定义休息控制器,并按照文档https://doc.cuba-platform.com/restapi-7.1/#rest_api_v2_custom_auth中的说明进行操作

我的“rest-dispatcher-spring.xml”

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-4.3.xsd">


    <context:component-scan base-package="com.company.test.web.resource"/>
</beans>

“rest-dispatcher-spring.xml”添加到“web-app.properties”

cuba.restSpringContextConfig = +com/company/test/rest-dispatcher-spring.xml

我的控制器看起来像这样

package com.company.test.web.resource;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@RestController
@RequestMapping("/test")
public class TestResource {

    @RequestMapping(value = "/testAPI", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
    public ResponseEntity testAPI() {
        return new ResponseEntity<>(HttpStatus.OK);
    }
}

我可以从 Postman 调用 API,但使用 URL 在 Swagger-ui 中未显示 API

http://localhost:8080/app/rest/v2/docs/swaggerDetailed.yaml

标签: javaspringswagger-uiswagger-2.0cuba-platform

解决方案


自定义 Spring MVC 控制器不计入详细的 swagger 文档中。Swagger 文档仅包括:

  • 实体,
  • 查询,
  • 休息服务。

推荐阅读