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
Cycles in Java classes cause infinite loop in ModelAttributeParameterExpander #621
Comments
@candrews I suspect this may be a bug. Will take a look, but most likely its going to be fixed in 2.x |
The team here and I are very psyched about using Swagger, and this issue is a blocker for us, so I have to ask - what's the timeline for 2.x? Also, my naive impression is that if a check for the @apimodel(hidden=true) annotation on the "field" variable in the "expand" method would solve this problem and doesn't seem like it could cause regressions, so is that solution workable, and would it be permitted in a near future non-2.x release? |
Well its really close :) but i'll say at least 2 weeks before a public snapshot/release. Let me see if I can fix it in 1.0.2. |
Having said that, I'd say a couple things
For a sneak peak take a look at the spike-to-seperate-models-and-dtos branch |
we shouldn't rely on an annotation as a means to break the cycle. |
@candrews Out of curiosity why are these deep domain objects annotated with |
I'm using them in controller methods, ex: @Controller
public class AddressService {
@Autowired
private AddressService addressService;
@ModelAttribute("address")
public Address getAddress(@PathVariable int addressId) {
return addressService.getById(addressId);
}
@RequestMapping(value = "/address/{addressId}", method = RequestMethod.POST)
@ResponseBody
public Address updateById(@PathVariable int addressId,
@Valid @ModelAttribute("address") Address address) {
return addressService.update(degree);
}
} There are a lot more methods (getting, updating, deleting, then using views/templates for html rendering, etc) but that's the basic idea. I think that's a pretty common approach. (Using view objects distinct from the entities seems to be a common alternative, but this pattern seems to work fine, too.) |
@candrews It seems like its a lot harder to fix it that I had anticipated in 1.x, especially since I suspect you're expecting that Unfortunately, I think it makes more sense for use to focus our efforts on getting 2.x out. |
This should now be fixed in 2.0 |
This doesn't appear to be fixed, I tried versions 2.0.1 - 2.1.1 and the latest 2.3.1 (which appears to have fixed the need for spring 4, yay!), the versions I could try that work with spring 3. I have the same setup, where entities reference one another, I applied the @ApiModelProperty(hidden = true) but I still get an endless stream of : 2016-01-08 12:47:52,601 [localhost-startStop-1] DEBUG springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander- Attempting to expand expandable field: ending in stackoverflow here: springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander.expand(ModelAttributeParameterExpander.java:84) |
@cm325 could you please try with 2.3.1 that is spring 3 compatible again |
If not please open a 🐛 |
Hi, yes, sry, I just edited my comment to include the fact that I just saw that 2.3.1 is spring 3 compatible, and just tested with that as well, and unfortunately, the same error occurs. I will open new bug- |
👍🏼 would be useful if u can provide a failing model or better still a
|
I just posted this - hoping that will be enough- |
help me . |
When using JPA, Hibernate, and other ORMs, it's common for each side of a relationship to refer to the other. For example:
Currently, this set of classes causes an infinite loop resulting in a StackOverflowError in com.mangofactory.swagger.readers.operation.parameter.ModelAttributeParameterExpander.expand(String, Class<?>, List). The problem is that the Java classes are expanded but the annotation which would cause the field to be excluded is being processed, so Person references Address references Person... and the expansion continues infinitely.
I think the solution is to simply process @ApiModelProperty(hidden = true) annotations at expansion time. It may also be nice to detect when such cycles occur and throw a descriptive error (instead of getting a StackOverflowError) but that's just a nice to have... solving the problem would quite sufficient :-)
Thanks!
The text was updated successfully, but these errors were encountered: