关闭spirng boot集成springdoc-openapi的接口文档

springdoc-openapi依赖包

xml 复制代码
<dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
            <version>2.1.0</version>
        </dependency>

关闭方式

yml 复制代码
# 配置文件中添加如下配置
springdoc:
  swagger-ui:
    enabled: false

关键部分代码分析

java 复制代码
	/*
 *
 *  *
 *  *  *
 *  *  *  *
 *  *  *  *  * Copyright 2019-2022 the original author or authors.
 *  *  *  *  *
 *  *  *  *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  *  *  *  * you may not use this file except in compliance with the License.
 *  *  *  *  * You may obtain a copy of the License at
 *  *  *  *  *
 *  *  *  *  *      https://www.apache.org/licenses/LICENSE-2.0
 *  *  *  *  *
 *  *  *  *  * 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.springdoc.core.properties;

import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.springdoc.core.configuration.SpringDocConfiguration;
import org.springdoc.core.utils.Constants;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import static org.springdoc.core.utils.Constants.SPRINGDOC_SWAGGER_UI_ENABLED;


/**
 * The type Swagger ui config properties.
 * @author bnasslahsen
 */
@Lazy(false)
@Configuration(proxyBeanMethods = false)
@ConfigurationProperties(prefix = "springdoc.swagger-ui")
@ConditionalOnProperty(name = SPRINGDOC_SWAGGER_UI_ENABLED, matchIfMissing = true)
@ConditionalOnBean(SpringDocConfiguration.class)
public class SwaggerUiConfigProperties extends AbstractSwaggerUiConfigProperties {

	/**
	 * The Disable swagger default url.
	 */
	private boolean disableSwaggerDefaultUrl;


	/**
	 * The Swagger ui version.
	 */
	private String version;

	/**
	 * The Csrf configuration.
	 */
	private Csrf csrf = new Csrf();

	/**
	 * The Syntax Highlight configuration.
	 */
	private SyntaxHighlight syntaxHighlight = new SyntaxHighlight();

	/**
	 * Whether to generate and serve an OpenAPI document.
	 */
	private boolean enabled = true;

	/**
	 * The Use root path.
	 */
	private boolean useRootPath;

	/**
	 * Gets swagger ui version.
	 *
	 * @return the swagger ui version
	 */
	public String getVersion() {
		return version;
	}

	/**
	 * Sets swagger ui version.
	 *
	 * @param version the swagger ui version
	 */
	public void setVersion(String version) {
		this.version = version;
	}

	/**
	 * Is use root path boolean.
	 *
	 * @return the boolean
	 */
	public boolean isUseRootPath() {
		return useRootPath;
	}

	/**
	 * Sets use root path.
	 *
	 * @param useRootPath the use root path
	 */
	public void setUseRootPath(boolean useRootPath) {
		this.useRootPath = useRootPath;
	}

	/**
	 * Is enabled boolean.
	 *
	 * @return the boolean
	 */
	public boolean isEnabled() {
		return enabled;
	}

	/**
	 * Sets enabled.
	 *
	 * @param enabled the enabled
	 */
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	/**
	 * Is disable swagger default url boolean.
	 *
	 * @return the boolean
	 */
	public boolean isDisableSwaggerDefaultUrl() {
		return disableSwaggerDefaultUrl;
	}

	/**
	 * Sets disable swagger default url.
	 *
	 * @param disableSwaggerDefaultUrl the disable swagger default url
	 */
	public void setDisableSwaggerDefaultUrl(boolean disableSwaggerDefaultUrl) {
		this.disableSwaggerDefaultUrl = disableSwaggerDefaultUrl;
	}

	/**
	 * Gets csrf.
	 *
	 * @return the csrf
	 */
	public Csrf getCsrf() {
		return csrf;
	}

	/**
	 * Sets csrf.
	 *
	 * @param csrf the csrf
	 */
	public void setCsrf(Csrf csrf) {
		this.csrf = csrf;
	}

	/**
	 * Is csrf enabled boolean.
	 *
	 * @return the boolean
	 */
	public boolean isCsrfEnabled() {
		return csrf.isEnabled();
	}

	/**
	 * Gets syntaxHighlight.
	 *
	 * @return the syntaxHighlight
	 */
	public SyntaxHighlight getSyntaxHighlight() {
		return syntaxHighlight;
	}

	/**
	 * Sets syntaxHighlight.
	 *
	 * @param syntaxHighlight the syntaxHighlight
	 */
	public void setSyntaxHighlight(SyntaxHighlight syntaxHighlight) {
		this.syntaxHighlight = syntaxHighlight;
	}

	/**
	 * Clone urls set.
	 *
	 * @return the set
	 */
	public Set<SwaggerUrl> cloneUrls() {
		return this.urls.stream().map(swaggerUrl -> new SwaggerUrl(swaggerUrl.getName(), swaggerUrl.getUrl(), swaggerUrl.getDisplayName())).collect(Collectors.toSet());
	}

	/**
	 * The type Csrf.
	 * @author bnasslashen
	 */
	public static class Csrf {

		/**
		 * The Enabled.
		 */
		private boolean enabled;

		/**
		 * Use Local storage.
		 */
		private boolean useLocalStorage;

