-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
In a very similar manner to the same issue with java-native
generator, the annotationLibrary
option is being ignored in the spring
generator, resulting in obsolete and conflicting imports being added to the model classes.
openapi-generator version
The issue is present in 7.16.0
.
OpenAPI declaration file content or url
type: object
required:
- schemas
additionalProperties: false
properties:
schemas:
type: object
additionalProperties:
$ref: "schema.yml" # anything could be here
(here your code)
Generation Details
In build.gradle
:
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
plugins {
id 'org.openapi.generator' version '7.15.0
}
ext {
openAPIGeneratorVersion = '7.15.0'
jakartaAnnotationVersion = '2.1.1'
jacksonDatabindNullableVersion = '0.2.6'
}
dependencies {
implementation ("org.openapitools:openapi-generator:$openAPIGeneratorVersion") {
exclude group: 'org.slf4j', module: 'slf4j-simple'
}
implementation "org.openapitools:jackson-databind-nullable:$jacksonDatabindNullableVersion"
implementation "jakarta.annotation:jakarta.annotation-api:$jakartaAnnotationVersion"
}
tasks.register('generateOpenAPI', GenerateTask) {
generatorName = "spring"
inputSpec = "$rootDir/api/api-v1.yml"
outputDir = "$projectDir"
ignoreFileOverride = "$projectDir/.openapi-generator-ignore"
apiPackage = "com.myapp.api"
modelPackage = "com.myapp.model"
configOptions = [
booleanGetterPrefix : "is",
interfaceOnly : "true",
openApiNullable : "false",
skipDefaultInterface : "true",
documentationProvider: "none",
annotationLibrary : "none2",
useEnumCaseInsensitive: "true",
useJakartaEe: "true"
]
globalProperties = [
apis: "",
models: "",
]
additionalProperties = [
removeEnumValuePrefix: "false",
]
}
tasks.named('compileJava') {
dependsOn tasks.named('generateOpenAPI')
}
tasks.withType(ProcessResources).configureEach {
dependsOn 'generateOpenAPI'
}
compileJava {
options.release = 17
sourceCompatibility = "17"
targetCompatibility = "17"
}
Steps to reproduce
Trying to build a project with the above configuration results in a compile-time error:
* What went wrong:
Execution failed for task ':application:compileJava'.
> Compilation failed; see the compiler output below.
/Users/shybovycha/projects/application/src/main/java/com/myapp/generated/model/Database.java:8: error: package io.swagger.v3.oas.annotations.media does not exist
import io.swagger.v3.oas.annotations.media.Schema;
Related issues/PRs
🎟️ #21991