Search in sources :

Example 56 with Swagger

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("_"));
        }
    }
}
Also used : Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 57 with Swagger

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");
    }
}
Also used : Path(io.swagger.models.Path) Swagger(io.swagger.models.Swagger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) SpecFilter(io.swagger.core.filter.SpecFilter) Test(org.testng.annotations.Test)

Example 58 with Swagger

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);
    }
}
Also used : Swagger(io.swagger.models.Swagger)

Example 59 with Swagger

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"));
}
Also used : Path(io.swagger.models.Path) ResourceWithAnnotations(io.swagger.servlet.resources.ResourceWithAnnotations) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) Test(org.testng.annotations.Test)

Example 60 with Swagger

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");
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Aggregations

Swagger (io.swagger.models.Swagger)184 Test (org.testng.annotations.Test)115 Operation (io.swagger.models.Operation)45 Parameter (io.swagger.models.parameters.Parameter)33 QueryParameter (io.swagger.models.parameters.QueryParameter)33 BodyParameter (io.swagger.models.parameters.BodyParameter)29 Path (io.swagger.models.Path)26 PathParameter (io.swagger.models.parameters.PathParameter)25 Reader (io.swagger.jaxrs.Reader)23 SpecFilter (io.swagger.core.filter.SpecFilter)21 Test (org.junit.Test)19 SwaggerParser (io.swagger.parser.SwaggerParser)16 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)16 Response (io.swagger.models.Response)14 SerializableParameter (io.swagger.models.parameters.SerializableParameter)14 HashMap (java.util.HashMap)14 Info (io.swagger.models.Info)12 Map (java.util.Map)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 Model (io.swagger.models.Model)10