Skip to content
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

Swagger API docs not rendering #7543

Closed
planetf1 opened this issue Mar 20, 2023 · 10 comments
Closed

Swagger API docs not rendering #7543

planetf1 opened this issue Mar 20, 2023 · 10 comments
Assignees

Comments

@planetf1
Copy link
Member

planetf1 commented Mar 20, 2023

Unable to use swagger API with ui chassis:

➜  egeria git:(issue7424) http --follow --verify=false GET https://localhost:8443/swagger-ui.html
2023-03-20 15:18:23.018 - INFO 87794 --- [nio-8443-exec-5] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-03-20 15:18:23.018 -DEBUG 87794 --- [nio-8443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected StandardServletMultipartResolver
2023-03-20 15:18:23.018 -DEBUG 87794 --- [nio-8443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected AcceptHeaderLocaleResolver
2023-03-20 15:18:23.018 -DEBUG 87794 --- [nio-8443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected FixedThemeResolver
2023-03-20 15:18:23.018 -DEBUG 87794 --- [nio-8443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@1d8e209e
2023-03-20 15:18:23.018 -DEBUG 87794 --- [nio-8443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.support.SessionFlashMapManager@4f2f680e
2023-03-20 15:18:23.018 -DEBUG 87794 --- [nio-8443-exec-5] o.s.web.servlet.DispatcherServlet        : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2023-03-20 15:18:23.018 - INFO 87794 --- [nio-8443-exec-5] o.s.web.servlet.DispatcherServlet        : Completed initialization in 0 ms
2023-03-20 15:18:23.045 -DEBUG 87794 --- [nio-8443-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springdoc.webmvc.ui.SwaggerWelcomeWebMvc#redirectToUi(HttpServletRequest)
2023-03-20 15:18:23.046 -DEBUG 87794 --- [nio-8443-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springdoc.webmvc.ui.SwaggerWelcomeWebMvc#redirectToUi(HttpServletRequest)
HTTP/1.1 401
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: keep-alive
Content-Length: 0
Date: Mon, 20 Mar 2023 15:18:23 GMT
Expires: 0
Keep-Alive: timeout=60
Pragma: no-cache
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
WWW-Authenticate: Bearer
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 0


Possibly permission related

http -a admin:secret --follow --verify=false GET https://localhost:8443/swagger-ui.html

has the same result

meantime .. The server chassis itself does not have swagger at all - the swagger page does not exist

➜  egeria git:(issue7424) http --follow --verify=false GET https://localhost:9443/swagger-ui.html
2023-03-20T15:20:20.154Z  INFO 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-03-20T15:20:20.154Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected StandardServletMultipartResolver
2023-03-20T15:20:20.154Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected AcceptHeaderLocaleResolver
2023-03-20T15:20:20.154Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected FixedThemeResolver
2023-03-20T15:20:20.155Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@7ff5929f
2023-03-20T15:20:20.155Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.support.SessionFlashMapManager@30cd5632
2023-03-20T15:20:20.155Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2023-03-20T15:20:20.155Z  INFO 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2023-03-20T15:20:20.175Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : GET "/swagger-ui.html", parameters={}
2023-03-20T15:20:20.191Z DEBUG 88378 --- [nio-9443-exec-5] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
2023-03-20T15:20:20.244Z DEBUG 88378 --- [nio-9443-exec-5] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2023-03-20T15:20:20.244Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2023-03-20T15:20:20.250Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2023-03-20T15:20:20.252Z DEBUG 88378 --- [nio-9443-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2023-03-20T15:20:20.282Z DEBUG 88378 --- [nio-9443-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
2023-03-20T15:20:20.284Z DEBUG 88378 --- [nio-9443-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [{timestamp=Mon Mar 20 15:20:20 GMT 2023, status=404, error=Not Found, path=/swagger-ui.html}]
2023-03-20T15:20:20.320Z DEBUG 88378 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 404
HTTP/1.1 404
Connection: keep-alive
Content-Disposition: inline;filename=f.txt
Content-Type: application/json
Date: Mon, 20 Mar 2023 15:20:20 GMT
Keep-Alive: timeout=60
Transfer-Encoding: chunked
Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers

{
    "error": "Not Found",
    "path": "/swagger-ui.html",
    "status": 404,
    "timestamp": "2023-03-20T15:20:20.264+00:00"
}

@planetf1
Copy link
Member Author

Following some fixes as part of fixing #7424

  • removing use of plugin (it seems that isn't appropriate for springboot 3)
  • ensuring only the new springdoc webmvc starter is applied

, the new behaviour is

  • same as before (cannot test further)
  • and from the server chassis, we now correctly get the swagger UI loaded:
➜  egeria git:(issue7424) ✗ http --follow --verify=false GET https://localhost:9443/swagger-ui.html
2023-03-20T15:23:47.313Z  INFO 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-03-20T15:23:47.313Z DEBUG 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected StandardServletMultipartResolver
2023-03-20T15:23:47.313Z DEBUG 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected AcceptHeaderLocaleResolver
2023-03-20T15:23:47.313Z DEBUG 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected FixedThemeResolver
2023-03-20T15:23:47.314Z DEBUG 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@c85d36f
2023-03-20T15:23:47.314Z DEBUG 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.support.SessionFlashMapManager@9b31448
2023-03-20T15:23:47.314Z DEBUG 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2023-03-20T15:23:47.314Z  INFO 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2023-03-20T15:23:47.332Z DEBUG 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : GET "/swagger-ui.html", parameters={}
2023-03-20T15:23:47.340Z DEBUG 89553 --- [nio-9443-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springdoc.webmvc.ui.SwaggerWelcomeWebMvc#redirectToUi(HttpServletRequest)
2023-03-20T15:23:47.390Z DEBUG 89553 --- [nio-9443-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
2023-03-20T15:23:47.391Z DEBUG 89553 --- [nio-9443-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Nothing to write: null body
2023-03-20T15:23:47.393Z DEBUG 89553 --- [nio-9443-exec-5] o.s.web.servlet.DispatcherServlet        : Completed 302 FOUND
2023-03-20T15:23:47.398Z DEBUG 89553 --- [nio-9443-exec-6] o.s.web.servlet.DispatcherServlet        : GET "/swagger-ui/index.html", parameters={}
2023-03-20T15:23:47.403Z DEBUG 89553 --- [nio-9443-exec-6] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/webjars/]]
2023-03-20T15:23:47.410Z DEBUG 89553 --- [nio-9443-exec-6] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
HTTP/1.1 200
Accept-Ranges: bytes
Connection: keep-alive
Content-Length: 734
Content-Type: text/html
Date: Mon, 20 Mar 2023 15:23:47 GMT
Keep-Alive: timeout=60
Last-Modified: Mon, 20 Mar 2023 15:21:07 GMT
Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers

<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
 <head>
   <meta charset="UTF-8">
   <title>Swagger UI</title>
   <link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
   <link rel="stylesheet" type="text/css" href="index.css" />
   <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
   <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
 </head>

 <body>
   <div id="swagger-ui"></div>
   <script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
   <script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
   <script src="./swagger-initializer.js" charset="UTF-8"> </script>
 </body>
</html>

HOWEVER, the api endpoint is not available
Screenshot 2023-03-20 at 15 25 11

➜  egeria git:(issue7424) ✗ http --follow --verify=false GET https://localhost:9443/v3/api-docs
2023-03-20T15:25:54.212Z DEBUG 89553 --- [nio-9443-exec-9] o.s.web.servlet.DispatcherServlet        : GET "/v3/api-docs", parameters={}
2023-03-20T15:25:54.213Z DEBUG 89553 --- [nio-9443-exec-9] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springdoc.webmvc.api.OpenApiWebMvcResource#openapiJson(HttpServletRequest, String, Locale)
2023-03-20T15:25:57.724Z DEBUG 89553 --- [nio-9443-exec-9] o.s.web.servlet.DispatcherServlet        : Failed to complete request: java.lang.ClassCastException
2023-03-20T15:25:57.725Z DEBUG 89553 --- [nio-9443-exec-9] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2023-03-20T15:25:57.725Z DEBUG 89553 --- [nio-9443-exec-9] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2023-03-20T15:25:57.725Z DEBUG 89553 --- [nio-9443-exec-9] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
2023-03-20T15:25:57.725Z DEBUG 89553 --- [nio-9443-exec-9] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [{timestamp=Mon Mar 20 15:25:57 GMT 2023, status=500, error=Internal Server Error, path=/v3/api-docs}]
2023-03-20T15:25:57.726Z DEBUG 89553 --- [nio-9443-exec-9] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 500
HTTP/1.1 500
Connection: close
Content-Type: application/json
Date: Mon, 20 Mar 2023 15:25:57 GMT
Transfer-Encoding: chunked

{
    "error": "Internal Server Error",
    "path": "/v3/api-docs",
    "status": 500,
    "timestamp": "2023-03-20T15:25:57.725+00:00"
}

Note the 'ClassCastException'

@planetf1
Copy link
Member Author

Failed to complete request: java.lang.ClassCastException: class jdk.proxy2.$Proxy135 cannot be cast to class jakarta.validation.constraints.Max (jdk.proxy2.$Proxy135 is in module jdk.proxy2 of loader org.springframework.boot.loader.LaunchedURLClassLoader @26653222; jakarta.validation.constraints.Max is in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @26653222)

@planetf1
Copy link
Member Author

See
https://springdoc.org/v2/

This technically recomments requiring

springdoc-openapi-starter-webmvc-ui

presumably at implementation Scope. However this causes a dependency warning

    runtimeOnly 'org.springdoc:springdoc-openapi-starter-webmvc-ui'
    implementation 'io.swagger.core.v3:swagger-annotations-jakarta'

But both versions cause the same error in the browser - and inability to get to /v3/api-docs

@planetf1
Copy link
Member Author

Checking dependency chains.

On the server chassis:

+--- org.springframework.boot:spring-boot-starter-web -> 3.0.4
|    +--- io.swagger.core.v3:swagger-annotations:2.2.8 (c)

|    +--- org.springframework:spring-web -> 6.0.6 (*)
|    \--- io.swagger.core.v3:swagger-annotations -> 2.2.8

|    +--- com.google.code.findbugs:jsr305 -> 3.0.2
|    \--- io.swagger.core.v3:swagger-annotations -> 2.2.8

But then the actual spring starter wants the non jarkarta version:

+--- org.springdoc:springdoc-openapi-starter-webmvc-ui -> 2.0.4
|    +--- org.springdoc:springdoc-openapi-starter-webmvc-api:2.0.4
|    |    +--- org.springdoc:springdoc-openapi-starter-common:2.0.4
|    |    |    +--- org.springframework.boot:spring-boot-autoconfigure:3.0.4 (*)
|    |    |    \--- io.swagger.core.v3:swagger-core-jakarta:2.2.8
|    |    |         +--- org.apache.commons:commons-lang3:3.12.0
|    |    |         +--- org.slf4j:slf4j-api:1.7.35 -> 2.0.6
|    |    |         +--- io.swagger.core.v3:swagger-annotations-jakarta:2.2.8
|    |    |         +--- io.swagger.core.v3:swagger-models-jakarta:2.2.8

Whilst one of these is needed (we only need the annotations to compile -- whilst does work if the entire springdoc webmvc starter is pulled in, it's unnecessary for compile, and breaks our validation rules) - with both behaving the same, will leave the code with the preferred version here included.

@planetf1
Copy link
Member Author

@bogdan-sava any ideas here?

@bogdan-sava
Copy link
Contributor

indeed
Swagger and api-docs calls allowed without Bearer token with this PR:

#7549

@bogdan-sava
Copy link
Contributor

Thanks @planetf1

@planetf1
Copy link
Member Author

Thanks @bogdan-sava - that addresses the security issue with the ui -- and swagger now works fine there

There remains an issue with the core chassis - I'll take another look (your thoughts welcome!) to see if I can identify the discrepancy which is causing a 500 on getting the API definition. It's likely dependency related -- the main chassis has a lot more components by default.

@bogdan-sava
Copy link
Contributor

bogdan-sava commented Mar 23, 2023

Hi @planetf1

Yes. Didn't see that. It is because of using javax validation api in glossary view. During the api-docs generation, it can't cast the javax validation.
I create PR to replace it with jakarta validation api: #7554

I tested it and it works

@planetf1
Copy link
Member Author

Confirmed, tests ok in main. Thanks for fixing

@planetf1 planetf1 mentioned this issue Mar 23, 2023
33 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

No branches or pull requests

2 participants