Skip to content

Commit a33702f

Browse files
committed
merge done
1 parent ecc45df commit a33702f

File tree

9 files changed

+120
-106
lines changed

9 files changed

+120
-106
lines changed

springdoc-openapi-webflux-core/src/test/java/test/org/springdoc/api/AbstractCommonTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public abstract class AbstractCommonTest {
2323
@Autowired
2424
protected WebTestClient webTestClient;
2525

26-
protected String getContent(String fileName) throws Exception {
26+
protected String getContent(String fileName) {
2727
try {
2828
Path path = Paths.get(FileUtils.class.getClassLoader().getResource(fileName).toURI());
2929
byte[] fileBytes = Files.readAllBytes(path);
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package test.org.springdoc.api.app157;
22

3+
import java.util.ArrayList;
4+
35
import io.swagger.v3.core.converter.ModelConverters;
4-
import io.swagger.v3.core.util.Json;
5-
import org.junit.jupiter.api.AfterAll;
66
import org.junit.jupiter.api.AfterEach;
7-
import org.junit.jupiter.api.BeforeAll;
87
import org.junit.jupiter.api.BeforeEach;
98
import org.junit.jupiter.api.Test;
109
import org.springdoc.core.Constants;
11-
import org.springdoc.core.converters.ModelConverterRegistrar;
12-
import org.springframework.boot.autoconfigure.SpringBootApplication;
13-
import org.springframework.test.web.servlet.MvcResult;
1410
import test.org.springdoc.api.AbstractSpringDocTest;
1511

16-
import java.util.List;
12+
import org.springframework.boot.autoconfigure.SpringBootApplication;
1713

18-
import static org.hamcrest.Matchers.*;
14+
import static org.hamcrest.Matchers.hasProperty;
15+
import static org.hamcrest.Matchers.is;
16+
import static org.hamcrest.Matchers.not;
1917
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2018
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
2119
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -27,28 +25,31 @@
2725
*/
2826
public class SpringDocApp157Test extends AbstractSpringDocTest {
2927

30-
@SpringBootApplication
31-
static class SpringBootApp {}
32-
33-
private StringyConverter myConverter = new StringyConverter();
34-
private ModelConverters converters = ModelConverters.getInstance();
35-
36-
@BeforeEach
37-
public void registerConverter() {
38-
converters.addConverter(myConverter);
39-
}
40-
41-
@AfterEach
42-
public void unregisterConverter() {
43-
converters.removeConverter(myConverter);
44-
}
45-
46-
@Test
47-
public void testApp() throws Exception {
48-
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL))
49-
.andExpect(status().isOk())
50-
.andExpect(jsonPath("$.openapi", is("3.0.1")))
51-
.andExpect(jsonPath("$.components.schemas.Foo.required", is(List.of("stringy"))))
52-
.andExpect(jsonPath("$.components.schemas.Bar", not(hasProperty("required"))));
53-
}
28+
@SpringBootApplication
29+
static class SpringBootApp {}
30+
31+
private StringyConverter myConverter = new StringyConverter();
32+
33+
private ModelConverters converters = ModelConverters.getInstance();
34+
35+
@BeforeEach
36+
public void registerConverter() {
37+
converters.addConverter(myConverter);
38+
}
39+
40+
@AfterEach
41+
public void unregisterConverter() {
42+
converters.removeConverter(myConverter);
43+
}
44+
45+
@Test
46+
public void testApp() throws Exception {
47+
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL))
48+
.andExpect(status().isOk())
49+
.andExpect(jsonPath("$.openapi", is("3.0.1")))
50+
.andExpect(jsonPath("$.components.schemas.Foo.required", is(new ArrayList<String>() {{
51+
add("stringy");
52+
}})))
53+
.andExpect(jsonPath("$.components.schemas.Bar", not(hasProperty("required"))));
54+
}
5455
}

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app158/CommonFooErrorHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package test.org.springdoc.api.app157;
1+
package test.org.springdoc.api.app158;
22

33
import org.springframework.http.HttpStatus;
44
import org.springframework.web.bind.annotation.ExceptionHandler;

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app158/ErrorDTO.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package test.org.springdoc.api.app157;
1+
package test.org.springdoc.api.app158;
22

33
public class ErrorDTO {
44
private String message;

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app158/HelloController.java

+10-17
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,22 @@
1616
*
1717
*/
1818

19-
package test.org.springdoc.api.app157;
19+
package test.org.springdoc.api.app158;
2020

21-
import org.springframework.http.HttpStatus;
22-
import org.springframework.http.ResponseEntity;
21+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
22+
import io.swagger.v3.oas.annotations.info.Info;
23+
import io.swagger.v3.oas.annotations.tags.Tag;
2324
import org.springframework.web.bind.annotation.GetMapping;
25+
import org.springframework.web.bind.annotation.RequestMapping;
2426
import org.springframework.web.bind.annotation.RestController;
2527

26-
/**
27-
* Put Foo and Bar in the schema's components, make sure there is an ignored wrapper
28-
* ({@code ResponseEntity}).
29-
*/
3028
@RestController
29+
@RequestMapping("/api")
30+
@OpenAPIDefinition(info = @Info(title = "API Examples", version = "1.0"), tags = @Tag(name = "Operations"))
3131
public class HelloController {
3232

33-
@GetMapping( "/foo")
34-
public ResponseEntity<Foo> getFoo() {
35-
return new ResponseEntity<Foo>(HttpStatus.OK);
36-
}
37-
38-
@GetMapping( "/bar")
39-
public ResponseEntity<Bar> getBar() {
40-
return new ResponseEntity<Bar>(HttpStatus.OK);
33+
@GetMapping("/foo")
34+
public SimpleDTO hello() {
35+
return new SimpleDTO("foo");
4136
}
42-
43-
4437
}

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app158/SimpleDTO.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package test.org.springdoc.api.app157;
1+
package test.org.springdoc.api.app158;
22

33
public class SimpleDTO {
44

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app158/SpecificFooErrorHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package test.org.springdoc.api.app157;
1+
package test.org.springdoc.api.app158;
22

33
import org.springframework.web.bind.annotation.ControllerAdvice;
44

Original file line numberDiff line numberDiff line change
@@ -1,62 +1,12 @@
11
package test.org.springdoc.api.app158;
22

3-
import java.util.List;
4-
5-
import io.swagger.v3.core.converter.ModelConverters;
6-
import org.junit.jupiter.api.AfterEach;
7-
import org.junit.jupiter.api.BeforeEach;
8-
import org.junit.jupiter.api.Test;
9-
import org.springdoc.core.Constants;
103
import test.org.springdoc.api.AbstractSpringDocTest;
114

125
import org.springframework.boot.autoconfigure.SpringBootApplication;
136

14-
import static org.hamcrest.Matchers.hasProperty;
15-
import static org.hamcrest.Matchers.is;
16-
import static org.hamcrest.Matchers.not;
17-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
18-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
19-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
20-
21-
/**
22-
* This test is to make sure that a new model converter can access the parent of a type, even if
23-
* the type is enclosed in an ignored wrapper. We test this by setting up a model converter which
24-
* adds "stringy" to the "required" property of a schema's parent, when the sub schema is a String.
25-
*/
26-
public class SpringDocApp157Test extends AbstractSpringDocTest {
27-
28-
@SpringBootApplication
29-
static class SpringBootApp {}
30-
31-
private StringyConverter myConverter = new StringyConverter();
32-
private ModelConverters converters = ModelConverters.getInstance();
33-
34-
@BeforeEach
35-
public void registerConverter() {
36-
converters.addConverter(myConverter);
37-
}
38-
39-
@AfterEach
40-
public void unregisterConverter() {
41-
converters.removeConverter(myConverter);
42-
}
43-
44-
@Test
45-
public void testApp() throws Exception {
46-
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL))
47-
.andExpect(status().isOk())
48-
.andExpect(jsonPath("$.openapi", is("3.0.1")))
49-
.andExpect(jsonPath("$.components.schemas.Foo.required", is(List.of("stringy"))))
50-
.andExpect(jsonPath("$.components.schemas.Bar", not(hasProperty("required"))));
51-
}
52-
=======
53-
import SpringBootApplication;
54-
import AbstractSpringDocTest;
55-
56-
public class SpringDocApp157Test extends AbstractSpringDocTest {
7+
public class SpringDocApp158Test extends AbstractSpringDocTest {
578

589
@SpringBootApplication
5910
static class SpringDocTestApp {}
6011

61-
>>>>>>> 5537e88ef7529cc8bca8d4f85a36cfab6b6b5b86
62-
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "API Examples",
5+
"version": "1.0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"tags": [
14+
{
15+
"name": "Operations"
16+
}
17+
],
18+
"paths": {
19+
"/api/foo": {
20+
"get": {
21+
"tags": [
22+
"hello-controller"
23+
],
24+
"operationId": "hello",
25+
"responses": {
26+
"409": {
27+
"description": "Conflict",
28+
"content": {
29+
"*/*": {
30+
"schema": {
31+
"$ref": "#/components/schemas/ErrorDTO"
32+
}
33+
}
34+
}
35+
},
36+
"200": {
37+
"description": "OK",
38+
"content": {
39+
"*/*": {
40+
"schema": {
41+
"$ref": "#/components/schemas/SimpleDTO"
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
},
50+
"components": {
51+
"schemas": {
52+
"ErrorDTO": {
53+
"type": "object",
54+
"properties": {
55+
"message": {
56+
"type": "string"
57+
}
58+
}
59+
},
60+
"SimpleDTO": {
61+
"type": "object",
62+
"properties": {
63+
"payload": {
64+
"type": "string"
65+
}
66+
}
67+
}
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)