从Gradle插件(openapitools生成器)引用外部文件(openapi规范) [英] Reference external file (openapi spec) from gradle plugin (openapitools generator)

查看:199
本文介绍了从Gradle插件(openapitools生成器)引用外部文件(openapi规范)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个引用已在工件中发布的openapi规范的应用程序.这意味着我将把foo.yaml作为依赖项拉入,但是我似乎无法弄清楚如何通过openapitools生成器插件实际引用该文件.

I am attempting to build an application that references an openapi spec that is already published in artifactory. That means I'll be pulling the foo.yaml in as a dependency, but I can't seem to figure out how to actually reference that file by the openapitools generator plugin.

鉴于openapi规范可用于生成服务器代码和客户端代码,因此完全分开发布并且只需将其引入并由实现引用是十分合理的.

Given that openapi specs can be used to generate both server code and client code, it makes perfect sense that it is published separately and simply pulled in and referenced by implementations.

com.company.bar-1.0.10在jar的顶层包含foo.yaml.

com.company.bar-1.0.10 contains foo.yaml at the top level of the jar.

我已经在build.gradle.kts文件的顶层添加了依赖项,并且还将其作为插件任务本身的一部分添加了.

I've added the dependency at the top level of the build.gradle.kts file and I've also added it as a part of the plugin task itself.

任务generateFooCode(类型:org.openapitools.generator.gradle.plugin.tasks.GenerateTask){

task generateFooCode(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {

generatorName = "java"
apiPackage = 'com.ehi.gbo.openapiconnect.api.foo'
modelPackage = 'com.ehi.gbo.openapiconnect.model.foo'
invokerPackage = 'com.ehi.gbo.openapiconnect.common.invoker'
inputSpec = "foo.yaml".toString()
outputDir = "$buildDir/generated-sources/foo".toString()
configOptions = [
        dateLibrary          : "java8",
        useTags              : true,
        interfaceOnly        : true,
        delegatePattern      : false,
        useBeanValidation    : false,
        performBeanValidation: false,
        useOptional          : false,
        serviceImplementation: false,
        serviceInterface     : false,
        java8                : false,
        serializableModel    : true,
        skipDefaultInterface : true,
        reactive             : false,
]
configurations {
    dependencies {
        implementation 'com.company.bar:foo-api:1.0.10'
    }
}

}

我得到的结果是:* 什么地方出了错:任务':generateFooCode'的执行失败.

Results I'm getting: * What went wrong: Execution failed for task ':generateFooCode'.

规范存在问题.可以通过validateSpec(Maven/Gradle)或--skip-validate-spec(CLI)禁用该选项.|错误计数:1,警告计数:0错误:-无法读取位置 foo.yaml

推荐答案

经过大量的搜索,我遇到了一个非常优雅的解决方案.

After a lot of googling, I came across a very elegant solution.

configurations {
    api
}
  dependencies {
    api 'somegroup:someArtifact:someVersion'
}
  task extractApi(type: Sync) {
    dependsOn configurations.api

    from { // use of closure defers evaluation until execution time
        configurations.api.collect { zipTree(it) }
    }
    into "$buildDir/api/"
}

然后我可以将inputSpec引用为$ buildDir/api/spec.yaml

Then I could just make the inputSpec reference $buildDir/api/spec.yaml

这篇关于从Gradle插件(openapitools生成器)引用外部文件(openapi规范)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