-
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
api_docs shows content but swagger-ui (2.6.1) is empty #1615
Comments
Could you try seeing the javascript console to see why its not loading the UI? |
When hitting enter I can see an HTTP-404 on the developer console of firefox: with this information I found: #983 and tried to access: http://localhost:8080/sabi/api/swagger-resources/configuration/ui |
In that case try accessing the swagger-ui here |
Hi,
thanks for your reply. With
http://localhost:8080/sabi/api/swagger-ui.html
I got a HTTP-404 while
http://localhost:8080/sabi/swagger-ui.html get the HTTP-200 shows the UI but nothing from my api.
My api Path comes from:
public class WebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(AppConfig.class);
ctx.setServletContext(servletContext);
Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
dynamic.addMapping("/api/*"); // only responsible for REST API calls and BASE_PATH
dynamic.setLoadOnStartup(1);
}
}
Happy new year :-)
Stefan
… Dilip Krishnan ***@***.***> hat am 1. Januar 2017 um 19:00 geschrieben:
In that case try accessing the swagger-ui here `http://localhost:8080/sabi/api/swagger-ui.html`
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#1615 (comment)
|
Try adding a |
Hm... the docket already has this mapping as you can see in the 3rd code snippet of my first posting. If it helps: I have configured another module with swagger with the same setup, but which can be taken to reproduce without the need of setting up a database. So here are the steps to reproduce:
Now you can see: http://localhost:8080/robot/swagger-ui.html while recognize the pathMapping and provide content. what am I doing wrong? Notice: the dispatcher servlet (see configs/WebAppInitalizer.java) is also configured for the path "api". You may check the dispatcher is working by probing, i.e.: I think that the dispatcher may interfere with the view resolver I added for swagger I'm wondering if I'm so far from standard, with providing swagger doc to a simple rest application. |
Any info about this one? I've got exactly the same problem on a more or less simple Sprint Boot 1.4.1 application. api-docs is generated well but the call from swagger to /swagger-resources fails with 500 http://localhost:8080/swagger-resources 500 Strange enough, if I exclude the SwaggerConfig from the basebackage scan of Spring, the swagger view is shown well but of course without taking the configuration in account. @configuration Summary:
Therefore, the generation of the interface spec works always but only the access via Swagger is somehow destroyed if the config is part of the Spring component scan .... |
One step further: @bean Surfing more around, I think this is similar as this problem here. Any idea how this could be fixed or any workaround? |
Are you getting a null pointer too? Really not sure whats going on. |
perhaps because its not a public controller? |
I thin the exception is the same as in #1328 and the symptoms as well excatly as this issue here: java.lang.NullPointerException: null |
I don't understand the question about the public controller above really, all controllers are public I think? The pointcut defined in JavaMelody looks straight forward. The only speciality is that it sets itself to the top position (setOrder). public class MonitoringSpringAdvisor extends DefaultPointcutAdvisor {
} If this Advisor is executed then springfox throws the null ptr exception. |
@Kusig in particular I was referring to |
The only thing which could be null on this line 67 of ApiResourceController is swaggerResources I think. What would mean that it isn't injected before properly with the constructor of the ApiResourceController. All this happens only if there is registered from another library (javamelody) the mentioned Interceptor above. As seen on other threads, there was as well the problem once such a similar interceptor was installed. I just am unsure about the swaggerResources beeing injected with the Constructor. Why not having it injected independent of the Constructor? |
Some debugging proofed what I wrote before. The swaggerResources is null if such a interceptor is registered which causes Springs cglib stuff to handle this. Might as well be a sideeffect of the variable beeing defined as final. Is this really needed? |
@StefanSchubert Thanks for reporting. The demo repo was helpful in finding the problem. |
@StefanSchubert Hope this helps! |
Long time not worked on my project. I will check this out this week. Do I have to switch to another swagger version? |
You'd just have to try the 2.7.0-SNAPSHOT. See the docs on how to set that up |
Tried to fetch the 2.7.0 Snapshot but maven couldn't resolve it. |
You can find the documentation for 2.7.0 under this link: https://springfox.github.io/springfox/docs/snapshot/#snapshot-3 |
Hm, OK I added the snapshop maven repro. Could compile and used the configuration as shown on the docu link above. All mentions URLS by spring-boot are accessable: However I cannot access /swagger-ui.html which results in a 404 It's not listed above but should be, or? I used the following maven deps for swagger: `
` |
Finally it's working for me too.
Also I have api as part of the base path of my controllers:
But the most important thing to do was this in my app-config:
|
Our Spring (but not spring-boot) app uses the @ annotation EnableWebMvc. To make swagger work we add a config class:
|
@TiltCitySong may be refresh your browser cache |
@dilipkrish Hi , i am also facing the same problem(/v2/api-docs shows all the json but swagger-ui.html is empty) . Project is Spring MVC (4.3.3.RELEASE) swagger(2.7.0) . My Docket Configuration is, @configuration
} My Spring configuration is, @OverRide
} @OverRide http://localhost:8080/travel/swagger-resources/configuration/ui gives : http://localhost:8080/travel/swagger-resources: { Maven: io.springfox springfox-swagger-ui 2.7.0 io.springfox springfox-swagger2 2.7.0web.xml: travel /Please let me now the issue. Thanks, |
I ran into similar situation - looks like 2.7.0 has some issues, I had to use 2.6.1 for both swagger-ui and swagger2. In gradle,
|
@srikanthps please try with 2.7.0 |
TL;DR Clear browser cache I had the same situation (spring-boot 1.5.8.RELEASE, springfox-swagger-ui 2.7.0).
|
What is correct fix for this? I do get similar error. Updated to 2.8 but problem is not solved |
Error similar to what? @yogeshmsharma |
Unnable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. |
You need to add |
Dilip Thanks for reply but it didn't worked @bean |
Are u using an API Gateway? |
No, it is simple Spring application |
I have also provided mapping in spring context xml
|
Hm...it's a while ago. but just in case you wish to compare the config setting, as meanwhile my setup is working, you may have a look at here: https://github.com/StefanSchubert/sabi Ah and reviewing the comments, see my posting from 16 Jun 2017 here? This was what finally helped in my case. |
Stefan thanks for your code base, actually its working for one version of java config where I have used annotation. But it is not working for XML based spring configuration for spring 5.0 . |
In case this help anyone - I encountered this problem after refactoring a Spring Boot project to deploy a WAR to a standalone Tomcat (rather than use the default embedded servlet container). The issue was my @SpringBootApplication class wasn't extending SpringBootServletInitializer |
Content Security Policy - Just in case this helps, I had this. Check your CSP, I disabled 'unsafe-eval' or similar. |
Hi this is a question on configuration. I was reading for hours today but did not get my mistake.
Symptom:
http://localhost:8080/sabi/api/v2/api-docs/
shows me that the annotations have been scanned and assembled. I get a detailed json containing my content.
However when calling the swagger-ui
http://localhost:8080/sabi/swagger-ui.html
The ui renders, but I can see non of my API. Even by pasting the api-docs url from above and pressing enter did not lead to any result.
Here's my setup:
Im using:
with spring-webmvc (4.2.1-RELEASE) and using xml-free annotation based config:
and
What am I doing wrong?
The text was updated successfully, but these errors were encountered: