How to generate Map<String, …> with Swagger Codegen?

流过昼夜 提交于 2020-07-31 04:11:35

问题


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.

Output Object : OutputClass

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

Right now, I used:

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

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?


回答1:


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



来源:https://stackoverflow.com/questions/60256066/how-to-generate-mapstring-with-swagger-codegen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!