OpenAPI Generator works from command line but not from Gradle Plugin

Viewed 1208

I want to generate the client stubs for my Flutter/Dart application for an internal API written in OpenAPI 3. The server itself was generated using the same API spec with the Maven plugin org.openapitools.openapi-generator-maven-plugin.

When I try to generate the Dart client stubs in this way via the command line it works fine:

java -cp openapi-generator-cli-5.1.1.jar org.openapitools.codegen.OpenAPIGenerator generate -i ./api_spec/api.json -g dart --enable-post-process-file

But I want to put it in a gradle build as part of the Flutter application, so I followed the instructions and created this build.gradle file:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
}

plugins {
    id "org.openapi.generator" version "5.1.1"
}

openApiGenerate {
    generatorName = "dart"
    inputSpec = "$rootDir/api_spec/api.json"
    outputDir = "$rootDir/../api"
    apiPackage = "mypackage.api"
    modelPackage = "mypackage.api"
}

However, this does not generate the client stubs. (I even tried changing language to see where the problem is, and the effect is the same). I get a bunch of errors like the following, which seem to indicate that for some reason it is expecting a Swagger 2.0 file instead of an OpenAPI 3.x file.

> Task :openApiGenerate FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':openApiGenerate'.
> There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
   | Error count: 72, Warning count: 0
  Errors:
        -attribute paths.'/subscriber/{id}/device'(post).[id].type is missing
        -attribute openapi is unexpected
        -attribute servers is unexpected
        -attribute swagger is missing
        -attribute components is unexpected

Is there any way to fix this, or to specify the OpenAPI version explicitly?

I even tried to set validateSpec = false but it does not make any difference, the flag is ignored and I still get the same output.

0 Answers
Related