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");
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class BeanConfig method scanAndRead.
public void scanAndRead() {
Set<Class<?>> classes = classes();
if (classes != null) {
Swagger swagger = reader.read(classes);
if (StringUtils.isNotBlank(host)) {
swagger.setHost(host);
}
if (StringUtils.isNotBlank(basePath)) {
swagger.setBasePath(basePath);
}
updateInfoFromConfig();
}
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class BaseApiListingResource method process.
protected Swagger process(Application app, ServletContext servletContext, ServletConfig sc, HttpHeaders headers, UriInfo uriInfo) {
SwaggerContextService ctxService = new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo));
Swagger swagger = ctxService.getSwagger();
synchronized (ApiListingResource.class) {
if (SwaggerContextService.isScannerIdInitParamDefined(sc)) {
if (!initializedScanner.containsKey(sc.getServletName() + "_" + SwaggerContextService.getScannerIdFromInitParam(sc))) {
swagger = scan(app, servletContext, sc, uriInfo);
}
} else {
if (SwaggerContextService.isConfigIdInitParamDefined(sc)) {
if (!initializedConfig.containsKey(sc.getServletName() + "_" + SwaggerContextService.getConfigIdFromInitParam(sc))) {
swagger = scan(app, servletContext, sc, uriInfo);
}
} else if (SwaggerContextService.isUsePathBasedConfigInitParamDefined(sc)) {
if (!initializedConfig.containsKey(sc.getServletName() + "_" + ctxService.getBasePath())) {
swagger = scan(app, servletContext, sc, uriInfo);
}
} else if (!initialized) {
swagger = scan(app, servletContext, sc, uriInfo);
}
}
}
if (swagger != null) {
SwaggerSpecFilter filterImpl = FilterFactory.getFilter();
if (filterImpl != null) {
SpecFilter f = new SpecFilter();
swagger = f.filter(swagger, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
}
}
return swagger;
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class JsonIdentityTest method scan.
@Test(description = "Scan API with operation and response references")
public void scan() throws IOException {
final Swagger swagger = new Reader(new Swagger()).read(JsonIdentityResource.class);
final String json = ResourceUtils.loadClassResource(getClass(), "ResourceWithJsonIdentity.json");
SerializationMatchers.assertEqualsToJson(swagger, json);
}
Aggregations