serverless spring boot3, springdoc, Invalid or unexpected token on swagger ui

127 Views Asked by At

I have the following dependencies:


  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.0</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  ...
    <dependency>
      <groupId>com.amazonaws.serverless</groupId>
      <artifactId>aws-serverless-java-container-springboot3</artifactId>
      <version>2.0.0-M2</version>
    </dependency>

As you can imagine I am running my application in AWS Lambda behind an Api Gateway. The apis work great both in my local and in the cloud.

Then one day, I decided to add a swagger-ui to the project and added following dependency:

    <dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
      <version>2.2.0</version>
    </dependency>

Something very strange happened... In my local I can get the swagger ui immediately. But in the cloud, the swagger ui page shows only a blank page. When I checked the console logs, it says:

Uncaught SyntaxError: Invalid or unexpected token (at swagger-ui-bundle.js:2:867116) swagger-ui-standalone-preset.js:2 

Uncaught SyntaxError: Invalid or unexpected token (at swagger-ui-standalone-preset.js:2:138206) swagger-initializer.js:5 

Uncaught ReferenceError: SwaggerUIBundle is not defined at window.onload (swagger-initializer.js:5:3)
window.onload @ swagger-initializer.js:5
load (async)
(anonymous) @ swagger-initializer.js:1

I checked the swagger-ui-bundle.js:2:867116 It looks like the file is correct up to some point and then it looks like a character encoding issue: 69389:(e,t,n)=>{var r=n(18674)({À:"A",Ã:"A",Â:"A",Ã:"A

Has anyone ever experienced/resolved such issue?

1

There are 1 best solutions below

0
abaratham On

I ran into this same issue - API Gateway expects all responses to be UTF-8 compatible. Adding these configs to application.properties to force Spring Boot to return all responses in UTF-8 format did the trick for me:

server.servlet.encoding.force-response=true
server.servlet.encoding.charset=UTF-8