如何告诉 Swagger 一个属性是一个 Map

编程入门 行业动态 更新时间:2024-10-14 22:20:43
本文介绍了如何告诉 Swagger 一个属性是一个 Map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在与 Jersey 开发一项宁静的服务.但是,我正在使用 Swagger 作为文档.我的模型具有地图类型的属性.Swagger 将这个属性显示为一个 Object(不是特定类型).那么如何告诉 Swagger 这个属性来自 Map 类型呢?

I am developing a restful service with Jersey. However, I am using Swagger for documentation. My Model has a property with Type of Map. Swagger shows that this attribute as an Object (not a specific type). So how can I tell Swagger that this property is from type Map ?

public class Model { private String name; private Map<Integer, String> myMap; public Model(){ super(); } public String getName() { return name; } public void setName(String name) { this.name = name; } public Map<Integer, String> getMyMap() { return myMap; } public void setMyMap(Map<Integer, String> myMap) { this.myMap = myMap; } }

宁静的服务:

@POST @Path("/createBundle") @Consumes({MediaType.APPLICATION_JSON}) @ApiOperation(value = "Create Bundle ", notes = "", response = Model.class) public Model createBundle(Bundle bundle){ return new Model(); }

我需要 Swagger 将其显示为 Map 的类型.

I need Swagger to show it as type of Map<Integer, String>.

Swagger 将文档显示为此图像.

Swagger shows the documentation as this image.

推荐答案

可以在@ApiOperation注解中设置响应类型:

You can set a response type in the @ApiOperation annotation:

@ApiOperation(value = "Find thingies as Map", notes = "Multiple thingies can be returned, <code>id</code> is the ID field", response = java.util.Map.class)

更多推荐

如何告诉 Swagger 一个属性是一个 Map

本文发布于:2023-06-08 21:32:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/589435.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是一个   属性   Swagger   Map

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!