Closed ShambuGIT closed 2 years ago
@ShambuGIT,
Provide you complete configuration. Same incomplete information as springdoc/springdoc-openapi#1431. Make sure you follow the contribution guidelines before opening issues.
Looks like you are not scanning for your GroupedOpenApi
beans.
If you choose not to use spring-boot. Then you have to scan for all the beans that are automatically auto-configured with spring-boot.
@bnasslahsen - I have provided the samplehello project that shows text box with Explore button if you access http://localhost:8090/hello/openapi/swagger-ui/index.html
Please validate and let me know what am missing.
Note: if I map "DefaultSwagger" as root path(change the <url-pattern>/openapi/*</url-pattern> into <url-pattern>/*</url-pattern>
) then it works fine.
Already answered here: springdoc/springdoc-openapi#841 Simply, move your Beans definition inside a dedicated configuration class:
package com.example.hello;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
class GroupsConfiguration {
@Bean
public GroupedOpenApi accountApi()
{
return GroupedOpenApi.builder()
.group("v1")
.packagesToScan("com.example.hello")
.build();
}
}
@bnasslahsen - Still it does not work under different context (http://localhost:8090/hello/**openapi**/swagger-ui/index.html). Attached the latest hello project
@ShambuGIT,
You are missing the following property in your project as explained here https://github.com/springdoc/springdoc-openapi/issues/899:
spring.mvc.servlet.path=/openapi
Thanks @bnasslahsen. It resolved the issue. One suggestion it would be nice if you put this details in https://springdoc.org/#faq
@bnasslahsen CVan you help this humble soul?? I'm trying to do the same thing, grouping API under the same swagger page, but the difference is the main page is an API GATEWAY, so they are not in the same package. BookService and CambioService should be grouped under Api-Gateway.
The top bar shows the explore tab, I tried everything here to make it show the dropbox but it's not happening... /v3/api-docs/ comes written on the explore box, and if I add /v3/api-docs/book it shows the right page.. same for /cambio.
What I am missing is that the dropbox is refusing to show. I believe I'm grouping them right in the @configuration class
`@Bean
@Lazy(false)
public List
var definitions = locator.getRouteDefinitions().collectList().block();
List<GroupedOpenApi> groupedOpenApis = new ArrayList<>();
definitions.stream()
.filter(routeDefinition -> routeDefinition.getId() != null && !routeDefinition.getId().isEmpty())
.forEach(routeDefinition -> {
String name = routeDefinition.getId();
config.addGroup(name);
GroupedOpenApi groupedOpenApi = GroupedOpenApi.builder()
.pathsToMatch("/" + name + "/**")
.group(name)
.displayName(name) // Use displayName to set a friendly name in the UI
.build();
groupedOpenApis.add(groupedOpenApi);
});
return groupedOpenApis;
}`
server:
port: 8765
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
spring:
application:
name: api-gateway
cloud:
gateway:
discovery:
locator:
enabled: true
routes:
- id: cambio
uri: lb://cambio-service
predicates:
- Path=/cambio/**
- id: book
uri: lb://book-service
predicates:
- Path=/book/**
- id: openApi
uri: lb://api-gateway
predicates:
- Path=/v3/api-docs/**
filters:
- RewritePath=/v3/api-docs/(?<path>.*), /$\{path}/v3/api-docs
springdoc:
swagger-ui:
filter: true
Issue I have spring mvc project without spring boot that integrated springdoc-openapi as mentioned in the document. Everything works fine. but one issue seen in UI where I could not see "select a definition" with list of groups instead it was showing Text box with Explore option.
springdoc-openapi-ui - 1.6.4 spring-boot & spring-boot-autoconfigure - 2.6.2
Screen shot taken from non spring boot app
If i specify api-docs path manually, it works fine. I tried with simple spring boot project where I could see the select a definition option. Is something am i missing in non spring boot integration.
Screen shot taken from spring boot app