springdoc-openapi-gradle-plugin icon indicating copy to clipboard operation
springdoc-openapi-gradle-plugin copied to clipboard

Is there any way to set it so that the output file is overwritten when you build?

Open waterdrake opened this issue 1 year ago • 3 comments

Is there any way to set it so that the output file is overwritten when you build? I use this:

openApi {
	outputFileName.set("openapi.yaml")
}

I noticed that it won't overwrite the yaml file if there is already one there with the same name.

waterdrake avatar Nov 07 '23 09:11 waterdrake

Is there any way to set it so that the output file is overwritten when you build? I use this:

openApi {
	outputFileName.set("openapi.yaml")
}

I noticed that it won't overwrite the yaml file if there is already one there with the same name.

I would like the same feature. I assume it is not possible because documentation states that Springdoc outputs are only available at runtime, but it would be pretty awesome to have it. By the way, I am not able to get the spec file in yaml format. Yaml format seems only available when it is already provided that way from the generated documentation and I am not able to configure it like that

mpolonio avatar Nov 08 '23 08:11 mpolonio

+1

The task caching is a bit too optimistic and seems to rely on a clean to have run beforehand to clear the build folder. This of course doesn't work if you're not writing to the build folder and/or not removing the file on a clean .

Potentially the task should either:

  • simply just be an untracked task and always run,
  • or check if the input jar used by forkedSpringBootRun has changed or not

Adding this gradle block will override generateOpenApiDocs to be an untracked task and always run.

tasks {
  generateOpenApiDocs {
        doNotTrackState("https://github.com/springdoc/springdoc-openapi-gradle-plugin/issues/131")
    }
}

imdando avatar Jan 08 '24 11:01 imdando

Have a try with the following Gradle script:

tasks.named('generateOpenApiDocs') {
    outputs.upToDateWhen {
        false
    }
}

JohnNiang avatar Apr 17 '24 03:04 JohnNiang

I created a pull request to use the inputs for the OpenAPI generation task to be the same as for the Spring Boot task. This will regenerate the OpenAPI if and only if the source files of the application change (but not if for example the tests change). See https://github.com/springdoc/springdoc-openapi-gradle-plugin/pull/147

hiddewie avatar Jun 17 '24 20:06 hiddewie

@waterdrake,

https://github.com/springdoc/springdoc-openapi-gradle-plugin/pull/147 should resolve the issue.

bnasslahsen avatar Jun 22 '24 19:06 bnasslahsen