Skip to content

Commit 84ac22a

Browse files
authored
Generate the OpenAPI spec on a free port (#7777)
`generateOpenApiDocs` forks a Spring Boot instance to harvest the spec, but the scrape URL was hardcoded to `http://localhost:8080` - the app's own port. If any Stirling instance is already listening there (a dev server, a container, a WSL relay) the plugin reads **that** build instead of the fork, and `task tool-models` then generates the Python and TypeScript models from whatever happens to be running. It fails silently and looks like success. I hit it while regenerating models after editing Java annotations: the build passed, the compiled class contained the new text, and the spec contained none of it. Fetching the URL by hand settled it: ``` paths live8080: 276 ours: 276 identical parsed content: True ``` The generated `SwaggerDoc.json` was the running instance's document, not the working tree's. Now on a random free port, passed to both the fork and the scrape URL so they cannot disagree. Override with `-PopenApiPort=NNNN` to use a specific port.
1 parent 70cdf24 commit 84ac22a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,12 @@ subprojects {
452452
if (name == 'stirling-pdf') {
453453
apply plugin: 'org.springdoc.openapi-gradle-plugin'
454454

455+
def openApiPort = rootProject.findProperty('openApiPort')?.toString()
456+
?: new ServerSocket(0).withCloseable { it.localPort }.toString()
457+
455458
openApi {
456-
apiDocsUrl = "http://localhost:8080/v1/api-docs"
459+
apiDocsUrl = "http://localhost:${openApiPort}/v1/api-docs"
460+
customBootRun { args = ["--server.port=${openApiPort}"] }
457461
outputDir = file("$projectDir")
458462
outputFileName = "SwaggerDoc.json"
459463
waitTimeInSeconds = 60 // Increase the wait time to 60 seconds

0 commit comments

Comments
 (0)