fix(gradle-plugin): add .convention() defaults to Property fields in ResolveTask by lfgcampos · Pull Request #5065 · swagger-api/swagger-core (original) (raw)
Pull Request
Thank you for contributing to swagger-core!
Please fill out the following information to help us review your PR efficiently.
Closes #5136
Description
In Gradle 9, calling Property<T>.get() on a property that has neither a set value nor a convention throws at runtime:
Cannot query the value of task property '...' because it has no value available.
ResolveTask.resolve() calls .get() unconditionally on prettyPrint, readAllResources, sortOutput, alwaysResolveAppPath, skipResolveAppPath, and encoding. None had a .convention(...) default, so they throw when not explicitly set by the caller.
Fix: add .convention(false) to the five boolean fields and .convention(StandardCharsets.UTF_8.name()) to encoding. Callers that set these explicitly are unaffected.
| Property | Type | Convention | Notes |
|---|---|---|---|
| outputFileName | Property | "openapi" | Was unguarded .get() |
| outputFormat | Property | Format.JSON | Was unguarded .get() |
| prettyPrint | Property | false | Matches SwaggerPlugin |
| readAllResources | Property | false | Matches SwaggerPlugin |
| encoding | Property | Charset.defaultCharset().name() | Matches SwaggerPlugin |
| sortOutput | Property | false | Matches SwaggerPlugin |
| alwaysResolveAppPath | Property | false | Matches SwaggerPlugin |
| skipResolveAppPath | Property | false | Matches SwaggerPlugin |
| skip | Property | false | Already safe via .getOrElse(), added for consistency |
| openAPI31 | Property | false | Matches SwaggerPlugin |
| convertToOpenAPI31 | Property | false | Fixes latent bug: .get() at line 578 had no isPresent() guard |
Type of Change
- 🐛 Bug fix
- ✨ New feature
- ♻️ Refactor (non-breaking change)
- 🧪 Tests
- 📝 Documentation
- 🧹 Chore (build or tooling)
Checklist
- I have added/updated tests as needed
- I have added/updated documentation where applicable
- The PR title is descriptive
- The code builds and passes tests locally
- I have linked related issues (if any)