2

I am working on an API which generates client SDK using the swagger.json file. But I am manually editing the swagger.json due to some technical reasons. The issue is that I can receive dynamic response from the API side. 3 to 4 fields are fixed for all responses but the remaining fields may vary. For those remaining fields I need a Map that can contain all the keys of the response json into the key field of the Map and the value field of the response json into the value field of the Map. Currently, I am using the following definition:

    "Annot": {
    {
      "type": "object",
      "properties": {
        "type": {
          "type": "string"
        },
        "begin": {
          "type": "integer",
          "format": "int32"
        },
        "end": {
          "type": "integer",
          "format": "int32"
        },
        "text": {
          "type": "string"
        },
        "additionalProperties": {
                    "type": "object"
                }
      }
    }
  ]
}

But unfortunately what it's generates is:

  private String type;
  private Long begin;
  private Long end;
  private String text;
  private Map additionalProperties;

Following definition is what I am expecting:

  private String type;
  private Long begin;
  private Long end;
  private String text;
  private Map<String, Object> additionalProperties;

Any idea how can create a Map by manually editing the swagger.json or how the definition should look like?

  • Can you show us what your expected output would look like? – Procrastinator Oct 09 '17 at 08:00
  • Please note, the swagger doesn't provide mapping to specific Java classes. From that point you canot go better than "Object". However - you may use an array of other types (array of a type contaning key/value attributes) – gusto2 Oct 09 '17 at 08:58
  • 1
    To make this an mvce, please can you add the command that generates the code? For example if it's `java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate ...` include that in the question with all the parameters you use. – slim Oct 09 '17 at 08:59
  • @slim I think I can not do that because I am using some customized version of swagger. The commands of the of the swagger and customized swagger are different and also the customized version is not available for all I am assuming. – Sourav Bhattacharjee Oct 09 '17 at 09:13
  • 1
    If you can't reproduce the issue with a standard version of Swagger, nobody can help you. – slim Oct 09 '17 at 09:26
  • Obviously I can reproduce it to get a right answer, but initially, I thought that it is not needed assuming who will give that answer knows that command. Anyway, I will add it. – Sourav Bhattacharjee Oct 09 '17 at 09:34
  • Might be useful https://stackoverflow.com/questions/36136885/swagger-map-of-string-object – moondaisy Oct 09 '17 at 13:06

0 Answers0