Giter VIP home page Giter VIP logo

spring-boot-starter-swagger's Introduction

所需要的依赖

	compile('io.springfox:springfox-swagger-ui:2.4.0')
	compile('io.springfox:springfox-swagger2:2.4.0')

配置文件

  • api信息
  • 摘要信息

@Configuration
@EnableSwagger2
public class SwaggerAutoConfiguration {

	/**
	 * api详情
	 * 
	 * @param title
	 * @param description
	 * @param version
	 * @param termsOfServiceUrl
	 * @param contact
	 * @param license
	 * @param licenseUrl
	 * @return
	 */
	@Bean
	public ApiInfo requestApiInfo(@Value("${spring.swagger.apiinfo.title}") String title,
			@Value("${spring.swagger.apiinfo.description}") String description,
			@Value("${spring.swagger.apiinfo.version}") String version,
			@Value("${spring.swagger.apiinfo.termsOfServiceUrl}") String termsOfServiceUrl,
			@Value("${spring.swagger.apiinfo.contact}") String contact,
			@Value("${spring.swagger.apiinfo.license}") String license,
			@Value("${spring.swagger.apiinfo.licenseUrl}") String licenseUrl) {
		return new ApiInfo(title, description, version, termsOfServiceUrl, contact, license, licenseUrl);
	}

	/**
	 * 摘要
	 * 
	 * @param apiInfo
	 * @param groupName
	 * @param pathMapping
	 * @param pathRegex
	 * @return
	 */
	@Bean
	public Docket requestDocket(ApiInfo apiInfo, @Value("${spring.swagger.docket.groupName}") String groupName,
			@Value("${spring.swagger.docket.pathMapping}") String pathMapping,
			@Value("${spring.swagger.docket.pathRegex}") String pathRegex) {

		return new Docket(DocumentationType.SWAGGER_2).groupName(groupName).useDefaultResponseMessages(false)
				.forCodeGeneration(true).pathMapping(pathMapping).select().paths(regex(pathRegex)).build()
				.apiInfo(apiInfo);
	}
}

在application.yml中配置相关的信息

spring:
  swagger:
    apiinfo:
       title: Spring Boot 测试
       version: 1.0
       description: Spring Boot 测试
       termsOfServiceUrl: www.dingdongcloud.com
       contact: 杭州云贝网络科技有限公司
       license: 云贝
       licenseUrl: www.dingdongcloud.com  
    docket:
       groupName: test
       pathMapping: /
       pathRegex: /.*

spring-boot-starter-swagger's People

Contributors

minlingchao1 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.