我正在尝试将我的API文档分解为多个可以独立编辑的JSON文件.我能够找到的所有示例都使用Swagger 1.2模式,该模式具有"api":{}对象以便将其分解.这似乎在2.0模式(http://json.schemastore.org/swagger-2.0)中缺失.所有定义的都是单个"路径"数组,它将所有API端点捆绑到该单个数组中.这在swagger-ui中的效果是有一个单独的"默认"类别,所有内容都被捆绑在一起,我无法分辨它.
TLDR:如何从swagger 2.0模式中的路径中拆分操作
{
"swagger": "2.0",
"info": {
"description": "My API",
"version": "1.0.0",
"title": "My API",
"termsOfService": "http://www.domain.com",
"contact": {
"name": "support@domain.com"
}
},
"basePath": "/",
"schemes": [
"http"
],
"paths": {
"Authorization/LoginAPI": {
"post": {
"summary": "Authenticates you to the system and produces a session token that will be used for future calls",
"description": "",
"operationId": "LoginAPI",
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"application/json"
],
"parameters": [{
"in": "formData",
"name": "UserName",
"description": "Login Username",
"required": true, …Run Code Online (Sandbox Code Playgroud)Spring Boot 2.6.3 与 Springdoc。
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在 中applicaton.yaml,当我将路径设置为 /v3/api-docs 或将其删除时,这意味着使用默认路径“/v3/api-docs”。Swagger UI 页面使用 API http://localhost:8080/swagger-ui/index.html 正确显示
但我想重写路径如下
api-docs.path: /bus/v3/api-docs
Run Code Online (Sandbox Code Playgroud)
然后 Swagger UI 显示“无法加载远程配置”错误:

我已经将swagger插入我的春季启动应用程序.Spring启动允许您拥有每个环境的属性文件.有没有办法禁用生产环境的招摇?
我创建了一个使用个人帐户安全的asp.net webapi应用程序,以便默认启用Bearer令牌.它工作正常,所以我能够在Postman中测试它们没有问题.
当我尝试通过Swashbuckle集成Swagger UI时,问题就出现了.我通过以下方式安装了Swashbuckle:
Install-Package Swashbuckle
然后更改SwaggerConfig.cs:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.ApiKey("Token")
.Description("Filling bearer token here")
.Name("Authorization")
.In("header");
}
.EnableSwaggerUi(c =>
{
c.EnableApiKeySupport("Authorization", "header");
};
Run Code Online (Sandbox Code Playgroud)
启动我的应用程序并填写Bearer令牌:
但是当我运行需要授权的api请求时,它不起作用.这是截图:
承载令牌被添加到标头中的Authorization.但我仍然得到错误401.我想知道是否因为令牌被编码(SPACE被%20取代)?任何的想法?谢谢.
顺便说一句,我想知道如何在我的Swagger文档中添加/ token,以便我可以在Swagger UI中获取令牌.
我在Swagger中有一系列参数
"parameters": [
{
"name": "username",
"description": "Fetch username by username/email",
"required": false,
"type": "string",
"paramType": "query"
},
{
"name": "site",
"description": "Fetch username by site",
"required": false,
"type": "string",
"paramType": "query"
},
{
"name": "survey",
"description": "Fetch username by survey",
"required": false,
"type": "string",
"paramType": "query"
}
],
Run Code Online (Sandbox Code Playgroud)
必须填写一个参数但是哪个参数无关紧要,其他参数可以留空.有没有办法在Swagger中表现出来?
我正在尝试使用Swagger来描述我正在构建的web-api.问题是我无法理解如何描述复杂的json对象?
例如,如何描述这个对象:
{
name: "Jhon",
address: [
{
type: "home",
line1: "1st street"
},
{
type: "office",
line1: "2nd street"
}
]
}
Run Code Online (Sandbox Code Playgroud) @RequestMapping(...)
public Foo getFoo(@HeaderParam("header") final String header) {
...
}
Run Code Online (Sandbox Code Playgroud)
添加一个@HeaderParam方法参数如上所述springfox选择它,当我看到swagger-ui时它有一个标题字段.这正是我想要的.有没有办法告诉springfox在一组方法中包含这个头参数而不必在方法本身上包含参数?我们真正要做的是使用标头的servlet过滤器,我们希望通过swagger-ui轻松设置它.
我正在使用java spring boot框架为我的项目创建REST api,我使用"springfox-swagger2和springfox-swagger-ui"来生成swagger文档.我可以使用url http:// localhost:8080/swagger-ui.html查看我的文档.
如何创建或生成swagger.json/spec.json,文档不应该与此应用程序一起使用我们使用单独的应用程序列出api文档
这是我的理解:
这些信息是否正确?如果没有,有人能用简单的术语解释什么是Swagger,Swashbuckle和Swashbuckle UI意味着什么?
另外,如果我不使用它,我作为API开发人员会失去什么?
我目前在 NestJS 项目中使用 Swagger,并且启用了资源管理器:
在 main.js
const options = new DocumentBuilder()
.setTitle('My App')
.setSchemes('https')
.setDescription('My App API documentation')
.setVersion('1.0')
.build()
const document = SwaggerModule.createDocument(app, options)
SwaggerModule.setup('docs', app, document, {
customSiteTitle: 'My App documentation',
})
Run Code Online (Sandbox Code Playgroud)
有了这个,资源管理器可以访问,/docs这是我所期望的。但我想知道是否可以向资源管理器添加任何身份验证层,因此只接受某些请求。
我想让这个资源管理器在生产中可以访问,但仅限于经过身份验证的用户。
提前致谢 :)
swagger-ui ×10
swagger ×7
java ×2
openapi ×2
spring ×2
spring-boot ×2
swagger-2.0 ×2
swashbuckle ×2
nestjs ×1
openapi.net ×1
spring-mvc ×1
springdoc ×1
springfox ×1
typescript ×1