Swagger在Linux上的兼容性问题可以通过以下几种方法解决:
docker pull swaggerapi/swagger-ui:latest
docker pull swaggerapi/swagger-editor:latest
docker run -d -p 8080:8080 swaggerapi/swagger-ui:latest
docker run -d -p 8081:8080 swaggerapi/swagger-editor:latest
http://localhost:8080
和http://localhost:8081
访问Swagger UI和Swagger Editor。curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g swagger-jsdoc express http-server
git clone https://github.com/swagger-api/swagger-ui.git
cd swagger-ui
npm install http-server -p 8080
node /path/to/swagger-editor/index.js
node /path/to/swagger-ui/index.js
http://localhost:8080
访问Swagger UI。pom.xml
文件中添加Springdoc OpenAPI依赖。<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("public")
.pathsToMatch("/public/**")
.build();
}
}
http://localhost:8080/swagger-ui/index.html
查看Swagger文档。通过以上方法,您应该能够在Linux系统上成功安装和运行Swagger,从而方便地生成和测试API文档。如果在安装过程中遇到任何问题,请参考相关文档或寻求社区帮助。