		/**
		 * Use Session storage.
		 */
		private boolean useSessionStorage;

		/**
		 * The Cookie name.
		 */
		private String cookieName = Constants.CSRF_DEFAULT_COOKIE_NAME;

		/**
		 * The Local storage key.
		 */
		private String localStorageKey = Constants.CSRF_DEFAULT_LOCAL_STORAGE_KEY;

		/**
		 * The Session storage key.
		 */
		private String sessionStorageKey = Constants.CSRF_DEFAULT_LOCAL_STORAGE_KEY;

		/**
		 * The Header name.
		 */
		private String headerName = Constants.CSRF_DEFAULT_HEADER_NAME;

		/**
		 * Is enabled boolean.
		 *
		 * @return the boolean
		 */
		public boolean isEnabled() {
			return enabled;
		}

		/**
		 * Sets enabled.
		 *
		 * @param enabled the enabled
		 */
		public void setEnabled(boolean enabled) {
			this.enabled = enabled;
		}

		/**
		 * Use Local storage boolean.
		 *
		 * @return the boolean
		 */
		public boolean isUseLocalStorage() {
			return useLocalStorage;
		}

		/**
		 * Sets useLocalStorage.
		 *
		 * @param useLocalStorage the use local storage
		 */
		public void setUseLocalStorage(boolean useLocalStorage) {
			this.useLocalStorage = useLocalStorage;
		}

		/**
		 * Use Session storage boolean.
		 *
		 * @return the boolean
		 */
		public boolean isUseSessionStorage() {
			return useSessionStorage;
		}

		/**
		 * Sets useSessionStorage.
		 *
		 * @param useSessionStorage the use local storage
		 */
		public void setUseSessionStorage(boolean useSessionStorage) {
			this.useSessionStorage = useSessionStorage;
		}

		/**
		 * Gets cookie name.
		 *
		 * @return the cookie name
		 */
		public String getCookieName() {
			return cookieName;
		}

		/**
		 * Sets cookie name.
		 *
		 * @param cookieName the cookie name
		 */
		public void setCookieName(String cookieName) {
			this.cookieName = cookieName;
		}

		/**
		 * Gets local storage key.
		 *
		 * @return the cookie name
		 */
		public String getLocalStorageKey() {
			return localStorageKey;
		}

		/**
		 * Sets local storage key.
		 *
		 * @param localStorageKey the local storage key
		 */
		public void setLocalStorageKey(String localStorageKey) {
			this.localStorageKey = localStorageKey;
		}

		/**
		 * Gets session storage key.
		 *
		 * @return the cookie name
		 */
		public String getSessionStorageKey() {
			return sessionStorageKey;
		}

		/**
		 * Sets local storage key.
		 *
		 * @param sessionStorageKey the local storage key
		 */
		public void setSessionStorageKey(String sessionStorageKey) {
			this.sessionStorageKey = sessionStorageKey;
		}

		/**
		 * Gets header name.
		 *
		 * @return the header name
		 */
		public String getHeaderName() {
			return headerName;
		}

		/**
		 * Sets header name.
		 *
		 * @param headerName the header name
		 */
		public void setHeaderName(String headerName) {
			this.headerName = headerName;
		}
	}

	/**
	 * The type Syntax highlight.
	 * @author bnasslashen
	 */
	public static class SyntaxHighlight {

		/**
		 * The Activated.
		 */
		private Boolean activated;

		/**
		 * The Theme.
		 */
		private String theme;

		/**
		 * Gets activated.
		 *
		 * @return the activated
		 */
		public Boolean getActivated() {
			return activated;
		}

		/**
		 * Sets activated.
		 *
		 * @param activated the activated
		 */
		public void setActivated(Boolean activated) {
			this.activated = activated;
		}

		/**
		 * Gets theme.
		 *
		 * @return the theme
		 */
		public String getTheme() {
			return theme;
		}

		/**
		 * Sets theme.
		 *
		 * @param theme the theme
		 */
		public void setTheme(String theme) {
			this.theme = theme;
		}

		/**
		 * Is present boolean.
		 *
		 * @return the boolean
		 */
		public boolean isPresent() {
			return activated != null || StringUtils.isNotEmpty(theme);
		}
	}

}
相关推荐
xlsw_2 小时前
java全栈day20--Web后端实战(Mybatis基础2)
java·开发语言·mybatis
神仙别闹3 小时前
基于java的改良版超级玛丽小游戏
java
黄油饼卷咖喱鸡就味增汤拌孜然羊肉炒饭3 小时前
SpringBoot如何实现缓存预热?
java·spring boot·spring·缓存·程序员
暮湫3 小时前
泛型(2)
java
超爱吃士力架3 小时前
邀请逻辑
java·linux·后端
南宫生4 小时前
力扣-图论-17【算法学习day.67】
java·学习·算法·leetcode·图论
转码的小石4 小时前
12/21java基础
java
李小白664 小时前
Spring MVC(上)
java·spring·mvc
GoodStudyAndDayDayUp4 小时前
IDEA能够从mapper跳转到xml的插件
xml·java·intellij-idea
装不满的克莱因瓶5 小时前
【Redis经典面试题六】Redis的持久化机制是怎样的?
java·数据库·redis·持久化·aof·rdb