No API definition provided Swagger Not able to display the documentation
Asked Answered
O

3

7

I'm not able to display my spring doc in swagger-ui. This is my configuration :

springdoc:
  # api-docs:
    # enabled: true
    # path: /v3/api-docs/swagger-config
  swagger-ui:
    # path: /swagger-ui.html
    disable-swagger-default-url: true
    # config-url: /v3/api-docs/swagger-config
    # url: /v3/api-docs

I enter this URL to access to the interface : http://localhost:8080/swagger-ui.html

swagger ui empty

The problem is that it is not displaying the api-docs which is loaded from :

"http://localhost:8080/v3/api-docs/swagger-config"

Status : 200.

But if i enter this in the url field, it works.. my goal is not to enter this each time..

swagger ui working

I tested everything possible.. i don't understand why it does not work

EDIT : swagger-config

{"configUrl":"/v3/api-docs/swagger-config","oauth2RedirectUrl":"http://localhost:8080/swagger-ui/oauth2-redirect.html","url":"/v3/api-docs","validatorUrl":""}{"configUrl":"/v3/api-docs/swagger-config","oauth2RedirectUrl":"http://localhost:8080/swagger-ui/oauth2-redirect.html","url":"/v3/api-docs","validatorUrl":""}

network tab

Oriel answered 14/4, 2022 at 7:57 Comment(5)
Can you please share the full URL you are accessing, the http console log in network tab and the dependency you added for swagger. Also this might help you #71858122Extrusive
swagger-config : localhost:8080/v3/api-docs/swagger-config docs config : localhost:8080/v3/api-docsWeigela
A picture about the http repsonse in your network tab of the browser would also be helpful. seeing what is actally beeing requestedExtrusive
@Extrusive I have added the pictureWeigela
Hi @Kévin, were you able to get the solution to this or we need to resort to the only way of passing the path in the search bar. Seems like there is no solution to this? Adding springdoc.swagger-ui.url and springdoc.api-docs.path does not work in my case as well.Archaeo
B
9

I had a similar issue and was able to reproduce it by updating the configuration in the springdoc demo project 'springdoc-openapi-spring-boot-2-webmvc'. I had the following properties defined:

springdoc.api-docs.path=/test/v3/api-docs
sprindoc.swagger-ui.config-url=/test/v3/api-docs/swagger-config
springdoc.swagger-ui.path=/test/swagger-ui.html

With that configuration I able to reproduce the problem the OP reported. What fixed it for me was to add an additional property:

springdoc.swagger-ui.url=/test/v3/api-docs

Hope this helps.

Bounded answered 20/4, 2022 at 15:27 Comment(1)
No it does not work, you can see that what you say is what is commented in my OP. Same behaviour, i need to tape /v3/api-docs in the search bar and after that it works.. :(Weigela
B
0

Had a similar issue while migrating froms springfox to springdoc, the difference was that when testing locally everything was fine, but remotely it was the same problem.

You pointing at /v3/api-docs and /v3/api-docs/swagger-config helped.
I looked at the response for swagger-config and saw it was the main page of my app instead of a JSON object with the configurations in it.
Then I looked and saw there was a security rule with exceptions for specific urls, including swagger ones. There were springfox ones I didn't need anymore, but no swagger-config. Updating that resolved the problem.

Hope this helps someone.

Briar answered 20/2, 2023 at 13:35 Comment(0)
S
0

I worked by that:

springdoc:
  swagger-ui:
    # swagger-ui地址
    path: /springdoc/swagger-ui.html
    enabled: true
    # 配置本地访问页面(注释)
    #config-url: /springdoc/api-docs/swagger-config
    # 取消默认Swagger访问页面
    disable-swagger-default-url: true
    # 修复Failed to load remote configuration.
    url: /springdoc/api-docs
  api-docs:
    path: /springdoc/api-docs

Otherwise, I do other thing at ResponseBodyAdvice

@RestControllerAdvice
@Slf4j
public class UnitedResponseAdvice implements ResponseBodyAdvice<Object> {

    @Override
    public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
        return true;
    }

    @Override
    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
        if (body != null && !(body instanceof ResponseVo) && !(body instanceof byte[])) {
            // 放行Swagger相关
            if (body instanceof TreeMap && ((TreeMap)body).containsKey("oauth2RedirectUrl")) {
                return body;
            }
            return ResponseVo.message(ResponseCode.SUCCESS.val(), ResponseCode.SUCCESS.des(), body);
        }
        return body;
    }
}
Starchy answered 25/7, 2023 at 3:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.