use of io.swagger.config.SwaggerConfig in project swagger-core by swagger-api.
the class SwaggerConfigLocatorTest method putConfigFirstTime.
@Test(description = "should add given config to map ")
public void putConfigFirstTime() {
SwaggerConfig config = new SwaggerConfig() {
@Override
public Swagger configure(Swagger swagger) {
return swagger;
}
@Override
public String getFilterClass() {
return null;
}
};
SwaggerConfigLocator.getInstance().putConfig(id, config);
assertEquals(SwaggerConfigLocator.getInstance().getConfig(id), config);
}
use of io.swagger.config.SwaggerConfig in project swagger-core by swagger-api.
the class SwaggerConfigLocatorTest method putConfigSecondTime.
@Test(description = "shouldn't add given config to map because already set")
public void putConfigSecondTime() {
putConfigFirstTime();
SwaggerConfig config = new SwaggerConfig() {
@Override
public Swagger configure(Swagger swagger) {
return swagger;
}
@Override
public String getFilterClass() {
return null;
}
};
SwaggerConfigLocator.getInstance().putConfig(id, config);
assertNotEquals(SwaggerConfigLocator.getInstance().getConfig(id), config);
}
use of io.swagger.config.SwaggerConfig in project swagger-core by swagger-api.
the class SwaggerContextService method initConfig.
public SwaggerContextService initConfig(Swagger swagger) {
String configIdKey;
if (configId != null) {
configIdKey = CONFIG_ID_PREFIX + configId;
} else if (contextId != null) {
configIdKey = CONFIG_ID_PREFIX + contextId;
} else {
if (isServletConfigAvailable(sc)) {
configIdKey = (sc.getInitParameter(CONFIG_ID_KEY) != null) ? CONFIG_ID_PREFIX + sc.getInitParameter(CONFIG_ID_KEY) : null;
if (configIdKey == null) {
boolean usePathBasedConfig = Boolean.valueOf(sc.getInitParameter(USE_PATH_BASED_CONFIG));
if (usePathBasedConfig && StringUtils.isNotBlank(basePath)) {
configIdKey = CONFIG_ID_PREFIX + basePath;
} else {
configIdKey = (sc.getInitParameter(CONTEXT_ID_KEY) != null) ? CONFIG_ID_PREFIX + sc.getInitParameter(CONTEXT_ID_KEY) : CONFIG_ID_DEFAULT;
}
}
} else {
if (isUsePathBasedConfig() && StringUtils.isNotBlank(basePath)) {
configIdKey = CONFIG_ID_PREFIX + basePath;
} else {
configIdKey = CONFIG_ID_DEFAULT;
}
}
}
SwaggerConfig value = (swaggerConfig != null) ? swaggerConfig : null;
if (value == null && isServletConfigAvailable(sc)) {
value = new WebXMLReader(sc);
}
if (value != null) {
SwaggerConfigLocator.getInstance().putConfig(configIdKey, value);
}
if (swagger != null) {
SwaggerConfigLocator.getInstance().putSwagger(configIdKey, swagger);
}
return this;
}
use of io.swagger.config.SwaggerConfig 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.config.SwaggerConfig in project swagger-core by swagger-api.
the class ApiListingJSON method scan.
protected synchronized void scan(Application app) {
Scanner scanner = ScannerFactory.getScanner();
LOGGER.debug("using scanner " + scanner);
if (scanner != null) {
SwaggerSerializers.setPrettyPrint(scanner.getPrettyPrint());
Set<Class<?>> classes = null;
classes = scanner.classes();
if (classes != null) {
Reader reader = new Reader(swagger);
swagger = reader.read(classes);
if (scanner instanceof SwaggerConfig) {
swagger = ((SwaggerConfig) scanner).configure(swagger);
}
}
}
initialized = true;
}
Aggregations