use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testRequestBodyWithRef.
@Test(description = "RequestBody with ref")
public void testRequestBodyWithRef() {
Components components = new Components();
components.addRequestBodies("User", new RequestBody().description("Test RequestBody"));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(RefRequestBodyResource.class);
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /:\n" + " get:\n" + " summary: Simple get operation\n" + " description: Defines a simple get operation with a payload complex input object\n" + " operationId: sendPayload\n" + " requestBody:\n" + " $ref: '#/components/requestBodies/User'\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + " deprecated: true\n" + "components:\n" + " schemas:\n" + " User:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " username:\n" + " type: string\n" + " firstName:\n" + " type: string\n" + " lastName:\n" + " type: string\n" + " email:\n" + " type: string\n" + " password:\n" + " type: string\n" + " phone:\n" + " type: string\n" + " userStatus:\n" + " type: integer\n" + " description: User Status\n" + " format: int32\n" + " xml:\n" + " name: User\n" + " requestBodies:\n" + " User:\n" + " description: Test RequestBody\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testResponseReturnType.
@Test(description = "Responses schema resolved from return type")
public void testResponseReturnType() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(ResponseReturnTypeResource.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /sample/{id}:\n" + " get:\n" + " summary: Find by id\n" + " description: Find by id operation\n" + " operationId: find\n" + " parameters:\n" + " - name: id\n" + " in: path\n" + " description: ID\n" + " required: true\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " responses:\n" + " \"200\":\n" + " description: Ok\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/TestDTO'\n" + " \"201\":\n" + " description: \"201\"\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/TestDTO'\n" + " \"204\":\n" + " description: No Content\n" + " content:\n" + " application/json: {}\n" + " /sample/{id}/default:\n" + " get:\n" + " summary: Find by id (default)\n" + " description: Find by id operation (default)\n" + " operationId: findDefault\n" + " parameters:\n" + " - name: id\n" + " in: path\n" + " description: ID\n" + " required: true\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/TestDTO'\n" + "components:\n" + " schemas:\n" + " TestDTO:\n" + " type: object\n" + " properties:\n" + " foo:\n" + " type: string";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testTicket3015.
@Test
public void testTicket3015() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Ticket3015Resource.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /test/test:\n" + " get:\n" + " operationId: schemaImpl\n" + " responses:\n" + " \"200\":\n" + " description: OK\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: string\n" + " format: uri\n" + " \"400\":\n" + " description: Bad Request\n" + " \"500\":\n" + " description: Internal Server Error\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
PrimitiveType.customExcludedClasses().add(URI.class.getName());
openAPI = reader.read(Ticket3015Resource.class);
yaml = "openapi: 3.0.1\n" + "paths:\n" + " /test/test:\n" + " get:\n" + " operationId: schemaImpl_1\n" + " responses:\n" + " \"200\":\n" + " description: OK\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " type: object\n" + " properties:\n" + " scheme:\n" + " type: string\n" + " fragment:\n" + " type: string\n" + " authority:\n" + " type: string\n" + " userInfo:\n" + " type: string\n" + " host:\n" + " type: string\n" + " port:\n" + " type: integer\n" + " format: int32\n" + " path:\n" + " type: string\n" + " query:\n" + " type: string\n" + " schemeSpecificPart:\n" + " type: string\n" + " rawSchemeSpecificPart:\n" + " type: string\n" + " rawAuthority:\n" + " type: string\n" + " rawUserInfo:\n" + " type: string\n" + " rawPath:\n" + " type: string\n" + " rawQuery:\n" + " type: string\n" + " rawFragment:\n" + " type: string\n" + " absolute:\n" + " type: boolean\n" + " opaque:\n" + " type: boolean\n" + " \"400\":\n" + " description: Bad Request\n" + " \"500\":\n" + " description: Internal Server Error\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
PrimitiveType.customExcludedClasses().remove(URI.class.getName());
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method test2607.
@Test(description = "test ticket #2607 resource with subresources")
public void test2607() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Test2607.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 2);
PathItem pathItem = paths.get("/swaggertest/name");
assertNotNull(pathItem);
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("text/plain"));
Schema schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
assertNotNull(schema);
assertEquals(schema.getType(), "string");
pathItem = paths.get("/swaggertest/subresource/version");
assertNotNull(pathItem);
operation = pathItem.getGet();
assertNotNull(operation);
assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("text/plain"));
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 ReaderTest method testOperationExtensions.
@Test(description = "OperationExtensions Tests")
public void testOperationExtensions() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(OperationExtensionsResource.class);
assertNotNull(openAPI);
Map<String, Object> extensions = openAPI.getPaths().get("/").getGet().getExtensions();
assertEquals(extensions.size(), 2);
assertNotNull(extensions.get("x-operation"));
assertNotNull(extensions.get("x-operation-extensions"));
}
Aggregations