• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

springdoc/springdoc-openapi-gradle-plugin: Library for OpenAPI 3 with spring-boo ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

springdoc/springdoc-openapi-gradle-plugin

开源软件地址(OpenSource Url):

https://github.com/springdoc/springdoc-openapi-gradle-plugin

开源编程语言(OpenSource Language):

Kotlin 85.5%

开源软件介绍(OpenSource Introduction):

Build Status Quality Gate

Introducing springdoc-openapi-gradle-plugin

Gradle plugin for springdoc-openapi.

This plugin allows you to generate an OpenAPI 3 specification for a Spring Boot application from a Gradle build. Compatibility Notes

The plugin is built on Gradle version 7.0.

Dependencies

This plugin has a runtime dependency on the following plugins:

  1. Spring Boot Gradle plugin - org.springframework.boot
  2. Gradle process plugin - com.github.psxpaul.execfork

How To Use

Gradle Groovy DSL

plugins {
      id "org.springframework.boot" version "2.3.0.RELEASE"
      id "org.springdoc.openapi-gradle-plugin" version "1.3.4"
}

Gradle Kotlin DSL

plugins {
    id("org.springframework.boot") version "2.3.0.RELEASE"
    id("org.springdoc.openapi-gradle-plugin") version "1.3.4"
}

Note: For latest versions of the plugins please check the Gradle Plugins portal.

How the plugin works?

When you add this plugin and its runtime dependency plugins to your build file, the plugin creates the following tasks:

  1. forkedSpringBootRun

  2. generateOpenApiDocs

Running the task generateOpenApiDocs writes the OpenAPI spec into a openapi.json file in your project's build dir.

gradle clean generateOpenApiDocs

When you run the gradle task generateOpenApiDocs, it starts your spring boot application in the background using forkedSpringBootRun task. Once your application is up and running generateOpenApiDocs makes a rest call to your applications doc url to download and store the open api docs file as json.

Customization

The following customizations can be done on task generateOpenApiDocs using extension openApi as follows

openApi {
    apiDocsUrl.set("https://localhost:9000/api/docs")
    outputDir.set(file("$buildDir/docs"))
    outputFileName.set("swagger.json")
    waitTimeInSeconds.set(10)
    forkProperties.set("-Dspring.profiles.active=special")
    groupedApiMappings.set(["https://localhost:8080/v3/api-docs/groupA" to "swagger-groupA.json",
                            "https://localhost:8080/v3/api-docs/groupB" to "swagger-groupB.json"])
}
Parameter Description Required Default
apiDocsUrl The URL from where the OpenAPI doc can be downloaded No http://localhost:8080/v3/api-docs
outputDir The output directory for the generated OpenAPI file No $buildDir - Your project's build dir
outputFileName The name of the output file with extension No openapi.json
waitTimeInSeconds Time to wait in seconds for your Spring Boot application to start, before we make calls to apiDocsUrl to download the OpenAPI doc No 30 seconds
forkProperties Any system property that you would normal need to start your spring boot application. Can either be a static string or a java Properties object No ""
groupedApiMappings A map of URLs (from where the OpenAPI docs can be downloaded) to output file names No []

Fork properties examples

Fork properties allows you to send in anything that might be necessary to allow for the forked spring boot application that gets started to be able to start (profiles, other custom properties, etc etc)

Static string

openApi {
	forkProperties = "-Dspring.profiles.active=special -DstringPassedInForkProperites=true"
}

Passing straight from gradle

This allows for you to be able to just send in whatever you need when you generate docs.

./gradlew clean generateOpenApiDocs -Dspring.profiles.active=special

and as long as the config looks as follows that value will be passed into the forked spring boot application.

openApi {
	forkProperties = System.properties
}

Grouped API Mappings Notes

The groupedApiMappings customization allows you to specify multiple URLs/file names for use within this plugin. This configures the plugin to ignore the apiDocsUrl and outputFileName parameters and only use those found in groupedApiMappings. The plugin will then attempt to download each OpenAPI doc in turn as it would for a single OpenAPI doc.

Building the plugin

  1. Clone the repo [email protected]:springdoc/springdoc-openapi-gradle-plugin.git
  2. Build and publish the plugin into your local maven repository by running the following
    ./gradlew clean pTML
    

Testing the plugin

  1. Create a new spring boot application or use an existing spring boot app and follow the How To Use section above to configure this plugin.

  2. Update the version for the plugin to match the current version found in build.gradle.kts

    id("org.springdoc.openapi-gradle-plugin") version "1.3.4"
    
  3. Add the following to the spring boot apps settings.gradle

    pluginManagement {
        repositories {
            mavenLocal()
            gradlePluginPortal()
        }
    }
    

Thank you for the support

  • Thanks a lot JetBrains for supporting springdoc-openapi project.

JenBrains logo




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap