I'm trying to generate models and controller interfaces with openapi-generator-gradle-plugin.
The problem I'm having is that the plugin in generating classes instead of interfaces.
A generated class looks like this:
public class DossiersApi {
private ApiClient localVarApiClient;
public DossiersApi() {
this(Configuration.getDefaultApiClient());
}
public DossiersApi(ApiClient apiClient) {
this.localVarApiClient = apiClient;
}
public ApiClient getApiClient() {
return localVarApiClient;
}
public void setApiClient(ApiClient apiClient) {
this.localVarApiClient = apiClient;
}
/**
* Build call for getDossier
* @param dossierId Unique identifier of the dossier. (required)
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
...
</table>
*/
public okhttp3.Call getDossierCall(Long Id, final ApiCallback _callback) throws ApiException {
Object localVarPostBody = null;
...
While I'm trying to generate an interface, so that I can implement it in my rest controller.
When looking at the configuration, I assumed that the interfaceOnly
parameter will make the openapi-generator-gradle-plugin generate interfaces instead of classes, but in my case it's not working and I'm not sure what's the problem.
I have already checked this, but none of the solutions is working for me: Generate Java Spring API from OpenAPI 3 ,
Generate only REST interfaces for spring boot with openapi-generator-gradle-plugin
My gradle.build looks like this :
plugins {
id 'org.springframework.boot' version '2.6.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id "org.openapi.generator" version "5.1.1"
}
group = 'com.cs'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
targetCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.postgresql:postgresql:42.1.4'
implementation 'javax.validation:validation-api:2.0.1.Final'
implementation 'org.springframework.boot:spring-boot-starter-security:2.6.1'
implementation 'io.swagger.core.v3:swagger-annotations:2.1.11'
implementation 'io.springfox:springfox-swagger2:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
implementation 'org.openapitools:jackson-databind-nullable:0.2.2'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'org.modelmapper:modelmapper:2.4.4'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
openApiGenerate {
generatorName = "java"
inputSpec = "$rootDir/src/main/resources/swagger.yaml".toString()
outputDir = "$buildDir/generated".toString()
apiPackage = "org.openapi.example.api"
invokerPackage = "org.openapi.example.invoker"
modelNameSuffix = "Dto"
generateApiTests = false
generateModelTests = false
modelPackage = "org.openapi.example.model"
configOptions = [
dateLibrary: 'java8',
interfaceOnly: 'true',
skipDefaultInterface: 'true',
useApiIgnore:'fales',
swaggerAnnotations: 'true',
]
globalProperties = [
modelDocs: 'false',
apis: '',
models: ''
]
}
Note that I also tried downgrading the openapi generator to version to 5.1.1 (I started with 5.3.0), but that didn't solve the problem. Would anyone have any idea how to fix this?
Thanks.
CodePudding user response:
The java
generator (simply) doesn't support (gracefully(? -> debug/verbose!)) the interfaceOnly
option.
Try generatorName = "spring"
or refer to one of the generators documented in the parent directory.