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);
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class ReaderTest method scanImplicitParamOverriddenMethodTest.
@Test(description = "scan indirect implicit params from overridden method")
public void scanImplicitParamOverriddenMethodTest() {
final Swagger swagger = new Reader(new Swagger()).read(IndirectImplicitParamsImpl.class);
assertNotNull(swagger);
assertEquals(swagger.getPath("/v1/users").getPost().getParameters().size(), 2);
}
use of io.swagger.models.Swagger in project swagger-core by swagger-api.
the class ReaderTest method scanExternalDocsOnMethod.
@Test(description = "scan external docs on method")
public void scanExternalDocsOnMethod() {
Swagger swagger = getSwagger(ResourceWithExternalDocs.class);
ExternalDocs externalDocsForGet = swagger.getPath("/testString").getGet().getExternalDocs();
assertNull(externalDocsForGet);
ExternalDocs externalDocsForPost = swagger.getPath("/testString").getPost().getExternalDocs();
assertNotNull(externalDocsForPost);
assertEquals("Test Description", externalDocsForPost.getDescription());
assertEquals("https://swagger.io/", externalDocsForPost.getUrl());
}
Aggregations