I cannot find a way to use Swagger UI with --skip-client
flag used during project generation.
I want to be able Swagger UI when only server code is generated. I only want to use server side code from JHipster, as I plan use completely separate frontend Angular 7 application. I don't want JHipster to generate webapp code, because it brings to much code overhead, which I want to avoid by creating separate a webapp.
http://localhost:8080/
results in 404
error
http://localhost:8080/v2/api-docs
shows raw Swagger JSON source content
http://localhost:8080/api/swagger-ui.html
throws the following error:
{
"type" : "https://www.jhipster.tech/problem/problem-with-message",
"title" : "Unauthorized",
"status" : 401,
"detail" : "Full authentication is required to access this resource",
"path" : "/api/swagger-ui.html",
"message" : "error.http.401"
}
I want to be able to authorize in order to use Swagger UI even when no client code was generated.
[email protected] /Users/milan/workspace/project
└── [email protected]
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.acme.project"
},
"jhipsterVersion": "5.7.2",
"applicationType": "monolith",
"baseName": "Project",
"packageName": "com.acme.project",
"packageFolder": "com.acme.project",
"serverPort": "8080",
"authenticationType": "jwt",
"cacheProvider": "hazelcast",
"enableHibernateCache": false,
"websocket": false,
"databaseType": "cassandra",
"devDatabaseType": "cassandra",
"prodDatabaseType": "cassandra",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSwaggerCodegen": false,
"jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
"testFrameworks": [],
"jhiPrefix": "jhi",
"otherModules": [],
"enableTranslation": false,
"clientPackageManager": "yarn",
"skipClient": true
}
}
entityName.json
files generated in the .jhipster
directorymacOS Mojave Version 10.14.2
Google Chrome Version 71.0.3578.98 (Official Build) (64-bit)
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
git version 2.20.1
node: v11.6.0
npm: 5.1.0
yeoman: 2.0.5
yarn: 1.12.3
Docker version 18.09.0, build 4d60db4
docker-compose version 1.23.2, build unknown
This use case is not handled by JHipster currently. However I see two workarounds :
Please use one of the solution suggested by @PierreBesson
@PierreBesson
When I skip client during project generation, I cannot find Swagger folder nor JHipster Registry URL, even though I chose to use it with generator. How do I access JHipster Registry? The only URL I see in my IDE is http://localhost:8080/
.
I don't want to use JHipster for frontend application, as I use separate lightweight Angular 7 application. JHipster Angular frontend generated code is a bit too much to handle.
docker-compose -f src/main/Docker/jhipster-registry.yml up -d
then access it on localhost:8761.@PierreBesson
- When I skip client during project generation, I cannot find Swagger folder nor JHipster Registry URL, even though I chose to use it with generator. How do I access JHipster Registry? The only URL I see in my IDE is
http://localhost:8080/
.- I don't want to use JHipster for frontend application, as I use separate lightweight Angular 7 application. JHipster Angular frontend generated code is a bit too much to handle.
You can add dependency swagger-ui into your project. Then, update mave, build , run project. The SwaggerUI will be available on URL http://localhost:8080/swagger-ui.html
@huyleonis, maybe your suggestion can be discussed on this opened issue: https://github.com/jhipster/generator-jhipster/issues/7966
@huyleonis yes but how would you manage authentication in swagger-ui?
@micobarac I got same issue, my workaround is add swagger-ui and swagger-layer dependency in pom.xml. then I can access http://localhost:8080/docs.html
@recyclerzhu2015 I added swagger-ui dependency to pom.xml and setup a Swagger docklet, but I cannot compile the project. Btw, what is swagger-layer, as I cannot find it on Maven repository?
Manual:
Spring Boot REST API Documentation with Swagger and SpringFox
Error:
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.IllegalStateException: Multiple Dockets with the same group name are not supported. The following duplicate groups were discovered. default
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185)
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:893)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
at com.logate.openprovider.OpenproviderApp.main(OpenproviderApp.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalStateException: Multiple Dockets with the same group name are not supported. The following duplicate groups were discovered. default
at springfox.documentation.spring.web.plugins.DuplicateGroupsDetector.ensureNoDuplicateGroups(DuplicateGroupsDetector.java:45)
at springfox.documentation.spring.web.plugins.DocumentationPluginsManager.documentationPlugins(DocumentationPluginsManager.java:97)
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:148)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182)
... 17 common frames omitted
It looks like one cannot create a Swagger docket without specifying group name, which is confusing.
When I set group name along with Swagger docket, the project compiles, but hitting http://localhost:8080/swagger-ui.html gives 404 error :(.
Ok, I managed to start it without docket configuration. All Springfox dependencies must have explicit versions set inside pom.xml.
By running mvn clean spring-boot:run
, I was able to start Swagger UI.
The question that still remains is how to configure Swagger UI default settings through docket, without setting specific group name?
Hi @micobarac , can i ask the configuration that you use for starting the swagger ui?
Hi @gvernile, I had the same need that @micobarac so for me was enough to add the swagger-ui dependecy to pom.xml and add the corresponding antMatcher for the swagger-ui.html resource handler to avoid the unauthorized error:
In pom.xml:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
In SecurityConfiguration.java, within configure method:
.antMatchers("/swagger-ui.html")
For me, the swagger ui it's showed up in http://localhost:8080/myappserver/swagger-ui.html
Note
I've generate only a back-end application (JHipster v6.4.1) served in the /myappserver context deployed on Tomcat 9
try this one :
http://localhost:8080/swagger-ui/index.html
Most helpful comment
You can add dependency swagger-ui into your project. Then, update mave, build , run project. The SwaggerUI will be available on
URL http://localhost:8080/swagger-ui.html