Add support for Maps / additionalProperties
How to specify the swagger documentation annotation for generating model schema for Map attribute in a Java bean?
//groovy code
class Foo {
int id
String description
Map<String, Bar> targets
//few other attributes
}
For targets attribute, swaggerui shows 1 line but does not give the model schema for Bar class.
targets (Map[string,Bar])
How do I get Bar class Model schema as well in UI? Am using latest swagger library ('com.wordnik:swagger-jersey-jaxrs_2.10:1.3.8')
Swagger currently doesn't support maps, but the new version of it which is really close is going to. On Sep 3, 2014 10:49 PM, "newtechfellas" [email protected] wrote:
Reopened #558 https://github.com/wordnik/swagger-ui/issues/558.
— Reply to this email directly or view it on GitHub https://github.com/wordnik/swagger-ui/issues/558#event-160784249.
hmm thank you for the clarification. Any tentative date of new version with Map support?
About a week.
On 3 September 2014 23:57, newtechfellas [email protected] wrote:
hmm thank you for the clarification. Any tentative date of new version with Map support?
— Reply to this email directly or view it on GitHub https://github.com/wordnik/swagger-ui/issues/558#issuecomment-54365803.
Is this available now? If yes. any sample documentation on which swagger annotations to add for Map attribute?
This is more of a swagger-core issue, but you can try using 1.5.0-SNAPSHOT. Keep in mind it's fresh so there may be bugs with it.
On 23 September 2014 18:48, newtechfellas [email protected] wrote:
Is this available now? If yes. any sample documentation on which swagger annotations to add for Map attribute?
— Reply to this email directly or view it on GitHub https://github.com/wordnik/swagger-ui/issues/558#issuecomment-56541431.
Yes, you can use the following annotations in an operation:
@ApiOperation(
value = "",
notes = "",
response = ResponseMessage.class,
responseContainer = "Map")
For a model:
https://github.com/wordnik/swagger-core/blob/develop_2.0/modules/swagger-core/src/test/scala/models/Person.java#L9
will produce this:
{
"Person": {
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"firstName": {
"type": "string"
},
"address": {
"$ref": "Address"
},
"properties": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"birthDate": {
"type": "string",
"format": "date-time"
},
"float": {
"type": "number",
"format": "float"
},
"double": {
"type": "number",
"format": "double"
}
}
}
}
It did not work. I tried with latest com.wordnik:swagger-jersey-jaxrs_2.10:1.3.10 version. Swagger doc still shows targets (Map[string,Bar]) for attribute of type Map and no expansion for Bar class properties. (Referring to Foo class in my question)
Also tried the responseContainer attribute for @ApiOperation annotation. No difference with this either.
@ApiOperation(value = "get foo details for person id and foo id", response = Foo, responseContainer = "Map")
You need to be using 1.5.0-SNAPSHOT as the dependency.
the javadoc says 'Valid values are "List", "Array" and "Set"'.. support for Map is new?
The javadocs are based on the 1.3.X release, not updated to 1.5.X yet.
where would I find 1.5.0-SNAPSHOT version? I checked http://repo1.maven.org/maven2/com/wordnik/ but did not find it.
I don't think the SNAPSHOT has been pushed yet. You can clone the repository and built it locally.
There is snapshot in sonatype. maven.org doesn't do snapshots, I believe.
Add this dependency to your pom.xml:
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Didn't mean to close it, will when it's supported in the UI
Any estimations when this will be implemented? Maps are ubiquitous in our api
@mjgolinski - are you using Swagger 2.0?
Yes
to be clear @mjgolinski maps are supported in the 1.5.0-SNAPSHOT version of swagger-jaxrs. In your response, just use containerType="Map". I think they're not complete in the UI, though.
@fehguy I need specifically swagger-ui support or at least estimates about when it will be implemented. Should I open a new ticket for it (I thought this one was about it)?
Hi - I also need it on the UI for submitting a map of strings... I checked out the ui and it doesn't seem to support it yet .. any timeline for this?