Code Monkey home page Code Monkey logo

Comments (4)

int128 avatar int128 commented on July 21, 2024

Would you provide the root cause of stack trace? You can see stack trace by ./gradlew -s option.
For example,

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':generateSwaggerCodePetstore'.
(snip)

Caused by: java.lang.RuntimeException: Error while running swagger-codegen-cli
(snip)

Caused by: java.lang.RuntimeException: Can't load config class with name generators.MySpring Available: ...
(snip)

Caused by: java.lang.ClassCastException: generators.MySpring cannot be cast to io.swagger.codegen.v3.CodegenConfig
	at io.swagger.codegen.v3.CodegenConfigLoader.forName(CodegenConfigLoader.java:29)
	... 2 more

from gradle-swagger-generator-plugin.

drmaas avatar drmaas commented on July 21, 2024

I had to do this customization in the config:

...
code.configuration = project.buildscript.configurations.getByName("classpath")
...

This makes the java exec of the swagger codegen cli use the buildscript classpath, which contained my generator class.

from gradle-swagger-generator-plugin.

sreich avatar sreich commented on July 21, 2024

it's been a while on this thread, but...did you solve the issue? I tried the code.configuration =...but the problem with that is it seems to override the dependency information too, so then it fails because it thinks swagger-codegen-cli isn't a dependency

happen to know how can i get it on the classpath but also the other dependency?

from gradle-swagger-generator-plugin.

sreich avatar sreich commented on July 21, 2024

Got it working, using swagger2 codegen, adding the following was the trick, ultimately. the @jar syntax, in particular...(sample here is truncated, so groupid/etc may not be uniform)

implementation("io.swagger:swagger-codegen:$swaggerVersion") { exclude("org.slf4", "sl4j-simple") }
swaggerCodegen("io.swagger:swagger-codegen-cli:$swaggerVersion")

//// .....


dependencies {
    swaggerCodegen("com.myorg.generator:my-swagger-generator:3.7.0-SNAPSHOT@jar")
}` 


for tests (using junit & testkit), i did:

`    val SWAGGER_TEST_CASE = """
import org.hidetake.gradle.swagger.generator.GenerateSwaggerCode
plugins {
    `kotlin-dsl`
    `maven-publish`
    id("com.myorg.service-conventions") version "+"
}

repositories {
    gradlePluginPortal()
    mavenCentral()
}

dependencies {
    swaggerCodegen("com.myorg:my-swagger-generator:3.7.0-SNAPSHOT@jar")
}

swaggerSources {
    register("swagger-test-plugin") {
        // Need to save a reference of it here because the `this` scope changes below.
        val validationTask = validation

        val yamlResourceDir = sourceSets.test.get().resources.srcDirs.first().path

        println("test using resource dir ${'$'}yamlResourceDir ")
        val yamlDir = "${'$'}yamlResourceDir/yaml"

        println("test yamlDir is ${'$'}yamlDir")
        setInputFile(file("${'$'}yamlDir/test.yaml"))

        code(delegateClosureOf<GenerateSwaggerCode> {
            language = "com.myorg.generator.swagger.MySpringCodegen"
            outputDir = file("build/generated")
            components = listOf("models")

            dependsOn(validationTask, tasks.named("build")
             , project.getTasksByName("my-swagger-generator:jar", true))
        })
    }
}

@bjconlan-fc close this issue please if you don't need it open still. it works for me
or @int128 can you close this, trying to clean up..

the 'this reference' thing i don't think is actually needed, you can reference it via the this@ syntax to reference out of the closure

from gradle-swagger-generator-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.