question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenApi Generator gradle plugin generates new gradle project

See original GitHub issue
Description

Hello!

I’m trying to generate code via OpenAPI Generator Gradle Plugin version 5.1.1 I can’t understand behavior of this plugin, it generates new gradle project, but not only kotlin classes

my task configuration is

openApiGenerate {
    //verbose.set(true)
    generatorName.set("kotlin")
    outputDir.set(project.file("${buildDir.name}/generated").absolutePath)
    inputSpec.set(project.file("schema/openapi.json").absolutePath)
    packageName.set("org.camunda.bpm.engine.rest")
    apiPackage.set("org.camunda.bpm.engine.rest.api")
    modelPackage.set("org.camunda.bpm.engine.rest.model")
}

As far as i know, maven plugin generates just classes, not new project Looks like gradle plugins works as generator cli

Why openapi generator gradle plugin generates new project? photo_2021-05-27_12-14-42

openapi-generator version

5.1.1

OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
ChristianCiachcommented, Jun 11, 2021

I second this. To this day I do not understand the purpose of the gradle plugin. One would expect this plugin to automatically include the generated code to /src/gen/java (not literally, but make the generated code part of a java sourceSet) of the gradle project that uses the plugin, and also extend the compileClasspath configuration to include the necessary dependencies (like jackson and stuff). But in fact, the Gradle plugin is a very thin wrapper around the CLI. You can just as well call this directly via javaExec.

To actually use the generated code inside your own gradle project, you have to do hacky stuff like sourceSets.main.java.srcDir "${buildDir}/generated/src/main/java" and also manually (!) copy the dependencies from the generated build.gradle file into your own.

We have tens of developers in our company, and every single one of them misunderstands the purpose of the gradle plugin. All one of them, myself included, expect this plugin to make it so that the generated code becomes directly usable inside your own gradle project. But unfortunately, this is not the case.

2reactions
Vampirecommented, Sep 7, 2021

Or like this for Kotlin:

val openApiGeneratorIgnoreFile = layout.projectDirectory.file(".openapi-generator-ignore")

openApiGenerate {
    generatorName.set("kotlin")
    outputDir.set(layout.buildDirectory.dir("generated/sources/openapi/main/kotlin").map {
        it.asFile.absolutePath
    })
    inputSpec.set(downloadNexusOpenApiSpec.map {
        it.outputs.files.singleFile.absolutePath
    })
    generateApiDocumentation.set(false)
    generateApiTests.set(false)
    generateModelDocumentation.set(false)
    generateModelTests.set(false)
    packageName.set("org.sonatype.nexus.client")
    apiPackage.set("org.sonatype.nexus.client.api")
    modelPackage.set("org.sonatype.nexus.client.model")
    configOptions.set(mapOf(
        "sourceFolder" to "",
        "enumPropertyNaming" to "original"
    ))
    ignoreFileOverride.set(
        openApiGeneratorIgnoreFile.asFile.absolutePath
    )
}

// TODO: work-around for https://github.com/OpenAPITools/openapi-generator/issues/10214
tasks.openApiGenerate {
    inputs
        .files(openApiGeneratorIgnoreFile)
        .withPathSensitivity(NONE)
        .withPropertyName("openApiGeneratorIgnoreFile")
}

sourceSets {
    main {
        java {
            srcDir(tasks.openApiGenerate)
        }
    }
}
/build/generated/sources/openapi/main/kotlin/**
!build/generated/sources/openapi/main/kotlin/org/**
Read more comments on GitHub >

github_iconTop Results From Across the Web

openapi-generator/README.adoc at master - GitHub
This document describes the Gradle plugin for OpenAPI Generator. This Gradle plugin offers a declarative DSL via extensions (these are Gradle project ......
Read more >
Plugins - OpenAPI Generator
A Maven plugin to support the OpenAPI generator project ... This gradle plugin offers a declarative DSL via extensions (these are Gradle ......
Read more >
Generate Java Spring API from OpenAPI 3 - Stack Overflow
I followed OpenAPI generator gradle plugin doc doc. My build.gradle: plugins { id 'java-library' id "org.openapi.generator" version ...
Read more >
org.openapi.generator - Gradle Plugin Portal
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI ...
Read more >
How to Automate OpenAPI Client Code Generation in Spring ...
This tool allows developers to auto-generate client code segments by referring to the ... How to Define the Code Generation as a Gradle...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found