/** * Copyright (c) 2018-2028, lengleng (wangiegie@gmail.com). *

* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *

* http://www.gnu.org/licenses/lgpl.html *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springblade.core.swagger; import com.google.common.base.Function; import com.google.common.base.Optional; import springfox.documentation.RequestHandler; import java.util.List; import java.util.function.Predicate; /** * Swagger工具类 * * @author Chill */ public class SwaggerUtil { /** * 获取包集合 * * @param basePackages 多个包名集合 */ public static Predicate basePackages(final List basePackages) { return input -> declaringClass(input).transform(handlerPackage(basePackages)).or(true); } private static Function, Boolean> handlerPackage(final List basePackages) { return input -> { // 循环判断匹配 for (String strPackage : basePackages) { boolean isMatch = input.getPackage().getName().startsWith(strPackage); if (isMatch) { return true; } } return false; }; } private static Optional> declaringClass(RequestHandler input) { return Optional.fromNullable(input.declaringClass()); } }