如何生成 Map<String,...>使用 Swagger Codegen?lt、amp、Map、String

由网友(楆尒錇我1輩釨)分享简介:我正在开发一个 API,我们在 swagger.yaml 文件中定义 API 定义.我正在处理的 API 返回一个包含地图的输出对象.I'm working on an API where we define the API definition in the swagger.yaml file. The API w...

我正在开发一个 API,我们在 swagger.yaml 文件中定义 API 定义.我正在处理的 API 返回一个包含地图的输出对象.

I'm working on an API where we define the API definition in the swagger.yaml file. The API which I am working on returns an output object which contains a map.

输出对象:输出类

public class OutputClass {
   private Map<String, MapValue> map;
   
}

现在,我用过:

 OutputClass:
    type: object
    additionalProperties:
      $ref: '#/definitions/MapValue'

但 Swagger Codegen 生成以下 Java 代码:

But Swagger Codegen generates the following Java code:

public class OutputClass extends HashMap<String, MapValue> implements Serializable { 
}

有什么方法可以达到我的需要吗?

Is there any way to achieve what I need?

推荐答案

你的地图定义是正确的.Swagger Codegen 关于将 OpenAPI 映射转换为 Java 代码的方式存在一个未解决的问题:https://github.com/swagger-api/swagger-codegen/issues/5187

Your map definition is correct. There's an open issue with Swagger Codegen about the way it translates OpenAPI maps to Java code: https://github.com/swagger-api/swagger-codegen/issues/5187

阅读全文

相关推荐

最新文章