๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Trouble Shooting

Spring Swagger(springdoc-openapi) Unable to render this definition ์˜ค๋ฅ˜

by ์ฃผ๋ฐœ2 2024. 3. 4.
๋ฐ˜์‘ํ˜•

Spring ์—์„œ ๋ฌธ์„œํ™”๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ ์ž Swagger(Springdoc-openapi)๋ฅผ ์ถ”๊ฐ€ํ•˜๋ ค๊ณ  ํ•˜๋Š”๋ฐ, ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฌธ๊ตฌ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.

 

Unable to render this definition ...

 

 

 

์‹ค์ œ api-docs URL๋กœ ์ ‘๊ทผํ•ด๋ณด๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฉ”์‹œ์ง€๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ปจ๋ฒ„ํ„ฐ๊ฐ€ ์•ˆ๋˜์–ด ๋‚˜์˜ค๋Š” ๋“ฏ ํ•œ ํ˜„์ƒ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

 

 

 

ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” MessageConverter ๋ฅผ Customํ•˜์—ฌ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ณ , ๋Œ€๋žต์ ์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉ์ค‘์ž…๋‹ˆ๋‹ค.

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);
        StringHttpMessageConverter converter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
        converter.setWriteAcceptCharset(false);
        converter.setSupportedMediaTypes(Arrays.asList(new MediaType("text", "plain", StandardCharsets.UTF_8)));

        converters.add(converter);
        converters.add(new MappingJackson2HttpMessageConverter());
    }

 

 

 

OpenAPI ๊ณต์‹ ๋ฌธ์„œ์— ๋ณด๋ฉด, ์œ„์™€ ๋™์ผํ•œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์„ค๋ช…ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

https://springdoc.org/#why-am-i-getting-an-error-swagger-ui-unable-to-render-definition-when-overriding-the-default-spring-registered-httpmessageconverter

 

OpenAPI 3 Library for spring-boot

Library for OpenAPI 3 with spring boot projects. Is based on swagger-ui, to display the OpenAPI description.Generates automatically the OpenAPI file.

springdoc.org

ByteArrayHttpMessageConverter๋ฅผ ๋“ฑ๋กํ•˜๋ผ๊ณ  ๋‚˜์˜ค๋Š”๋ฐ์š”, Note์—๋Š” ๋“ฑ๋ก ์ˆœ์„œ ๋˜ํ•œ ์ค‘์š”ํ•˜๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);
        StringHttpMessageConverter converter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
        converter.setWriteAcceptCharset(false);
        converter.setSupportedMediaTypes(Arrays.asList(new MediaType("text", "plain", StandardCharsets.UTF_8)));

        converters.add(converter);
        converters.add(new ByteArrayHttpMessageConverter()); // ์ถ”๊ฐ€
        converters.add(new MappingJackson2HttpMessageConverter());
    }

์œ„์™€ ๊ฐ™์ด ByteArrayHttpMessageConverter() ๋ฅผ MappingJackson2HttpMessageConverter() ์ „์— ๋“ฑ๋ก์„ ํ•˜๋ฉด ์ •์ƒ์ ์œผ๋กœ ํ˜ธ์ถœ์ด ๋˜๋Š”๋ฐ, ์ˆœ์„œ๋ฅผ ๋ฐ˜๋Œ€๋กœ ํ•˜๋ฉด ๋™์ผํ•˜๊ฒŒ Unable to render ... ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€