I am struggling with java annotations to return definition of Maps in my 
Models. I am aware of the additionalProperties stuff. What I want it to 
have them listed among the "definitions" in the swagger.json output

For instance, I am returning data such as:

```
{

    "en": "Hi there!",
    "fr": "Salut !"

}
```

What should I do with my java annotations / classes definitions to finally 
get something like that in swagger-ui:

```
Labels {
    description:    a map lang -> label
    < * >:    string
}

```

I know how the swagger.json file must look like (example below), but I 
don't know how to have it generated using annotations in my java source

For instance, here is a simple Resource that returns a Map language -> 
label:

```
@Path("test")
@Produces(MediaType.APPLICATION_JSON)
@Api(tags={"Test"})
public class TestResource {
    @GET
    @ApiOperation(value = "Testing labels")
    @ApiResponses(value = {
            @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Some 
labels returned by the test salutation resource", response = Labels.class)
    })
    public Labels getResponse() {
        Labels labels = new Labels();
        labels.put("en","Hi there!");
        labels.put("fr", "Salut !");
        return labels;
    }
    
    @ApiModel(description="a Map lang -> label")
    static public class Labels extends LinkedHashMap<String, String> {
    }
}

```

Here is the swagger.json that gets generated:

```
{

    "swagger": "2.0",
    "tags": [
        {
            "name": "Test"
        }
    ],
    "paths": {
        "/test": {
            "get": {
                "tags": [
                    "Test"
                ],
                "summary": "Testing labels",
                "description": "",
                "operationId": "getResponse",
                "produces": [
                    "application/json"
                ],
                "parameters": [ ],
                "responses": {
                    "200": {
                        "description": "Some labels",
                        "schema": {
                            "type": "object",
                            "additionalProperties": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }

}

```

Here how it looks in swagger-ui ("Model") :

```
{
    < * >:    string
}
``

How could I get the following, using java annotations:

```
{

    "swagger": "2.0",
    "tags": [
        {
            "name": "Test"
        }
    ],
    "paths": {
        "/test": {
            "get": {
                "tags": [
                    "Test"
                ],
                "summary": "Testing labels",
                "description": "",
                "operationId": "getResponse",
                "produces": [
                    "application/json"
                ],
                "parameters": [ ],
                "responses": {
                    "200": {
                        "description": "Some labels",
                        "schema": {
                            "$ref": "#/definitions/Labels"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "Labels": {
            "type": "object",
            "description": "a map lang -> label",
            "additionalProperties": {
                "type": "string"
            }
        }
    }

}
```

in order to get the following in swagger-ui:

```
Labels {
    description:    a map lang -> label
    < * >:    string
}

```

TIA

fps

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to swagger-swaggersocket+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to