Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kotlin] Add Option to Skip Merging Spec Files #19396

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading