springdoc-openapi-gradle-plugin icon indicating copy to clipboard operation
springdoc-openapi-gradle-plugin copied to clipboard

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

Open JiangHongTiao opened this issue 2 years ago • 0 comments

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

  • TrustStore Configuration: Added properties trustStore and trustStorePassword to allow specifying a custom TrustStore.

  • SSL Context Adjustment: Modified the SSL context setup within the plugin to include the TrustStore, ensuring self-signed certificates are trusted during SSL handshakes. When TrustStore is not provided default SSL context is used.

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

  • Tested fetching OpenAPI documentation in a local environment with a self-signed certificate, ensuring no SSL handshake errors occurred.
  • Verified backward compatibility and that the changes do not affect existing functionalities.
  • A new test case that validates the functionality of OpenAPI fetch using the TrustStore.

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

JiangHongTiao avatar Nov 28 '23 21:11 JiangHongTiao