Code Monkey home page Code Monkey logo

Comments (6)

ciscoo avatar ciscoo commented on August 22, 2024 15

@jangalinski @Clemzd @int128 and others that find this issue, here's an example:

plugins {
    // ...
    id("org.hidetake.swagger.generator") version "2.18.1"
}

// ...

dependencies {
    swaggerCodegen("io.swagger.codegen.v3:swagger-codegen-cli:3.0.8")
   // ... other Swagger dependencies like annotations
}

// ...

swaggerSources {
    // Gradle recommends `register` over `create` to avoid eagerly creating/configuring items.
    register("petstore") {
        // Part of the "petstore" SwaggerSource
        // Need to save a reference of it here because the `this` scope changes below.
        val validationTask = validation

        setInputFile(file("petstore-swagger.json"))

        // The method signiature is `code(@DelegatesTo(GenerateSwaggerCode) Closure closure)`
        // So best to use `delegateClosureOf<GenerateSwaggerCode>`
        // https://docs.gradle.org/current/userguide/kotlin_dsl.html#groovy_closures_from_kotlin
        code(delegateClosureOf<GenerateSwaggerCode> {
            language = "spring"
            components = listOf("models")
            dependsOn(validationTask)
        })
    }
}

tasks.named("compileJava").configure {
    dependsOn(tasks.named("generateSwaggerCode"))
}

sourceSets {
    val main by getting
    val petstore by swaggerSources.getting
    main.java.srcDir("${petstore.code.outputDir}/src/main/java")
}

from gradle-swagger-generator-plugin.

mywill avatar mywill commented on August 22, 2024 5

I have it working on version 2.15.0 and gradle 5 with this

swaggerSources {
    create( "qwerservice", {
        setInputFile( file("swagger.yml") )
        code.outputDir = file( "$buildDir/client" )
        code.language = "spring"
        code.additionalProperties = mapOf( "group-id" to "com.qwer",
                                            "dateLibrary" to "java8",
                                            "java8" to "true",
                                            "modelPackage" to "com.qwer.model",
                                            "apiPackage" to "com.qwer.api",
                                            "invokerPackage" to "com.qwer.invoker" )
    } )
}

from gradle-swagger-generator-plugin.

bigpuritz avatar bigpuritz commented on August 22, 2024 2

alternatively you can create a custom task like this:

import org.hidetake.gradle.swagger.generator.GenerateSwaggerCode

plugins {
    id("org.hidetake.swagger.generator") version "2.18.2"
}

dependencies {
    swaggerCodegen("io.swagger.codegen.v3:swagger-codegen-cli:3.0.23")
 }

tasks {
    register<GenerateSwaggerCode>("petstore") {
        inputFile = projectDir.resolve("petstore.yaml")
        language = "spring"
    }
 }

from gradle-swagger-generator-plugin.

int128 avatar int128 commented on August 22, 2024

It is not supported yet. It will be supported in the future release.

from gradle-swagger-generator-plugin.

clementgpro avatar clementgpro commented on August 22, 2024

@mywill hi! Could you share your build.gradle.kts? I am trying to make it work with kotlindsl too.

from gradle-swagger-generator-plugin.

sreich avatar sreich commented on August 22, 2024

fyi to anyone seeing this, that "this scope changes" thing is not necessary. kotlin lets you use this@register and such, to access different scopes that are injected into the closure. it allows similar with return@ for breaking out of closures

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.