English 中文(简体)
• 如何在我的Swagger UI中凌驾于开放的开放式消费物价指数光谱版本之上?
原标题:How to override/customize OpenAPI Spec Version in my Swagger UI?

我不知道为什么对我来说如此困难,但我已经 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)
}
问题回答

在您的春布申请类别中,添加一个习惯<代码>。 开放式消费标准/编码

import org.springdoc.core.customizers.OpenApiCustomiser
import org.springdoc.core.customizers.OperationCustomizer
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean

@SpringBootApplication
class MyLittleApplication {

    @Bean
    fun customOpenAPI(): OpenAPI {
        val openAPI = OpenAPI()
        openAPI.info = Info()
            .title("My Little API")
            .description("API for doing things")
            .version("0.0.3") // Set your project version here
        return openAPI
    }

    // ... other beans and configurations

    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            runApplication<MyLittleApplication>(*args)
        }
    }
}

举例而言,创设一个特殊<代码>OpenAPI bean,并将该版本改为您选定的项目版本(0.0.3)。 您可根据需要动态更新这一版本。 进口所需类别(OpenAPI,Info,并将申请类别与@SpringBootApplication。 有了这一配置,Swagger UI版本就应当更新到您在习俗中具体规定的价值





相关问题
WAF FILE could not EXPORT due to no WEB PROJECT option found

I was trying to create a war file on spring tool suite 4 (windows version). But as I was about to export the it to the local file system, I couldn t find the web project (wiseai-console) option of the ...

Combine multiple cb.literal() into 1 Expression

I am working on a Spring Boot project that uses PostgreSQL. I want to create a advanced search feature where user can search through the jsonb column that I have in many of my tables. Somewhere in my ...

Error using criteriaBuilder.max() for LocalDate

I am trying to get max date using criteria builder in a subquery. But I am getting this error Required type: Expression Provided: Expression Subquery<LocalDate> subRoot = criteriaQuery....

热门标签