ApacheCamelREST请求POST的Body参数未在OpenAPI/Swagger文档中显示。
创始人
2024-09-05 14:01:29
0

可以使用Camel OpenAPI插件来生成OpenAPI规范文档并将其公开到Swagger UI中。为了在OpenAPI文档中显示POST请求的Body参数,需要将Camel OpenAPI插件配置为支持请求体参数。

以下是使用Camel OpenAPI插件和Camel Rest DSL定义REST服务的示例代码:

restConfiguration()
	.component("servlet")
	.bindingMode(RestBindingMode.auto)
	.dataFormatProperty("prettyPrint", "true")
	.contextPath("/api")
	.apiContextPath("/api-doc")
	.apiProperty("api.title", "User API")
	.apiProperty("cors", "true")
	.enableCORS(true)
	.port(8080)
	.host("localhost");

rest("/users").description("User REST service")
	.produces("application/json")
	.consumes("application/json")
	
	.post().description("Add a new user")
		.type(User.class)
		.param().name("body").type(body).description("The user to add").endParam()
		.outType(User.class)
		.route()
		    .to("bean:UserService?method=addUser")
		.endRest();

在POST请求中,我们使用了.type(User.class)定义请求体参数的类型,并使用.param()定义请求体参数。使用.outType(User.class)定义响应体参数的类型。

要在OpenAPI文档中显示请求体参数,需要使用.apiParam()定义OpenAPI参数。以下是示例代码:

.post().description("Add a new user")
	.type(User.class)
	.param().name("body").type(body).description("The user to add")
		.apiParam().name("user").type(User.class).description("User object").endParam()
	.endParam()
	.outType(User.class)
	.route()
		.to("bean:UserService?method=addUser")
	.endRest();

您应该能够在OpenAPI文档中看到相应的POST请求体参数。

相关内容

热门资讯

安装apache-beam==... 出现此错误可能是因为用户的Python版本太低,而apache-beam==2.34.0需要更高的P...
避免在粘贴双引号时向VS 20... 在粘贴双引号时向VS 2022添加反斜杠的问题通常是由于编辑器的自动转义功能引起的。为了避免这个问题...
Android Recycle... 要在Android RecyclerView中实现滑动卡片效果,可以按照以下步骤进行操作:首先,在项...
omi系统和安卓系统哪个好,揭... OMI系统和安卓系统哪个好?这个问题就像是在问“苹果和橘子哪个更甜”,每个人都有自己的答案。今天,我...
原生ios和安卓系统,原生对比... 亲爱的读者们,你是否曾好奇过,为什么你的iPhone和安卓手机在操作体验上有着天壤之别?今天,就让我...
Android - 无法确定任... 这个错误通常发生在Android项目中,表示编译Debug版本的Java代码时出现了依赖关系问题。下...
Android - NDK 预... 在Android NDK的构建过程中,LOCAL_SRC_FILES只能包含一个项目。如果需要在ND...
Akka生成Actor问题 在Akka框架中,可以使用ActorSystem对象生成Actor。但是,当我们在Actor类中尝试...
Agora-RTC-React... 出现这个错误原因是因为在 React 组件中使用,import AgoraRTC from “ago...
Alertmanager在pr... 首先,在Prometheus配置文件中,确保Alertmanager URL已正确配置。例如:ale...