use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testSimpleReadClass.
@Test(description = "test a simple resource class")
public void testSimpleReadClass() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(BasicFieldsResource.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 6);
PathItem pathItem = paths.get(PATH_1_REF);
assertNotNull(pathItem);
assertNull(pathItem.getPost());
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertEquals(OPERATION_SUMMARY, operation.getSummary());
assertEquals(OPERATION_DESCRIPTION, operation.getDescription());
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testResourceWithClassBasedSubresources.
@Test(description = "scan resource with class-based sub-resources")
public void testResourceWithClassBasedSubresources() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(SubResourceHead.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 3);
PathItem pathItem = paths.get("/head/tail/hello");
assertNotNull(pathItem);
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("*/*"));
Schema schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
pathItem = paths.get("/head/tail/{string}");
assertNotNull(pathItem);
operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("*/*"));
schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
pathItem = paths.get("/head/noPath");
assertNotNull(pathItem);
operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("*/*"));
schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class RequestBodyTest method testRequestBodyAnnotationPriority.
@Test(description = "scan class with requesbody annotation")
public void testRequestBodyAnnotationPriority() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(RequestBodyResource.class);
PathItem userPathItem = openAPI.getPaths().get(USER_PATH);
io.swagger.v3.oas.models.parameters.RequestBody getRequestBody = userPathItem.getGet().getRequestBody();
assertNotNull(getRequestBody);
assertEquals(getRequestBody.getDescription(), REQUEST_BODY_IN_ANNOTATION);
io.swagger.v3.oas.models.parameters.RequestBody postRequestBody = userPathItem.getPost().getRequestBody();
assertNotNull(postRequestBody);
assertEquals(postRequestBody.getDescription(), REQUEST_BODY_IN_ANNOTATION);
io.swagger.v3.oas.models.parameters.RequestBody putRequestBody = userPathItem.getPut().getRequestBody();
assertNotNull(putRequestBody);
assertEquals(putRequestBody.getDescription(), REQUEST_BODY_IN_METHOD);
io.swagger.v3.oas.models.parameters.RequestBody deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_METHOD);
io.swagger.v3.oas.models.parameters.RequestBody patchRequestBody = userPathItem.getPatch().getRequestBody();
assertNotNull(patchRequestBody);
assertEquals(patchRequestBody.getDescription(), REQUEST_BODY_IN_METHOD);
userPathItem = openAPI.getPaths().get(USER_PATH + "/deleteUserMethod_Param_RequestBody");
deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_PARAMETER);
userPathItem = openAPI.getPaths().get(USER_PATH + "/deleteUserOperation_Method_Param_RequestBody");
deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_PARAMETER);
userPathItem = openAPI.getPaths().get(USER_PATH + "/deleteUserOperation_RequestBody");
deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_PARAMETER);
userPathItem = openAPI.getPaths().get(USER_PATH + "/deleteUserOperation_Method_Param");
deleteRequestBody = userPathItem.getDelete().getRequestBody();
assertNotNull(deleteRequestBody);
assertEquals(deleteRequestBody.getDescription(), REQUEST_BODY_IN_METHOD);
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class FormParamBeanTest method shouldSerializeTypeParameter.
@Test(description = "check schema of serialized BeanParam containing FormParams")
public void shouldSerializeTypeParameter() {
OpenAPI openApi = new Reader(new OpenAPI()).read(MyFormBeanParamResource.class);
RequestBody requestBody = openApi.getPaths().get("/").getGet().getRequestBody();
Assert.assertNotNull(requestBody);
MediaType mediaType = requestBody.getContent().get("application/x-www-form-urlencoded");
Assert.assertNotNull(mediaType);
Schema schema = mediaType.getSchema();
Assert.assertEquals(schema.getProperties().size(), 2);
Assert.assertEquals(schema.getProperties().get("param1"), new StringSchema());
Assert.assertEquals(schema.getProperties().get("param2"), new StringSchema());
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testTicket3731.
@Test(description = "Constraints annotations in models")
public void testTicket3731() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Ticket3731Resource.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /test/cart:\n" + " get:\n" + " summary: Get cart items\n" + " description: Paging follows RFC 5005.\n" + " operationId: getCart\n" + " parameters:\n" + " - name: pageSize\n" + " in: query\n" + " description: \"Number of items per page. Range[1, 200]\"\n" + " schema:\n" + " maximum: 200\n" + " minimum: 1\n" + " type: integer\n" + " format: int32\n" + " default: 50\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
reader = new Reader(new OpenAPI());
openAPI = reader.read(Ticket3731BisResource.class);
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Aggregations