Hi,
I have a jaxrs (Apache Wink) application and I am trying to document it with Swagger.
Swagger versions that I am using :
swagger-core 1.5.1-M1, swagger-jaxrs: 1.5.1-M1 , Swagger-UI : 2.1.8
Due to some legal reasons I wont be able to update this versions in my project, atleast for some time.
I have a Rest api that takes JsonNode (from Jackson) as input payload ( POST method). To simplify the input for users of the service, the api takes any valid json as input and internally validates if it fits this schema - { "key1" : [ "value1", "value2"] , "key2" : [ "value1", "value2"] }
Swagger UI shows the properties of JsonNode class as the model for input. I need to replace that model with the above schema.
I have implemented the model converter for this that looks like this -
public class JsonNodeModelConverterNew extends AbstractModelConverter {
public JsonNodeModelConverterNew(ObjectMapper mapper) {
super(Json.mapper());
}
@Override
public Model resolve(Type type, ModelConverterContext context, Iterator<ModelConverter> chain) {
ModelImpl impl = new ModelImpl();
String key = "<attributeName1>";
impl.addProperty(key, context.resolveProperty(String.class));
String value = "[ \"<attrValue1>\", \"<attrValue2>\" ]";
impl.addProperty(value, context.resolveProperty(String.class));
context.defineModel(impl.getName(), impl);
return impl;
}
@Override
public Property resolveProperty(Type type, ModelConverterContext context, Iterator<ModelConverter> chain) {
return chain.next().resolveProperty(type, context, chain);
}
But I am not able to figure out how do I a register this converter with the Jaxrs application?
I have tried adding it to the list of classes/singletons in the jaxrs Application subclass, but that does not work. Swagger UI still shows the properties of JsonNode class.
If you could point me to some example, would be great.
Another doubt that I had is - does the version 1.5.1-M1 support Collections as input parameter, Whenever I have tried it is running into ClassCastExceptions.
Even collection types present in other pojos are not correctly represented in request/response models.
What version has support for this enabled?
Any help appreciated.
Thanks,
Nikhil