OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.81k stars 6.58k forks source link

[BUG] [openapi-generator-gradle-plugin] jar: URL resolution not allowed by gradle #19260

Open arthurtemple opened 3 months ago

arthurtemple commented 3 months ago
Description

This recent Pull Request enabled inputSpec resolution from a jar: URI in maven projects (thanks a lot, by the way!).

We hoped to use this new feature in gradle projects, unfortunately gradle tries to resolve the inputSpec as a file and fails to do so when a jar: URI is provided.

openapi-generator version

Gradle plugin version 7.7.0.

Steps to reproduce

A simple project is available as attachment here: open-api-uri-issue.zip

In order to reproduce, simply run ./gradlew openApiValidate

Expected output

./gradlew openApiValidate

> Task :openApiValidate
Validating spec jar:file:src/main/resources/petstore.jar!/petstore.yaml
Spec is valid.

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

Actual output

./gradlew openApiValidate
> Task :openApiValidate FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':openApiValidate'.
> Cannot convert URL 'jar:file:src/main/resources/petstore.jar!/petstore.yaml' to a file.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 605ms
1 actionable task: 1 executed
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/18576

Suggest a fix

A fix seems to remove the constraint in GenerateTask.kt and ValidateTask.kt:

- @get:InputFile
- @PathSensitive(PathSensitivity.RELATIVE)
+ @get:Input
val inputSpec = project.objects.property<String>()
arthurtemple commented 3 months ago

As a side note, it is possible to work around gradle validation (and caching) using remoteInputSpec instead of inputSpec.

This is only supported in openApiGenerate task, however, and not in openApiValidate. If you consider this good enough (which is my case), please delete this issue :pray: .