Skip to content

Malformed (base64 encoded) api-docs JSON when MappingJackson2HttpMessageConverter is active #2143

@lbenedetto

Description

@lbenedetto

To Reproduce
Steps to reproduce the behavior:

  • Spring Boot 3.0.4 or 2.7.8
  • springdoc-openapi-starter-webmvc-ui:2.0.4 or 1.6.15
@Configuration
public class ApiWebMvcConfiguration extends DelegatingWebMvcConfiguration {

  @Autowired
  Jackson2ObjectMapperBuilder jacksonBuilder;

  @Override
  protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    var applicationContext = this.getApplicationContext();
    if (applicationContext != null) {
      jacksonBuilder.applicationContext(applicationContext);
    }
    converters.add(new MappingJackson2HttpMessageConverter(jacksonBuilder.build()));
  }
}

Expected behavior

Expected:

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localhost:8080",
            "description": "Generated server url"
        }
    ],
    "paths": {
        ...
    },
    "components": {}
}

Actual:

"eyJvcGVuYXBpIjoiMy4wLjEiLCJpbmZvIjp7InRpdGxlIjoiT3BlbkFQSSBkZWZpbml0aW9uIiwidmVyc2lvbiI6InYwIn0sInNlcnZlcnMiOlt7InVybCI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MCIsImRlc2NyaXB0aW9uIjoiR2VuZXJhdGVkIHNlcnZlciB1cmwifV0sInBhdGhzIjp7Ii9pZC92MS8iOnsiZ2V0Ijp7InRhZ3MiOlsiZGVtby1jb250cm9sbGVyIl0sInN1bW1hcnkiOiJPSyIsIm9wZXJhdGlvbklkIjoiaW5zdGFuY2VDb25maWciLCJyZXNwb25zZXMiOnsiMjAwIjp7ImRlc2NyaXB0aW9uIjoiT0siLCJjb250ZW50Ijp7IiovKiI6eyJzY2hlbWEiOnsidHlwZSI6InN0cmluZyJ9fX19fX19fSwiY29tcG9uZW50cyI6e319"

This causes swagger-ui to be unable to parse the response

Additional context
I believe this is caused by the changes required for fixing #2051. I tried both adding and removing StringHttpMessageConverter, but the only thing that helps is not registering MappingJackson2HttpMessageConverter

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions