我不知道为什么对我来说如此困难,但我已经 st了几个小时。
我先用“Yaml”文档,用开放式3.0.0规格,界定了我的“Swagger UI”。 这一规格要求界定一个版本,显示在Swagger页上。 但我想我的Swagger-UI要使用我的“格拉斯”档案版本,因此,我不必担心在任何时候都会改变两种版本。 但似乎没有工作。
难道没有办法超过规格文件版本?
这里我要说的是:
4. 建造。
version = "0.0.3" // <= I want this on my Swagger Page
group = "com.my.api"
java.sourceCompatibility = JavaVersion.VERSION_17
dependencies {
...
implementation("org.springdoc:springdoc-openapi-webflux-ui:1.6.15")
}
springBoot {
buildInfo()
}
openApiGenerate {
generatorName.set("kotlin")
inputSpec.set("$rootDir/src/main/resources/static/my-api-spec.yaml")
outputDir.set("$buildDir/generated")
modelPackage.set("com.my.api.web.model")
globalProperties.set(mapOf(
"apis" to "false",
"apiDocs" to "false",
"apiTests" to "false",
"models" to "",
"modelTests" to "false",
"modelDocs" to "false",
"invoker" to "false"
))
configOptions.set(mapOf(
"serializationLibrary" to "jackson",
"sourceFolder" to ""
))
}
sourceSets {
main {
java.srcDir("$buildDir/generated")
}
}
tasks.withType<KotlinCompile> {
dependsOn(tasks.openApiGenerate)
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}
src/main/resources/application.yml
springdoc:
swagger-ui:
enabled: true
url: /my-api-spec.yaml
path: /swagger-ui.html
api-docs:
enabled: true
path: /api-docs
src/main/resources/static/my-api-spec.yaml
openapi: 3.0.0
info:
title: My Little API
description: "API for doing things"
version: "placeholder" # But this shows up no matter what
servers:
- url: http://localhost:8080/
description: "Local"
paths:
/me:
get:
summary: "Get Current User Details"
description: "Returns basic details about the current Authenticated User"
responses:
200 :
description: "The Current Authenticated User s Details"
content:
application/json:
schema:
$ref: #/components/schemas/BasicUserInfo
...
我尝试了这一点,但没有幸运。 它只是取代我/api-docs中的版本,但国际不动产业联合会忽视了这一版本,而是使用了该书的版本。
src/main/kotlin/com/my/api/Application.kt
@SpringBootApplication
class MyLittleApplication {
@Bean
@ConditionalOnProperty(value = ["springdoc.swagger-ui.enabled"], havingValue = "true")
fun swaggerCustomization(buildProperties: BuildProperties): OpenApiCustomiser {
return OpenApiCustomiser { openApi ->
openApi.info.version(buildProperties.version)
}
}
}
fun main(args: Array<String>) {
runApplication<MyLittleApplication>(*args)
}