Add option to skip merging spec files (#19396)

Introduced a new property `inputSpecRootDirectorySkipMerge` to conditionally skip the merging step of the specification files. Updated the logic to honor this new property, ensuring merging only occurs if it is explicitly not skipped. Enabled configuration via Gradle build file.
This commit is contained in:
Erik VanderWerf 2025-02-19 01:28:03 -08:00 committed by GitHub
parent 890c37fd77
commit 9374dbd030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 5 deletions

View File

@ -98,6 +98,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
outputDir.set(generate.outputDir)
inputSpec.set(generate.inputSpec)
inputSpecRootDirectory.set(generate.inputSpecRootDirectory)
inputSpecRootDirectorySkipMerge.set(generate.inputSpecRootDirectorySkipMerge)
remoteInputSpec.set(generate.remoteInputSpec)
templateDir.set(generate.templateDir)
templateResourcePath.set(generate.templateResourcePath)

View File

@ -51,14 +51,28 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
/**
* The Open API 2.0/3.x specification location.
*
* Be default, Gradle will treat the openApiGenerate task as up-to-date based only on this file, regardless of
* changes to any $ref referenced files. Use the `inputSpecRootDirectory` property to have Gradle track changes to
* an entire directory of spec files.
*/
val inputSpec = project.objects.property<String>()
/**
* Local root folder with spec files
* Local root folder with spec files.
*
* By default, a merged spec file will be generated based on the contents of the directory. To disable this, set the
* `inputSpecRootDirectorySkipMerge` property.
*/
val inputSpecRootDirectory = project.objects.property<String>()
/**
* Skip bundling all spec files into a merged spec file, if true.
*
* Default false.
*/
val inputSpecRootDirectorySkipMerge = project.objects.property<Boolean>()
/**
* The remote Open API 2.0/3.x specification URL location.
*/
@ -400,6 +414,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
@Suppress("MemberVisibilityCanBePrivate")
fun applyDefaults() {
releaseNote.set("Minor update")
inputSpecRootDirectorySkipMerge.set(false)
modelNamePrefix.set("")
modelNameSuffix.set("")
apiNameSuffix.set("")

View File

@ -106,6 +106,10 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
/**
* The Open API 2.0/3.x specification location.
*
* Be default, Gradle will treat the openApiGenerate task as up-to-date based only on this file, regardless of
* changes to any $ref referenced files. Use the `inputSpecRootDirectory` property to have Gradle track changes to
* an entire directory of spec files.
*/
@Optional
@get:InputFile
@ -113,13 +117,23 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
val inputSpec = project.objects.property<String>()
/**
* Local root folder with spec files
* Local root folder with spec files.
*
* By default, a merged spec file will be generated based on the contents of the directory. To disable this, set the
* `inputSpecRootDirectorySkipMerge` property.
*/
@Optional
@get:InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
val inputSpecRootDirectory = project.objects.property<String>();
/**
* Skip bundling all spec files into a merged spec file, if true.
*/
@Input
@Optional
val inputSpecRootDirectorySkipMerge = project.objects.property<Boolean>()
/**
* Name of the file that will contain all merged specs
*/
@ -625,9 +639,16 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
}
inputSpecRootDirectory.ifNotEmpty { inputSpecRootDirectoryValue ->
run {
resolvedInputSpec = MergedSpecBuilder(inputSpecRootDirectoryValue, mergedFileName.getOrElse("merged")).buildMergedSpec()
logger.info("Merge input spec would be used - {}", resolvedInputSpec)
val skipMerge = inputSpecRootDirectorySkipMerge.get()
val runMergeSpec = !skipMerge
if (runMergeSpec) {
run {
resolvedInputSpec = MergedSpecBuilder(
inputSpecRootDirectoryValue,
mergedFileName.getOrElse("merged")
).buildMergedSpec()
logger.info("Merge input spec would be used - {}", resolvedInputSpec)
}
}
}