java - 古巴平台自定义控制器未在 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
解决方案
自定义 Spring MVC 控制器不计入详细的 swagger 文档中。Swagger 文档仅包括:
- 实体,
- 查询,
- 休息服务。
推荐阅读
- json - Swift - 将类型动态传递给 JSONDecoder
- sql - PostgreSQL 多行作为列
- tensorflow - 在 python 中加载 tensorflow-gpu 似乎会强制我的 Windows 计算机在使其进入睡眠状态后重新启动
- android - 从 JSON 响应改造中获取字符串数据
- c++ - 如何删除cin后的一行?
- ios - 如何在越狱的 iOS 环境中对所有其他应用程序进行浮动视图?
- python - 如何将python中的视频分成4个相等的部分?
- javascript - 对 JavaScript 中除一个元素之外的数组进行排序
- python - 无法使用 Seaborn 绘图
- c# - 多个 REST API 方法可以共享同一个控制器类吗?