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

fork properties not found #75

Closed
thejeff77 opened this issue Mar 31, 2022 · 14 comments · Fixed by #78
Closed

fork properties not found #75

thejeff77 opened this issue Mar 31, 2022 · 14 comments · Fixed by #78

Comments

@thejeff77
Copy link

after upgrading from 1.3.3 to 1.3.4, get this error:

Could not get unknown property 'forkProperties' for extension 'openApi' of type org.springdoc.openapi.gradle.plugin.OpenApiExtension.

application/build.gradle

config file:

openApi {
	waitTimeInSeconds.set(120)
	forkProperties.set("-Dspring.profiles.active=local")
	outputDir.set(file("$rootDir/application"))
	groupedApiMappings.set(["http://localhost:8080/v3/api-docs/someGroup1" : "someGroup1.json",
							"http://localhost:8080/v3/api-docs/someGroup2" : "someGroup2.json"])
}
@kogayushi
Copy link

hi, @thejeff77

as far as i investigated, we should use bootRun's args directive.
like this => https://github.com/springdoc/springdoc-openapi-gradle-plugin/blob/master/src/test/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePluginTest.kt#L94-L96

probably, this is what you want to know.

@thejeff77
Copy link
Author

thejeff77 commented Apr 4, 2022

Unfortunatly no. I'm not trying to set a local profile running the app. I'm trying to set it when the plugin runs - which is what this forkProperties argument is used for. It doesn't matter what app setting I set.. the point is that forkProperties is borked after the version upgrade - which is the reason for this bug. Does that make sense?

@kogayushi
Copy link

kogayushi commented Apr 4, 2022

sorry, but i don’t understand your point.
anyway, did you try this ? not yet ?

if you try my suggestion, your config file gonna be like this.

openApi {
	waitTimeInSeconds.set(120)
        bootRun {
            args = ["--spring.profiles.active=local"]
        }
	outputDir.set(file("$rootDir/application"))
	groupedApiMappings.set(["http://localhost:8080/v3/api-docs/someGroup1" : "someGroup1.json",
							"http://localhost:8080/v3/api-docs/someGroup2" : "someGroup2.json"])
}

i believe this gonna fix your issue, i don't know this is absolutely right way, though.

@kogayushi
Copy link

and, i forgot what i have to say.

i’m not maintainer of this plugin.
but i’ve just found whom facing same issue what i was facing.

i hope my advice helps you, a little bit.

@sgrimm
Copy link
Contributor

sgrimm commented Apr 6, 2022

I ran into this too. My workaround:

import org.springframework.boot.gradle.tasks.run.BootRun

openApi {
  val bootRun = project.tasks["bootRun"] as BootRun

  // Previously: properties["spring.profiles.active"] = "apidoc"
  bootRun.jvmArgs("-Dspring.profiles.active=apidoc")
}

The BootRun.jvmArgs() method adds JVM arguments; you can call it multiple times if you need to.

@kogayushi
Copy link

sorry, but i found my workaround has another problem.

if configure like openapi { bootRun { args = ["--spring.profiles.active=local"] } }, this args will be applied to ./gradlew bootRun too, unintentionally.

please be careful if you choose with this workaround.

@gerkestam2
Copy link

gerkestam2 commented Apr 20, 2022

This one works for me:

openApi {

bootRun {
    jvmArgs = ["-DSERVER_PORT=8093", "-DMANAGEMENT_PORT=9993"]
}
waitTimeInSeconds.set(120)

}

Could the documentation be updated?

@mhornung-chwy
Copy link

The problem with some of the other answers here is that it modifies the bootRun task to always run with the profile you want to use to generate the API docs. A workaround to that is this:

  1. Modify the bootRun task to pass all the command line properties through.
// Kotlin
tasks.bootRun {
    systemProperties(System.getProperties().mapKeys { it.key as String })
}
  1. Specify the Spring profile on the arguments.
./gradlew generateOpenApiDocs -Dspring.profiles.active=apidocs

@caspianb
Copy link

caspianb commented Apr 25, 2022

@mhornung-chwy I do not believe that works if you wish to trigger doc generation as part of a greater process (e.g. X dependsOn generateOpenApiDocs, etc).

As far as I can tell, there is no viable "workaround" for the missing forkProperties parameter; it would be very helpful if some form of equivalent option were reinstated. We are currently stuck on the older version because of this (unless there is some method to ingest specific environment variables into a specific task directly inside the gradle files?).

@mhornung-chwy
Copy link

mhornung-chwy commented Apr 26, 2022

@caspianb Here's another workaround.

First, register the new task that depends on the API docs generation and does whatever else it needs to do.

tasks.register<DefaultTask>("someTask") {
    dependsOn("generateOpenApiDocs")
}

Modify bootRun to ingest any system properties that are set.

tasks.bootRun {
    systemProperties(System.getProperties().mapKeys { it.key as String })
}

Create a new task to set the spring.profiles.active system property.

tasks.register<DefaultTask>("systemPropsTask") {
    System.setProperty("spring.profiles.active", "apidocs")
}

Lastly, make the API spec generation depend on the task that sets the system properties.

tasks.withType<org.springdoc.openapi.gradle.plugin.OpenApiGeneratorTask> {
    dependsOn("systemPropsTask")
}

Run ./gradlew someTask to generate the API spec, and continue with whatever else is set in the task.

@ericenns
Copy link

ericenns commented Jun 9, 2022

NOTE: This was edited to fix an incorrect solution that I posted earlier

@caspianb here is another workaround. (note: this is all in kotlin DSL)

Add the following to top of build.gradle.kts

import org.springframework.boot.gradle.tasks.run.BootRun

Then update the bootRun task to set any of the bootRun properties when running the generateOpenApiDocs task.

tasks.named<BootRun>("bootRun") {
    if (project.gradle.taskGraph.hasTask(":generateOpenApiDocs")) { 
        // customize bootRun here
        // pass all system properties to bootRun (likely only want to pass your specific params here
        bootRun.systemProperties(System.getProperties().mapKeys { it.key as String })
    }
}

@thejeff77
Copy link
Author

thejeff77 commented Jun 9, 2022

Seems like you guys are doing a lot of work to work around this issue when you could simply bump the version back to 1.3.3.

What's the point of the additional code in your repo rather than waiting for a versioned release with a fix?

The easiest thing to maintain is no code. Ex: https://github.com/kelseyhightower/nocode

@litols
Copy link
Contributor

litols commented Jun 12, 2022

Hi there, I faced to this issue too. to customize bootRun parameter, I've submit PR to supply custom properties.
I hope I can resolve this issue by this PR...

@juliaisnotavailable
Copy link

Non Kotlin workaround where you don't need to trigger doc generation as part of a greater process.

bootRun {
   systemProperties System.properties
}

./gradlew generateOpenApiDocs -Dspring.profiles.active=openapi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants