|
1 | 1 | package io.swagger; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.databind.JsonNode; |
3 | 4 | import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; |
| 5 | +import io.swagger.annotations.Api; |
| 6 | +import io.swagger.annotations.ApiOperation; |
| 7 | +import io.swagger.annotations.ApiResponse; |
| 8 | +import io.swagger.annotations.ApiResponses; |
| 9 | +import io.swagger.annotations.Example; |
| 10 | +import io.swagger.annotations.ExampleProperty; |
4 | 11 | import io.swagger.converter.ModelConverters; |
5 | 12 | import io.swagger.jaxrs.Reader; |
6 | 13 | import io.swagger.models.ExternalDocs; |
7 | 14 | import io.swagger.models.Model; |
8 | 15 | import io.swagger.models.Operation; |
| 16 | +import io.swagger.models.Pet; |
9 | 17 | import io.swagger.models.Swagger; |
10 | 18 | import io.swagger.models.Tag; |
11 | 19 | import io.swagger.models.parameters.BodyParameter; |
|
42 | 50 | import io.swagger.resources.RsMultipleConsumesProducesResource; |
43 | 51 | import io.swagger.resources.SimpleMethods; |
44 | 52 | import io.swagger.util.Json; |
| 53 | +import io.swagger.util.Yaml; |
45 | 54 | import org.testng.annotations.Test; |
46 | 55 |
|
47 | 56 | import javax.ws.rs.DELETE; |
|
50 | 59 | import javax.ws.rs.OPTIONS; |
51 | 60 | import javax.ws.rs.POST; |
52 | 61 | import javax.ws.rs.PUT; |
| 62 | +import javax.ws.rs.Path; |
53 | 63 | import javax.ws.rs.core.MediaType; |
| 64 | +import javax.ws.rs.core.Response; |
54 | 65 | import java.lang.annotation.Annotation; |
55 | 66 | import java.lang.reflect.Method; |
56 | 67 | import java.math.BigDecimal; |
@@ -465,6 +476,35 @@ public void testSubResourceHasTheRightApiPath() { |
465 | 476 |
|
466 | 477 | } |
467 | 478 |
|
| 479 | + @Test(description = "Test Response Example") |
| 480 | + public void testResponseExample() { |
| 481 | + Swagger swagger = getSwagger(ResponseExampleResource.class); |
| 482 | + assertNotNull(swagger); |
| 483 | + assertNotNull(swagger.getPath("/v1/example")); |
| 484 | + assertEquals(swagger.getPaths().size(), 1); |
| 485 | + assertTrue(swagger.getPath("/v1/example").getGet().getResponses().get("200").getExamples().get("application/json") instanceof JsonNode); |
| 486 | + |
| 487 | + } |
| 488 | + |
| 489 | + @Api |
| 490 | + @Path("/v1") |
| 491 | + public class ResponseExampleResource { |
| 492 | + @Path("example") |
| 493 | + @ApiOperation(value = "aa") |
| 494 | + @ApiResponses({ |
| 495 | + @ApiResponse(code = 200, message = "test", response = Pet.class, |
| 496 | + examples = @Example(value = |
| 497 | + { |
| 498 | + @ExampleProperty(mediaType = "application/json", value = "{\"id\" : 1, \"name\" : \"test\"}") |
| 499 | + } |
| 500 | + )) |
| 501 | + }) |
| 502 | + @GET |
| 503 | + public Response getResource() { |
| 504 | + return null; |
| 505 | + } |
| 506 | + } |
| 507 | + |
468 | 508 | @Test(description = "Resolve Model with XML Properties starting with is prefix per #2635") |
469 | 509 | public void testModelResolverXMLPropertiesName() { |
470 | 510 | final MyClass myClass = new MyClass(); |
|
0 commit comments