-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
UI stalling when API returns a ResponseEntity<String> #50
Comments
@agentgonzo This is a known issue! This is because there is a limitation with the schema generation to not be able to generate generic types very well. The UI is not stalled, if you look closely it has a javascript error in the browser. One way to prevent "stalling" and working around the problem, is to add a configuration extension to ignore (ResponseEntity.class) and decorate your controller method with @apimodel(type=String.class). The configuration should look something like the example below <bean id="swaggerConfiguration" class="com.mangofactory.swagger.SwaggerConfiguration">
<property name="basePath" value="http://localhost:8080/swagger-springmvc-test"/>
<property name="extensions">
<bean class="com.mangofactory.swagger.SwaggerConfigurationExtension" >
...
<property name="ignorableParameterTypes">
<list>
<value type="java.lang.Class">org.springframework.http.ResponseEntity</value>
</list>
</property>
<property name="documentationTransformer" value="some class"/>
</bean>
</property>
...
</bean> There was a regression that has now been fixed. This should be available in the 0.4.1 release in the next couple of days. |
OK, thanks for the info. I'll await the new release! |
I've just tried out the above code again in 0.4.1. Where it was stalling before (javascript error), I now get a 500 error. If curling the URL directly at http://localhost:8080/api-docs/core/metrics?api_key=special-key I get the following stack trace: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class |
@agentgonzo I believe thats a regression. We experimented with trying to use the wordnik schema provider and that seemed to not work out as you've found out! We're working on a rewrite of the schema generation for the next release, but in the mean time. I'll have another build out to revert the schema generation back to what it was (however sub-optimal). |
@agentgonzo This issue should be resolved now. Well its reverted to its earlier behavior. You might find that you get further along in the process only to get another error. Its not worth chasing that problem however since its being re-written anyways in the next release. Do let me know how the 0.4.2 works out. |
Thanks. I'll take a look at it today and get back to you then wait for the rewrite. Thanks for the good work! On 9 Apr 2013, at 00:14, Dilip Krishnan notifications@github.com wrote:
|
Yes, I can confirm that 0.4.2 has exactly the same behaviour as 0.4.0, namely: public Object test() {...} works fine |
Hi, |
@Daigotsu This has been fixed and should be available in 0.5.0. Would you mind trying 0.5.0-SNAPSHOT to see if you have any issues? |
Looks that the problem still occur. After upgrading to the 0.5.0 StackOverflowError is thrown. Below you will find the stack trace which I hope will help you in finding the reason: java.lang.StackOverflowError Unfortunately solving this issue is getting quite urgent to me so I would ask when the final fix will be provided (stable version). If you need any additional information, don't hesistate to ask. |
@dilipkrish fix of #69 helped. Now works much better, thanks for that (no exception is thrown) but I've experienced other issue. After opening the main page I'm receiving: "fetching resource xxx-controller: http://localhost:8080/......" and nothing happend. But after pasting the url manually into the browser I'm receiving the json (I think correct) response. |
@Daigotsu Could you see if you're getting a javascript error in the browser? I know of an existing bug in the swagger ui that is fixed in the swagger-springmvc-example project. It doesnt seem like an issue with this library however |
Previously I'd just been using the maven releases. As 0.5.0-SNAPSHOT hasn't [ERROR] COMPILATION ERROR : I don't know what to do about that error unfortunately given the 'found' If I can get a working version of 0.5.0 I can test to see whether I still On 1 May 2013 14:41, Dilip Krishnan notifications@github.com wrote:
|
@Daigotsu I didn't get any javascript error (at least the console in my browser don't show any error). I will take a look on the example that you attached, maybe it will help me in finding the reason why it doesn't work. |
@agentgonzo Its hard to figure out these problems as I have no idea what your set up is (IDE, Environment etc.). It seems to be building just fine from the repository. Are you using git to get the latest codebase or are you just downloading the zip file? |
@Daigotsu Are you perhaps running into a stack overflow error on the browser? I think you need to wait a bit before the swagger ui throws an error. I know that swagger has a bug with generating models with recursive types. for e.g. A -- has a property of type --> B -- has a property of type (parent) --> A |
I got the latest source from git. then just ran 'mvn package'. Tried this On 2 May 2013 15:28, Dilip Krishnan notifications@github.com wrote:
|
Try doing a mvn clean install |
same error On 2 May 2013 15:44, Dilip Krishnan notifications@github.com wrote:
|
if you can release 0.5.0-SNAPSHOT into the maven repo I can check it with On 2 May 2013 15:45, Steve Arch steve@quorg.org wrote:
|
Sorry for late answer. Just mention answers.
Everything ok. |
@dilipkrish I've checked the javascript console again. I'm receiving the "Uncaught TypeError: Cannot call method 'toLowerCase' of undefined" that comes from swagger.js:362 ( this.isArray = this.dataType.toLowerCase() === 'array'). btw. The DocumentationController returns xml. Shouldn't the controller produce an application/json? |
So, i try to start application with 0.5.0 version, but get an error on ui SwaggerOperations must have a nickname. According this updated api manual https://github.com/wordnik/swagger-core/wiki/API-Declaration#apis nickname field mandatory. But i can't find where i must specify this 'nickname'. Can u help me? |
@Daigotsu I think, you don't need to specify the nickname. I think that the nickname is just a name of the controller method responsible for handling the request |
@dilipkrish I think I found the reason why swagger-ui hangs on fetching the data. I have a private method in my controller that returns URL (java.net). It seems that the DocumentationController takes all methods (even if a method is private and is not annotated). In result URL class is included in the model ("models"). Furthermore URL class has a method getContent that returns ... Object and type information is not generated for that (but the property "content" is created in the output xml/json). In result, swagger-ui throws an error. |
@andrzejpa Yeah i see it, but I doesn't make any changes. Controller public methods all under ApiOperation. I have never explicit set method name. Only response type. |
@dilipkrish I fixed it (I'm not able to commit the code). The type information in ObjectMemberVisitor was not set. The following lines added to the "schema" method solved my issue: In addition junit test (SimpleModelTest:schemaHasAnObjectProperty) needs to be updated as well to verify that the "object" type is returned. |
@agentgonzo Did you ever get the compilation issue you were having resolved? I am experiencing the same. |
@beeler78 Seems like this stack overflow question might help with figuring out the problem. It works just fine on the mac, I'll check the windows vm and see if that works as well. EDIT: I tested it on windows and it works just fine. Java version 1.6.0_34-b04 |
@beeler78 - no, I haven't managed to get it working. The workaround that I have in place at the moment is to just have the methods return Object rather than ResponseEntity<?> and am waiting on a release of 0.5.0 which I hope will fix it. |
@dilipkrish Thanks for the help. After downloading the most recent Java 6 update (45) it is now compiling successfully. |
#50 (comment) |
I'm using 0.4.0 and springMVC running in jetty.
When I have my API definitions as returning a ResponseEntity object (or any derived class from HttpEntity, the UI will stall at "fetching resource : http://localhost:8085/api-docs/core/metrics?api_key=special-key"
If I make it return a String, or Object, then it will work fine. Strangely, the XML returned when accessing the data directly is exactly the same.
Good:
@RequestMapping(method = RequestMethod.GET, value="/v0.1/test", produces = CONTENT_TYPE)
@ApiOperation(value = "Register DNS service name", notes = "A Path representing the DNS name to register is pas")
@responsebody
public Object test() {
return null;
}
Bad:
@RequestMapping(method = RequestMethod.GET, value="/v0.1/test", produces = CONTENT_TYPE)
@ApiOperation(value = "Register DNS service name", notes = "A Path representing the DNS name to register is pas")
@responsebody
public ResponseEntity test() {
return null;
}
The text was updated successfully, but these errors were encountered: