I am using Value.Immutable classes as part of my rest input/output. Swagger does not seem to understand these beans as there are no getters and setters in the immutable interface definition. Because of this, I don't see anything in the Example section in swagger.
How do I enable Value.Immutable classes?
I am using 1.0.0-1
Same problem here with Swagger v1.5.10 (via Springfox-Swagger2 v2.6.1) and Immutables v2.4.3.
What is swagger 2.6.1?
Ah sorry, my mistake. I've corrected my post, it's Swagger (annotations and models) v1.5.10.
The problem seems to be, that Swagger is trying to scan for fields rather than for getters; using the @Value.Immutable
annotation, I'm only defining getters in an abstract class or interface though, the fields are automatically generated in a separate implementing class.
Any updates on this?
Any updates on what? The question isn't very clear.
@webron Thanks for reply. I meant to ask how we could combine using Value.Immutable (immutables.github.io) with swagger?
Is that a solved problem? That will be great if that is the case.
That would introduce another dependency, which we are only doing if absolutely necessary. So I don't think this falls into that category
@fehguy Actually, I disagree. Swagger wouldn't need a further dependency; instead there could be a mode where Swagger will scan beans not for fields but rather for getters. That would solve the problem not just for this case but potentially for many others too.
which part do you disagree with?
I disagree with the notion, that solving this problem would introduce a further dependency. The solution doesn't have to be (and probably shouldn't be) specific to Value.Immutables.
[For context: Value.Immutable refers to the [ immutables.github.io](immutables.github.io) project which uses annotations to create POJOs, I'm sure you've figured this much out]
I have the same issue. It seems that the Jackson io.swagger.jackson.ModelResolver
expects everything to be bean-like. However it's perfectly possible to stream non-bean methods into JSON so really the ModelResolver should look at those methods too.
It doesn't look too tricky to fix, the question really is how best to resolve it? I can think of a few ideas:
Enhance the jackson ModelResolver so that it will pull in every method that gets streamed into the JSON, not just bean-like methods.
Refactor the jackson ModelResolver so that it has some extension points - for example you'd want all ModelResolvers to respect the swagger annotations.
Create an Immutables specific ModelResolver. This is clean but the problem with this is that it would need to see the immutables annotations, which adds a dependency. Is it possible to somehow do this optionally? I've no idea?
(2 & 3 kinda go together as you can see)
If someone who knows about swagger / ModelResolvers (@Webron? @fehguy?) has any suggestions on how best to provide a solution I don't mind taking a look at writing a patch (no promises though :p )
Upon further inspection, I think the root cause here is that the ModelResolver doesn't respect the @JsonSerialize(as=...)
annotation. If we can add this it might JustWork(tm).
Here's the extra test I'm using (to be added to SimpleGenerationTest.java
):
@Test //passes
public void testNotBeanlike() throws Exception {
final Model model = context.resolve(NotBeanlike.class);
final Map<String, Property> props = model.getProperties();
assertEquals(props.size(), 1);
final Property prop = props.values().iterator().next();
assertEquals(prop.getName(), "notGetter");
}
static class NotBeanlike {
@JsonProperty("notGetter")
public String notGetter() {return "Not a getter";}
}
@Test //fails
public void testEvenLessBeanlike() throws Exception {
final Model model = context.resolve(EvenLessBeanlike.class);
final Map<String, Property> props = model.getProperties();
assertEquals(props.size(), 1);
final Property prop = props.values().iterator().next();
assertEquals(prop.getName(), "notGetter");
}
@JsonSerialize(as = NotBeanlike.class)
@JsonDeserialize(as = NotBeanlike.class)
static interface EvenLessBeanlike {
public String notGetter();
}
Yes, we do not support the JsonSerialize(...)
annotation at all. I also don't want to add another dependency as it creates other messes.
However, for testing purposes, let's go ahead and add the immutables dependency as a test dependency.
Please add a test showing this issue and go ahead and the dependency, we'll see if we can fix it in general.
@fehguy I've updated my PR to include an immutables test.
It also has a proposed fix ;)
@fehguy Any thoughts?
This has been merged, sorry for the delay
Thanks - much appreciated!
When are you guys next planning to release?
1.5.14 has been released:
https://github.com/swagger-api/swagger-core/releases/tag/v1.5.14
@fehguy This feature was removed in 2.0.0, was there a reason for this and was the functionality replaced?
@kingcowman - 2.0.0 was a rewrite almost from scratch, so some features might have dropped. Please file a new ticket and reference this one.
Most helpful comment
1.5.14 has been released:
https://github.com/swagger-api/swagger-core/releases/tag/v1.5.14