-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide better compatibility for projects migrating from OAS 3.0 to O…
…AS 3.1. Fixes #2849
- Loading branch information
1 parent
88f5da0
commit 911fb5f
Showing
565 changed files
with
42,605 additions
and
1 deletion.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...openapi-javadoc-tests/src/test/java/test/org/springdoc/api/v31/AbstractSpringDocTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* | ||
* * | ||
* * * | ||
* * * * | ||
* * * * * | ||
* * * * * * Copyright 2019-2025 the original author or authors. | ||
* * * * * * | ||
* * * * * * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * * * * * you may not use this file except in compliance with the License. | ||
* * * * * * You may obtain a copy of the License at | ||
* * * * * * | ||
* * * * * * https://www.apache.org/licenses/LICENSE-2.0 | ||
* * * * * * | ||
* * * * * * Unless required by applicable law or agreed to in writing, software | ||
* * * * * * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * * * * * See the License for the specific language governing permissions and | ||
* * * * * * limitations under the License. | ||
* * * * * | ||
* * * * | ||
* * * | ||
* * | ||
* | ||
*/ | ||
|
||
package test.org.springdoc.api.v31; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springdoc.core.utils.Constants; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.MvcResult; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
/** | ||
* The type Abstract spring doc test. | ||
*/ | ||
@ActiveProfiles("test") | ||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
public abstract class AbstractSpringDocTest { | ||
|
||
/** | ||
* The constant className. | ||
*/ | ||
public static String className; | ||
|
||
/** | ||
* The Mock mvc. | ||
*/ | ||
@Autowired | ||
protected MockMvc mockMvc; | ||
|
||
/** | ||
* Gets content. | ||
* | ||
* @param fileName the file name | ||
* @return the content | ||
* @throws Exception the exception | ||
*/ | ||
public static String getContent(String fileName) throws Exception { | ||
try { | ||
Path path = Paths.get(AbstractSpringDocTest.class.getClassLoader().getResource(fileName).toURI()); | ||
byte[] fileBytes = Files.readAllBytes(path); | ||
return new String(fileBytes, StandardCharsets.UTF_8); | ||
} | ||
catch (Exception e) { | ||
throw new RuntimeException("Failed to read file: " + fileName, e); | ||
} | ||
} | ||
|
||
/** | ||
* Test app. | ||
* | ||
* @throws Exception the exception | ||
*/ | ||
@Test | ||
protected void testApp() throws Exception { | ||
className = getClass().getSimpleName(); | ||
String testNumber = className.replaceAll("[^0-9]", ""); | ||
MvcResult mockMvcResult = mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL)).andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.openapi", is("3.1.0"))).andReturn(); | ||
String result = mockMvcResult.getResponse().getContentAsString(); | ||
String expected = getContent("results/3.1.0/app" + testNumber + ".json"); | ||
assertEquals(expected, result, true); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...doc-openapi-javadoc-tests/src/test/java/test/org/springdoc/api/v31/app1/ApiException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* | ||
* * | ||
* * * | ||
* * * * | ||
* * * * * | ||
* * * * * * Copyright 2019-2025 the original author or authors. | ||
* * * * * * | ||
* * * * * * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * * * * * you may not use this file except in compliance with the License. | ||
* * * * * * You may obtain a copy of the License at | ||
* * * * * * | ||
* * * * * * https://www.apache.org/licenses/LICENSE-2.0 | ||
* * * * * * | ||
* * * * * * Unless required by applicable law or agreed to in writing, software | ||
* * * * * * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * * * * * See the License for the specific language governing permissions and | ||
* * * * * * limitations under the License. | ||
* * * * * | ||
* * * * | ||
* * * | ||
* * | ||
* | ||
*/ | ||
|
||
package test.org.springdoc.api.v31.app1; | ||
|
||
/** | ||
* The type Api exception. | ||
*/ | ||
public final class ApiException extends Exception { | ||
|
||
/** | ||
* The constant serialVersionUID. | ||
*/ | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* The Code. | ||
*/ | ||
@SuppressWarnings("unused") | ||
|
||
private final int code; | ||
|
||
/** | ||
* Instantiates a new Api exception. | ||
* | ||
* @param code the code | ||
* @param msg the msg | ||
*/ | ||
public ApiException(int code, String msg) { | ||
super(msg); | ||
this.code = code; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...-openapi-javadoc-tests/src/test/java/test/org/springdoc/api/v31/app1/ApiOriginFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* | ||
* * | ||
* * * | ||
* * * * | ||
* * * * * | ||
* * * * * * Copyright 2019-2025 the original author or authors. | ||
* * * * * * | ||
* * * * * * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * * * * * you may not use this file except in compliance with the License. | ||
* * * * * * You may obtain a copy of the License at | ||
* * * * * * | ||
* * * * * * https://www.apache.org/licenses/LICENSE-2.0 | ||
* * * * * * | ||
* * * * * * Unless required by applicable law or agreed to in writing, software | ||
* * * * * * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * * * * * See the License for the specific language governing permissions and | ||
* * * * * * limitations under the License. | ||
* * * * * | ||
* * * * | ||
* * * | ||
* * | ||
* | ||
*/ | ||
|
||
package test.org.springdoc.api.v31.app1; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.FilterConfig; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.ServletRequest; | ||
import jakarta.servlet.ServletResponse; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* The type Api origin filter. | ||
*/ | ||
class ApiOriginFilter implements jakarta.servlet.Filter { | ||
/** | ||
* Do filter. | ||
* | ||
* @param request the request | ||
* @param response the response | ||
* @param chain the chain | ||
* @throws IOException the io exception | ||
* @throws ServletException the servlet exception | ||
*/ | ||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, | ||
FilterChain chain) throws IOException, ServletException { | ||
HttpServletResponse res = (HttpServletResponse) response; | ||
res.addHeader("Access-Control-Allow-Origin", "*"); | ||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); | ||
res.addHeader("Access-Control-Allow-Headers", "Content-Type"); | ||
chain.doFilter(request, response); | ||
} | ||
|
||
/** | ||
* Destroy. | ||
*/ | ||
@Override | ||
public void destroy() { | ||
} | ||
|
||
/** | ||
* Init. | ||
* | ||
* @param filterConfig the filter config | ||
* @throws ServletException the servlet exception | ||
*/ | ||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
} | ||
} |
Oops, something went wrong.