-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Map data types #38
Comments
This example could be relevant: http://json-schema.org/example2.html edit: Actually, looks like setting "additionalProperties" to a schema would allow an object to contain arbitrary keys with values following that schema. http://json-schema.org/latest/json-schema-validation.html#anchor64 |
I have some ideas on how these can be solved. In fact we've solved them without changing the spec over at swagger-springmvc. We render generic types with a something that looks like a generic type, its just a trick but it conveys the language specific semantics (in this case generics) without needing to break the specification. For e.g. in spring mvc ResponseEntity«Pet»: {
id: "ResponseEntity«Pet»",
description: "",
extends: "",
properties: {
headers: {
$ref: "HttpHeaders"
},
body: {
type: "Pet"
},
statusCode: {
type: "string"
}
}
}, Ofcourse We define a custom class Entry for the alternate... public class Entry<K, V> {
private V key;
public V getKey() {
return key;
}
public void setKey(V key) {
this.key = key;
}
} and the model gets rendered as ....
In swagger ui the model schema gets rendered as a list of entries ... [
{
"key": {
// Contact model schema goes here
}
] Feedback.. thoughts? |
@dilipkrish - there are two problems I see with what you wrote. The first is the rendering you do for generic classes. This is actually bad, and I think we need to clarify it in the spec ( @fehguy should comment on this as well though ). I believe that model names should be alphanumeric with the exception of a few characters (_, not sure if more than that). The reason is that using a string like The second issue relates to the map representation you propose. Your solution (even without the generics) works. I even suggested it as a workaround in the past. However, I believe it doesn't hit the goal. The question is what meaning we choose to give to 'map'. I believe it should suggest a direct key access data type, much like we support list and sets (sets are lists with unique items only). |
@webron I agree that the map solution is an approximation since Map isnt supported as a first class citizen as a container type. Until we get there, it conveys the intent of what a map is (a list of key value pairs, to be more specific a Set of key value pairs) and also generates the same shape of the data structure in the swagger ui. Ultimately what we care about in any distributed system is the shape of the message thats on either side of the fence and not the behavior. Also, note in swagger-springmvc, Regarding the issue of generic types, I see limiting to alphanumeric and (_ as a potential problem. There are many cases where we need models to have other character. Namespacing is one of them. for e.g. AFAIK, tooling should only care about or break (it does if your identifiers contain Anyways, this solution has been supported for over a year. I've tried swagger code gen and it works pretty well with it too. I'm just trying to socialize how we're using it currently within the scope of the spec and its working out great without having to change it. Just a food for thought. |
Any update on this? We're looking to heavily utilize Swagger on my current project, but this could be a showstopper for us. Our requirement is to support tagging like |
@jgritman - For now, you can emulate it by having a model with two fields - key and value, and then have an array of that model. |
updated operations to require summary instead of description
This has been resolved in Swagger 2.0 by adding support for the |
This is a long-time requested feature, and has many issues in the other repositories. All issues will be linked to here.
I'm not going into the solution at the moment. Feel free to open a discussion as to how you'd expect it to look in the spec (this should follow the JSON schema structure if there is one).
Related issues:
The text was updated successfully, but these errors were encountered: