springdoc / springdoc-openapi-gradle-plugin

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
145 stars 45 forks source link

Add TrustStore Support for Fetching OpenAPI via HTTPS with Self-Signed Certificates #136

Closed JiangHongTiao closed 2 months ago

JiangHongTiao commented 9 months ago

This Pull Request introduces enhancements to the plugin to support using a custom TrustStore. This feature is crucial for fetching OpenAPI documentation over HTTPS in environments that utilize self-signed certificates, especially in local development setups.

Changes Made

Motivation

In our current setup, fetching OpenAPI documentation over HTTPS fails due to untrusted self-signed certificates. By enabling TrustStore configuration, developers can easily add their self-signed certificates to the TrustStore, circumventing the SSL handshake issue.

Testing

Usage

Set the new properties in the application's configuration to point to the custom TrustStore and its password:

openApi {
    apiDocsUrl.set("https://localhost:9000/api/docs")
    outputDir.set(file("$buildDir/docs"))
    outputFileName.set("swagger.json")
    waitTimeInSeconds.set(10)
    trustStore.set("keystore/truststore.p12")
    trustStorePassword.set("changeit".toCharArray())
    groupedApiMappings.set(
        ["https://localhost:8080/v3/api-docs/groupA" to "swagger-groupA.json",
            "https://localhost:8080/v3/api-docs/groupB" to "swagger-groupB.json"]
    )
    customBootRun {
        args.set(["--spring.profiles.active=special"])
    }
}

Request for Review

I kindly request a thorough review of these changes, focusing particularly on the SSL context modifications and the implementation of the new properties. Any feedback or suggestions to further optimize this feature are welcome.

fixes #135

bnasslahsen commented 2 months ago

@JiangHongTiao,

Thank you for your contribution to the project. Will be merged soon.