OpenAPITools / OpenAPITools/openapi-generator

[BUG] Gradle plugin seems to mistake JSON OpenAPI 3.0 spec for Swagger 2.0, while CLI works fine

Open
#9,898 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Running the Gradle plugin on the JSON file obtained from the online OpenAPI 3.0.1 definition exposed by Springdoc fails validation, but generates the client stubs fine with the openapi-generator-cli-5.1.1.jar.

My configuration is simply like this (I tried with other languages not just dart with the same effect)

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 I get a bunch of errors like this:

> 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

Why is it expecting swagger when this is an OpenAPI 3.0 definition, and complaining that openapi is unexpected?
This file works perfectly with CLI generator but for some reason Gradle is not detecting it as OpenAPI 3.0.1.

This seems to be a bug with the plugin.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with api_spec/api.json and the Gradle openApiGenerate configuration using plugin version 5.1.1, then compare it with openapi-generator-cli-5.1.1.jar. Trace how the Gradle plugin selects validation and specification handling; done means the OpenAPI 3.0.1 document validates and generates the client successfully through Gradle.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.