【发布时间】:2021-11-15 21:15:11
【问题描述】:
所以我有一个简单的 Spring Boot REST API 可以正常工作,现在我已经为 ui 和 core 添加了一些 swagger 依赖项,并使用 @ApiIgnore 或 @Operation 等标签进行了一些测试,它们都可以正常工作并且两者都在 http://localhost:8080/swagger-ui/#/
中更新现在我正在尝试通过 @OpenAPIDefinition 标记更新 API 信息,在我的应用程序类中是这样的:
@OpenAPIDefinition(
info = @Info(
title = "the title",
version = "0.0",
description = "My API",
license = @License(name = "Apache 2.0", url = "http://foo.bar"),
contact = @Contact(url = "http://gigantic-server.com", name = "Fred", email = "Fred@gigagantic-server.com")))
现在我已经阅读here,Spring Boot 应用程序应该进行类扫描并识别 @OpenAPIDefinition bean 并更新 http://localhost:8080/v3/api-docs 中生成的 json。但事实并非如此,我也尝试使用 openapi.yaml 文件设置该信息,但也没有运气。
我怀疑这可能与我的依赖关系有关,因为我是新来的大摇大摆的人,仍然有点迷茫并且可能混淆了一些东西,我将 pom.xml 留在这里:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我对如何继续感到有些茫然,并且不明白 swagger 如何识别 @ApiIgnore 标记,但忽略 @OpenAPIDefinition 标记。正如我所说,我对整个事情和 stackoverflow 都是新手,所以如果我忘记添加任何相关代码,请原谅我,谢谢!
【问题讨论】:
标签: java spring spring-boot swagger springfox