Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.

Commit 251d250

Browse files
fix(swagger): ensure byteArrayHttpMessageConverter is the first converter to render swagger UI (#1865) (#1867)
* fix(swagger): ensure byteArrayHttpMessageConverter is the first converter to render swagger UI * test(swagger): add test for swagger openapi migration * test(swagger): refactor fix and rename swagger test (cherry picked from commit aaf0414) Co-authored-by: Edgar Garcia <63310723+edgarulg@users.noreply.github.com>
1 parent 8345720 commit 251d250

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/CloudEventHandlerConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020
import org.springframework.context.annotation.Bean;
2121
import org.springframework.context.annotation.Configuration;
22+
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
2223
import org.springframework.http.converter.HttpMessageConverter;
2324
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
2425

@@ -27,6 +28,11 @@ public class CloudEventHandlerConfiguration implements WebMvcConfigurer {
2728

2829
@Override
2930
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
31+
converters.add(
32+
0,
33+
new ByteArrayHttpMessageConverter()); // adding ByteArrayHttpMessageConverter as the first
34+
// element to avoid Swagger decode issues. See:
35+
// https://github.com/springdoc/springdoc-openapi/issues/2143
3036
converters.add(cloudEventHttpMessageConverter());
3137
}
3238

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2025 Harness, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.netflix.spinnaker.gate.config;
18+
19+
import static org.hamcrest.Matchers.is;
20+
import static org.hamcrest.Matchers.startsWith;
21+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
22+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
23+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
24+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
25+
26+
import com.netflix.spinnaker.gate.Main;
27+
import org.junit.jupiter.api.Test;
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
30+
import org.springframework.boot.test.context.SpringBootTest;
31+
import org.springframework.test.context.ActiveProfiles;
32+
import org.springframework.test.context.TestPropertySource;
33+
import org.springframework.test.web.servlet.MockMvc;
34+
35+
@AutoConfigureMockMvc
36+
@SpringBootTest(classes = Main.class)
37+
@ActiveProfiles("swaggertest")
38+
@TestPropertySource(properties = {"spring.config.location=classpath:gate-test.yml"})
39+
public class GateSwaggerConfigTest {
40+
41+
@Autowired private MockMvc mockMvc;
42+
43+
private static final String OPENAPI_API_PATH = "/v3/api-docs";
44+
45+
@Test
46+
void TestSwaggerDocsIsNotMalformed() throws Exception {
47+
mockMvc
48+
.perform(get(OPENAPI_API_PATH))
49+
.andDo(print())
50+
.andExpect(status().isOk())
51+
.andExpect(
52+
jsonPath("$.openapi", startsWith("3."))) // validates we use version 3.x.x from kork
53+
.andExpect(jsonPath("$.info.title", is("Spinnaker Test")));
54+
}
55+
}

gate-web/src/test/resources/gate-test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,18 @@ spinnaker:
7272
front50:
7373
enabled: true
7474
url: https://front50.net
75+
76+
---
77+
78+
spring:
79+
config:
80+
activate:
81+
on-profile: swaggertest
82+
83+
swagger:
84+
enabled: true
85+
title: Spinnaker Test
86+
description:
87+
contact:
88+
patterns:
89+
- /test

0 commit comments

Comments
 (0)