Skip to content

Commit 911fb5f

Browse files
committed
Provide better compatibility for projects migrating from OAS 3.0 to OAS 3.1. Fixes #2849
1 parent 88f5da0 commit 911fb5f

File tree

565 files changed

+42605
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

565 files changed

+42605
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2025 the original author or authors.
8+
* * * * * *
9+
* * * * * * Licensed under the Apache License, Version 2.0 (the "License");
10+
* * * * * * you may not use this file except in compliance with the License.
11+
* * * * * * You may obtain a copy of the License at
12+
* * * * * *
13+
* * * * * * https://www.apache.org/licenses/LICENSE-2.0
14+
* * * * * *
15+
* * * * * * Unless required by applicable law or agreed to in writing, software
16+
* * * * * * distributed under the License is distributed on an "AS IS" BASIS,
17+
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* * * * * * See the License for the specific language governing permissions and
19+
* * * * * * limitations under the License.
20+
* * * * *
21+
* * * *
22+
* * *
23+
* *
24+
*
25+
*/
26+
27+
package test.org.springdoc.api.v31;
28+
29+
import java.nio.charset.StandardCharsets;
30+
import java.nio.file.Files;
31+
import java.nio.file.Path;
32+
import java.nio.file.Paths;
33+
34+
import org.junit.jupiter.api.Test;
35+
import org.springdoc.core.utils.Constants;
36+
37+
import org.springframework.beans.factory.annotation.Autowired;
38+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
39+
import org.springframework.boot.test.context.SpringBootTest;
40+
import org.springframework.test.context.ActiveProfiles;
41+
import org.springframework.test.web.servlet.MockMvc;
42+
import org.springframework.test.web.servlet.MvcResult;
43+
44+
import static org.hamcrest.Matchers.is;
45+
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
46+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
47+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
48+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
49+
50+
/**
51+
* The type Abstract spring doc test.
52+
*/
53+
@ActiveProfiles("test")
54+
@SpringBootTest
55+
@AutoConfigureMockMvc
56+
public abstract class AbstractSpringDocTest {
57+
58+
/**
59+
* The constant className.
60+
*/
61+
public static String className;
62+
63+
/**
64+
* The Mock mvc.
65+
*/
66+
@Autowired
67+
protected MockMvc mockMvc;
68+
69+
/**
70+
* Gets content.
71+
*
72+
* @param fileName the file name
73+
* @return the content
74+
* @throws Exception the exception
75+
*/
76+
public static String getContent(String fileName) throws Exception {
77+
try {
78+
Path path = Paths.get(AbstractSpringDocTest.class.getClassLoader().getResource(fileName).toURI());
79+
byte[] fileBytes = Files.readAllBytes(path);
80+
return new String(fileBytes, StandardCharsets.UTF_8);
81+
}
82+
catch (Exception e) {
83+
throw new RuntimeException("Failed to read file: " + fileName, e);
84+
}
85+
}
86+
87+
/**
88+
* Test app.
89+
*
90+
* @throws Exception the exception
91+
*/
92+
@Test
93+
protected void testApp() throws Exception {
94+
className = getClass().getSimpleName();
95+
String testNumber = className.replaceAll("[^0-9]", "");
96+
MvcResult mockMvcResult = mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL)).andExpect(status().isOk())
97+
.andExpect(jsonPath("$.openapi", is("3.1.0"))).andReturn();
98+
String result = mockMvcResult.getResponse().getContentAsString();
99+
String expected = getContent("results/3.1.0/app" + testNumber + ".json");
100+
assertEquals(expected, result, true);
101+
}
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2025 the original author or authors.
8+
* * * * * *
9+
* * * * * * Licensed under the Apache License, Version 2.0 (the "License");
10+
* * * * * * you may not use this file except in compliance with the License.
11+
* * * * * * You may obtain a copy of the License at
12+
* * * * * *
13+
* * * * * * https://www.apache.org/licenses/LICENSE-2.0
14+
* * * * * *
15+
* * * * * * Unless required by applicable law or agreed to in writing, software
16+
* * * * * * distributed under the License is distributed on an "AS IS" BASIS,
17+
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* * * * * * See the License for the specific language governing permissions and
19+
* * * * * * limitations under the License.
20+
* * * * *
21+
* * * *
22+
* * *
23+
* *
24+
*
25+
*/
26+
27+
package test.org.springdoc.api.v31.app1;
28+
29+
/**
30+
* The type Api exception.
31+
*/
32+
public final class ApiException extends Exception {
33+
34+
/**
35+
* The constant serialVersionUID.
36+
*/
37+
private static final long serialVersionUID = 1L;
38+
39+
/**
40+
* The Code.
41+
*/
42+
@SuppressWarnings("unused")
43+
44+
private final int code;
45+
46+
/**
47+
* Instantiates a new Api exception.
48+
*
49+
* @param code the code
50+
* @param msg the msg
51+
*/
52+
public ApiException(int code, String msg) {
53+
super(msg);
54+
this.code = code;
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2025 the original author or authors.
8+
* * * * * *
9+
* * * * * * Licensed under the Apache License, Version 2.0 (the "License");
10+
* * * * * * you may not use this file except in compliance with the License.
11+
* * * * * * You may obtain a copy of the License at
12+
* * * * * *
13+
* * * * * * https://www.apache.org/licenses/LICENSE-2.0
14+
* * * * * *
15+
* * * * * * Unless required by applicable law or agreed to in writing, software
16+
* * * * * * distributed under the License is distributed on an "AS IS" BASIS,
17+
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* * * * * * See the License for the specific language governing permissions and
19+
* * * * * * limitations under the License.
20+
* * * * *
21+
* * * *
22+
* * *
23+
* *
24+
*
25+
*/
26+
27+
package test.org.springdoc.api.v31.app1;
28+
29+
import java.io.IOException;
30+
31+
import jakarta.servlet.FilterChain;
32+
import jakarta.servlet.FilterConfig;
33+
import jakarta.servlet.ServletException;
34+
import jakarta.servlet.ServletRequest;
35+
import jakarta.servlet.ServletResponse;
36+
import jakarta.servlet.http.HttpServletResponse;
37+
38+
/**
39+
* The type Api origin filter.
40+
*/
41+
class ApiOriginFilter implements jakarta.servlet.Filter {
42+
/**
43+
* Do filter.
44+
*
45+
* @param request the request
46+
* @param response the response
47+
* @param chain the chain
48+
* @throws IOException the io exception
49+
* @throws ServletException the servlet exception
50+
*/
51+
@Override
52+
public void doFilter(ServletRequest request, ServletResponse response,
53+
FilterChain chain) throws IOException, ServletException {
54+
HttpServletResponse res = (HttpServletResponse) response;
55+
res.addHeader("Access-Control-Allow-Origin", "*");
56+
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
57+
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
58+
chain.doFilter(request, response);
59+
}
60+
61+
/**
62+
* Destroy.
63+
*/
64+
@Override
65+
public void destroy() {
66+
}
67+
68+
/**
69+
* Init.
70+
*
71+
* @param filterConfig the filter config
72+
* @throws ServletException the servlet exception
73+
*/
74+
@Override
75+
public void init(FilterConfig filterConfig) throws ServletException {
76+
}
77+
}

0 commit comments

Comments
 (0)