gpt4 book ai didi

java - 如何根据yml文件生成resttemplate?

转载 作者:行者123 更新时间:2023-12-05 09:36:54 30 4
gpt4 key购买 nike

我使用开放的 openapi-generator-gradle-plugin。这是我的 build.gradle:

buildscript {
repositories {
mavenLocal()

jcenter {
url "http://nexus.ca.sbrf.ru:8081/nexus/content/repositories/jcenter"
}
maven {
url "http://nexus.ca.sbrf.ru:8081/nexus/content/repositories/central"
}
maven { url 'http://nexus.ca.sbrf.ru:8081/nexus/content/repositories/Atlassian_proxy' }
maven { url 'http://nexus.ca.sbrf.ru:8081/nexus/content/groups/public' }

dependencies {
classpath 'org.openapitools:openapi-generator-gradle-plugin:4.3.0'
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.1.RELEASE"
classpath "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE"
}
}
}


apply plugin: 'java'
apply plugin: 'org.openapi.generator'
apply plugin: "maven-publish"
apply plugin: "io.spring.dependency-management"
apply plugin: "org.springframework.boot"

dependencies {
compile 'org.springframework:spring-context:5.3.0'
compile 'org.springframework:spring-web:4.1.6.RELEASE'
compile 'javax.servlet:javax.servlet-api:4.0.1'
compile 'org.openapitools:jackson-databind-nullable:0.2.1'
compile 'io.swagger:swagger-core:1.5.21'
compile 'javax.annotation:javax.annotation-api:1.3.1'
}

openApiGenerate {
generatorName = "spring"
library = "resttemplate"
inputSpec = "$rootDir/openapi-contracts/src/main/resources/openapi/api.yml".toString()
outputDir = "$project.buildDir/generated/openapi"
apiPackage = "ru.openapi.api.v1"
modelPackage = "ru.openapi.model.v1"
enablePostProcessFile = true
configOptions = [
dateLibrary : "java8",
useBeanValidation : "true",
enableBuilderSupport: "true",
interfaceOnly : "true",
delegatePattern : "true"
]
}

sourceSets {
main {
java {
srcDirs "build/generated/openapi/src/main/java"
}
}
}

正在生成服务器代码,一切正常,但我希望为其生成 resttemplate。

为此我指出:

library = "resttemplate"

我收到这个错误:

Unknown library: resttemplateAvailable libraries:spring-bootspring-mvcspring-cloud

我该如何解决这个问题?

最佳答案

不知道如何用 gradle 做,但在 maven 中它会是这样的:

      <plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi.plugin.version}</version>
<executions>
<execution>
<id>${your-id}</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged>
<inputSpec>${project.basedir}/swagger.json</inputSpec>
<generatorName>java</generatorName>
<library>resttemplate</library>
<apiPackage>your.package</apiPackage>
<modelPackage>your.package</modelPackage>
<generateApis>true</generateApis>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateModels>true</generateModels>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>true</generateSupportingFiles>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<useTags>true</useTags>
<interfaceOnly>false</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>

希望对你有所帮助。也许问题是 resttemplate 依赖于 spring-web

关于java - 如何根据yml文件生成resttemplate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64802216/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com