use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testSubResourceHasTheRightApiPath.
@Test(description = "Scan subresource per #2632")
public void testSubResourceHasTheRightApiPath() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(ClassPathParentResource.class);
assertNotNull(openAPI);
assertNotNull(openAPI.getPaths().get("/v1/parent"));
assertNotNull(openAPI.getPaths().get("/v1/parent/{id}"));
assertEquals(openAPI.getPaths().size(), 2);
OpenAPI subResourceApi = new Reader(new OpenAPI()).read(ClassPathSubResource.class);
assertNotNull(subResourceApi);
assertNotNull(subResourceApi.getPaths().get("/subresource"));
assertNotNull(subResourceApi.getPaths().get("/subresource/{id}"));
assertEquals(subResourceApi.getPaths().size(), 2);
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testParameterWithFilter.
@Test(description = "Responses with filter")
public void testParameterWithFilter() {
Components components = new Components();
components.addParameters("id", new Parameter().description("Id Description").schema(new IntegerSchema()).in(ParameterIn.QUERY.toString()).example(1).required(true));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(SimpleParameterResource.class);
OpenAPISpecFilter filterImpl = new RefParameterFilter();
SpecFilter f = new SpecFilter();
openAPI = f.filter(openAPI, filterImpl, null, null, null);
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" + " parameters:\n" + " - $ref: '#/components/parameters/id'\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + " deprecated: true\n" + "components:\n" + " parameters: \n" + " id:\n" + " in: query\n" + " description: Id Description\n" + " required: true\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " example: 1\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testTicket3624.
@Test(description = "Optional handling")
public void testTicket3624() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Service.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /example/model:\n" + " get:\n" + " tags:\n" + " - ExampleService\n" + " summary: ' Retrieve models for display to the user'\n" + " operationId: getModels\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Response'\n" + " /example/model/by/ids:\n" + " get:\n" + " tags:\n" + " - ExampleService\n" + " summary: ' Retrieve models by their ids'\n" + " operationId: getModelsById\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/ByIdResponse'\n" + " /example/containerized/model:\n" + " get:\n" + " tags:\n" + " - ExampleService\n" + " summary: ' Retrieve review insights for a specific product'\n" + " operationId: getContainerizedModels\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/ContainerizedResponse'\n" + "components:\n" + " schemas:\n" + " Model:\n" + " type: object\n" + " properties:\n" + " text:\n" + " type: string\n" + " title:\n" + " type: string\n" + " active:\n" + " type: boolean\n" + " schemaParent:\n" + " $ref: '#/components/schemas/Model'\n" + " optionalString:\n" + " type: string\n" + " parent:\n" + " $ref: '#/components/schemas/Model'\n" + " id:\n" + " type: integer\n" + " format: int32\n" + " Response:\n" + " type: object\n" + " properties:\n" + " count:\n" + " type: integer\n" + " format: int32\n" + " models:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/Model'\n" + " ByIdResponse:\n" + " type: object\n" + " properties:\n" + " modelsById:\n" + " type: object\n" + " additionalProperties:\n" + " $ref: '#/components/schemas/Model'\n" + " ContainerizedResponse:\n" + " type: object\n" + " properties:\n" + " totalCount:\n" + " type: integer\n" + " format: int32\n" + " containerizedModels:\n" + " type: array\n" + " items:\n" + " $ref: '#/components/schemas/ModelContainer'\n" + " ModelContainer:\n" + " type: object\n" + " properties:\n" + " text:\n" + " type: string\n" + " model:\n" + " $ref: '#/components/schemas/Model'\n" + " id:\n" + " type: integer\n" + " format: int32";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testGetServers.
@Test(description = "Get servers")
public void testGetServers() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(ServersResource.class);
Operation operation = openAPI.getPaths().get("/").getGet();
assertNotNull(operation);
assertEquals(5, operation.getServers().size());
assertEquals(operation.getServers().get(0).getUrl(), "http://class1");
assertEquals(operation.getServers().get(1).getUrl(), "http://class2");
assertEquals(operation.getServers().get(2).getUrl(), "http://method1");
assertEquals(operation.getServers().get(3).getUrl(), "http://method2");
assertEquals(operation.getServers().get(4).getUrl(), "http://op1");
assertEquals(operation.getServers().get(0).getVariables().size(), 2);
assertEquals(operation.getServers().get(0).getVariables().get("var1").getDescription(), "var 1");
assertEquals(operation.getServers().get(0).getVariables().get("var1").getEnum().size(), 2);
assertEquals(openAPI.getServers().get(0).getDescription(), "definition server 1");
}
use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.
the class ReaderTest method testRequestBodyWithFilter.
@Test(description = "RequestBody with filter")
public void testRequestBodyWithFilter() {
Components components = new Components();
components.addRequestBodies("User", new RequestBody());
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(SimpleRequestBodyResource.class);
OpenAPISpecFilter filterImpl = new RefRequestBodyFilter();
SpecFilter f = new SpecFilter();
openAPI = f.filter(openAPI, filterImpl, null, null, null);
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";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Aggregations