Skip to content

Commit

Permalink
Add option to skip merging spec files (#19396)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erikvanderwerf authored Feb 19, 2025
1 parent 890c37f commit 9374dbd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,34 @@ 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
@PathSensitive(PathSensitivity.RELATIVE)
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
*/
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 9374dbd

Please sign in to comment.