ApacheCamelREST请求POST的Body参数未在OpenAPI/Swagger文档中显示。
创始人
2024-09-05 14:01:05
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请求体参数。

相关内容

热门资讯

透视好友!hhpoker德州牛... 透视好友!hhpoker德州牛仔视频,hhpoker有透视功能吗(透视)原先真的有挂(wepoke教...
透视脚本!fishpoker透... 透视脚本!fishpoker透视,德州局透视脚本,其实是有挂(扑克教程)一、德州局透视脚本软件透明挂...
透视数据!wepoker透视功... 透视数据!wepoker透视功能下载,we-poker正规吗(透视)一贯有挂(线上教程);1、打开软...
透视智能ai!fishpoke... 透视智能ai!fishpoker透视底牌,哈糖大菠萝万能挂,确实真的是有挂(攻略教程);1、下载好哈...
透视透视挂!悦扑克脚本,拱趴大... 透视透视挂!悦扑克脚本,拱趴大菠萝作弊方法(透视)固有真的是有挂(揭秘攻略)1、进入游戏-大厅左侧-...
透视规律!智星德州插件2024... 透视规律!智星德州插件2024最新版,德州真人透视脚本,都是真的有挂(AI教程)1、智星德州插件20...
透视线上!wpk俱乐部有没有辅... 透视线上!wpk俱乐部有没有辅助,aapoker怎么拿好牌(透视)都是有挂(透牌教程)wpk俱乐部有...
透视最新!newpoker脚本... 透视最新!newpoker脚本,pokemmo脚本,切实是有挂(揭秘教程);进入游戏-大厅左侧-新手...
透视挂!xpoker透视辅助,... 透视挂!xpoker透视辅助,德普软件(透视)真是有挂(玩家教程);1、用户打开应用后不用登录就可以...
透视科技!德州私人局怎么透视,... 透视科技!德州私人局怎么透视,pokermaster修改器,一贯真的有挂(2025新版技巧);1、下...