use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class SpecFilterTest method filterAwayInternalModelProperties.
@Test(description = "it should filter away internal model properties")
public void filterAwayInternalModelProperties() throws IOException {
final Swagger swagger = getSwagger("specFiles/sampleSpec.json");
final InternalModelPropertiesRemoverFilter filter = new InternalModelPropertiesRemoverFilter();
final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
for (Map.Entry<String, Model> entry : filtered.getDefinitions().entrySet()) {
for (String propName : entry.getValue().getProperties().keySet()) {
assertFalse(propName.startsWith("_"));
}
}
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class SpecFilterTest method filterAwayStoreResource.
@Test(description = "it should filter away the store resource")
public void filterAwayStoreResource() throws IOException {
final Swagger swagger = getSwagger("specFiles/petstore.json");
final NoUserOperationsFilter filter = new NoUserOperationsFilter();
final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
if (filtered.getPaths() != null) {
for (Map.Entry<String, Path> entry : filtered.getPaths().entrySet()) {
assertNotEquals(entry.getKey(), "/user");
}
} else {
fail("paths should not be null");
}
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class ApiDeclarationServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final Swagger swagger = (Swagger) getServletContext().getAttribute("swagger");
if (swagger == null) {
response.setStatus(404);
return;
}
final String pathInfo = request.getPathInfo();
if ("/swagger.json".equals(pathInfo)) {
response.getWriter().println(Json.mapper().writeValueAsString(swagger));
} else if ("/swagger.yaml".equals(pathInfo)) {
response.getWriter().println(Yaml.mapper().writeValueAsString(swagger));
} else {
response.setStatus(404);
}
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class ReaderTest method readerTest1.
@Test
public void readerTest1() {
final Swagger swagger = new Swagger();
Reader.read(swagger, Collections.<Class<?>>singleton(ResourceWithAnnotations.class));
Assert.assertNotNull(swagger);
final Info info = swagger.getInfo();
Assert.assertNotNull(info);
Assert.assertEquals(info.getTitle(), "Test title");
Assert.assertEquals(info.getDescription(), "Test description");
Assert.assertEquals(info.getVersion(), "1.0.0");
Assert.assertEquals(info.getTermsOfService(), "link_to_terms");
Assert.assertEquals(info.getContact().getName(), "Author");
Assert.assertEquals(info.getContact().getEmail(), "author@mail");
Assert.assertEquals(info.getContact().getUrl(), "site");
Assert.assertEquals(info.getLicense().getName(), "License");
Assert.assertEquals(info.getLicense().getUrl(), "license_url");
Assert.assertEquals(info.getVendorExtensions().get("x-ext1_prop1"), "ext1_val1");
Assert.assertEquals(info.getVendorExtensions().get("x-ext1_prop2"), "x-ext1_val2");
Assert.assertEquals(swagger.getHost(), "host");
Assert.assertEquals(swagger.getBasePath(), "/api");
Assert.assertNotNull(swagger.getPath("/resources/testMethod3"));
Assert.assertNotNull(swagger.getDefinitions().get("SampleData"));
Assert.assertEquals(swagger.getExternalDocs().getDescription(), "docs");
Assert.assertEquals(swagger.getExternalDocs().getUrl(), "url_to_docs");
Path path = swagger.getPath("/resources/testMethod3");
Assert.assertNotNull(path);
Operation get = path.getGet();
Assert.assertNotNull(get);
Assert.assertEquals("value", get.getVendorExtensions().get("x-name"));
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class ApiListingJSONTest method initializeTest.
@Test(description = "test Swagger initialization from BeanConfig")
public void initializeTest() {
final BeanConfig bc = new BeanConfig();
bc.setTitle("Petstore Sample API");
bc.setHost("petstore.swagger.io");
bc.setBasePath("/api");
bc.setScan(true);
final ApiListingJSON listing = new ApiListingJSON();
// Initializing by Swagger object
ApiListingJSON.init(new Swagger());
// Reading configuration and scanning resources
listing.scan(null);
final Swagger sw = ApiListingJSON.swagger;
Assert.assertNotNull(sw);
Assert.assertEquals(sw.getInfo().getTitle(), "Petstore Sample API");
Assert.assertEquals(sw.getHost(), "petstore.swagger.io");
Assert.assertEquals(sw.getBasePath(), "/api");
}
Aggregations