use of io.swagger.jaxrs.Reader in project webcert by sklintyg.
the class ApiScanner method scan.
private synchronized Swagger scan(Application app, ServletConfig sc, String api) {
Swagger swagger = null;
ReflectiveJaxrsScanner scanner = new ReflectiveJaxrsScanner();
scanner.setResourcePackage(BASE_REST_PACKAGE_NAME + api);
scanner.setPrettyPrint(true);
SwaggerSerializers.setPrettyPrint(scanner.getPrettyPrint());
Set<Class<?>> classes = resolveClasses(app, sc, scanner);
if (classes != null) {
Reader reader = new Reader(null, ReaderConfigUtils.getReaderConfig(context));
swagger = reader.read(classes);
swagger.setBasePath(resolveBasePathForApi(api));
swagger = scanner.configure(swagger);
context.setAttribute(SWAGGER_TOKEN + api, swagger);
apiInitialized.put(SWAGGER_TOKEN + api, Boolean.TRUE);
}
return swagger;
}
use of io.swagger.jaxrs.Reader in project swagger-core by swagger-api.
the class BaseApiListingResource method scan.
private static synchronized Swagger scan(Application app, ServletContext context, ServletConfig sc, UriInfo uriInfo) {
Swagger swagger = null;
SwaggerContextService ctxService = new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo));
Scanner scanner = ctxService.getScanner();
if (scanner != null) {
SwaggerSerializers.setPrettyPrint(scanner.getPrettyPrint());
swagger = new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo)).getSwagger();
Set<Class<?>> classes;
if (scanner instanceof JaxrsScanner) {
JaxrsScanner jaxrsScanner = (JaxrsScanner) scanner;
classes = jaxrsScanner.classesFromContext(app, sc);
} else {
classes = scanner.classes();
}
if (classes != null) {
Reader reader = new Reader(swagger, ReaderConfigUtils.getReaderConfig(context));
swagger = reader.read(classes);
if (scanner instanceof SwaggerConfig) {
swagger = ((SwaggerConfig) scanner).configure(swagger);
} else {
SwaggerConfig swaggerConfig = ctxService.getConfig();
if (swaggerConfig != null) {
LOGGER.debug("configuring swagger with " + swaggerConfig);
swaggerConfig.configure(swagger);
} else {
LOGGER.debug("no configurator");
}
}
new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo)).updateSwagger(swagger);
}
}
if (SwaggerContextService.isScannerIdInitParamDefined(sc)) {
initializedScanner.put(sc.getServletName() + "_" + SwaggerContextService.getScannerIdFromInitParam(sc), true);
} else if (SwaggerContextService.isConfigIdInitParamDefined(sc)) {
initializedConfig.put(sc.getServletName() + "_" + SwaggerContextService.getConfigIdFromInitParam(sc), true);
} else if (SwaggerContextService.isUsePathBasedConfigInitParamDefined(sc)) {
initializedConfig.put(sc.getServletName() + "_" + ctxService.getBasePath(), true);
} else {
initialized = true;
}
return swagger;
}
use of io.swagger.jaxrs.Reader in project swagger-core by swagger-api.
the class SimpleReaderTest method scanSimpleResourceWithoutAnnotations.
@Test(description = "scan a simple resource without annotations")
public void scanSimpleResourceWithoutAnnotations() {
DefaultReaderConfig config = new DefaultReaderConfig();
config.setScanAllResources(true);
Swagger swagger = new Reader(new Swagger(), config).read(SimpleResourceWithoutAnnotations.class);
assertEquals(swagger.getPaths().size(), 2);
Operation get = getGet(swagger, "/{id}");
assertNotNull(get);
assertEquals(get.getParameters().size(), 2);
PathParameter param1 = (PathParameter) get.getParameters().get(0);
assertEquals(param1.getIn(), "path");
assertEquals(param1.getName(), "id");
assertTrue(param1.getRequired());
assertNull(param1.getDescription());
assertEquals(param1.getDefaultValue(), "5");
Parameter param2 = get.getParameters().get(1);
assertEquals(param2.getIn(), "query");
assertEquals(param2.getName(), "limit");
assertFalse(param2.getRequired());
assertNull(param2.getDescription());
}
use of io.swagger.jaxrs.Reader in project swagger-core by swagger-api.
the class ReferenceTest method scanAPI.
@Test(description = "Scan API with operation and response references")
public void scanAPI() throws IOException {
final Swagger swagger = new Reader(new Swagger()).read(ResourceWithReferences.class);
final String json = ResourceUtils.loadClassResource(getClass(), "ResourceWithReferences.json");
SerializationMatchers.assertEqualsToJson(swagger, json);
}
use of io.swagger.jaxrs.Reader in project swagger-core by swagger-api.
the class RegexPathParamTest method scanSimpleResource.
@Test(description = "scan a simple resource")
public void scanSimpleResource() {
Swagger swagger = new Reader(new Swagger()).read(RegexPathParamResource.class);
Operation get = swagger.getPaths().get("/{report_type}").getGet();
Parameter param = get.getParameters().get(0);
assertEquals(param.getName(), "report_type");
assertEquals(param.getPattern(), "[aA-zZ]+");
}
Aggregations