我在Swagger规范中有一个其他定义的枚举:
"action": {
"title": "Action",
"description": "Action to apply to matching requests",
"type": "object",
"enum": [
{"delayAction": {"$ref": "#/definitions/delayAction"}},
{"abortAction": {"$ref": "#/definitions/abortAction"}},
{"traceAction": {"$ref": "#/definitions/traceAction"}}
]
}
Run Code Online (Sandbox Code Playgroud)
并且delayAction,abortAction和traceAction都被定义.
但是在Swagger UI中,模型action是空的.
如何修改我的Swagger定义,以便Swagger UI可以显示action模型中的定义?
最近我正在使用Swagger UI制作API资源管理器.问题是,当我有大量数据时,UI需要很长时间来响应任何交互(即使我选择任何文本,或将数据输入文本字段).
你知道为什么,有什么建议吗?
如何按字母顺序对方法进行排序,例如DELETE,GET,POST,PUT。
我已经阅读了这篇文章,但是它是HTML格式的,但就我而言,我将Swagger集成到了Spring Boot中,因此在创建Docket时需要对其进行排序。
然后我operationOrdering()在Docket中注意到了这种方法,但是我仍然无法使它起作用。
是否可以在 hapi-swagger 中根据用户角色从文档(swagger ui)中隐藏一些 API。我的意思是想我有/employee和/admin两个API所以每当管理员登录招摇UI或招摇文档,以便既/employee和/adminAPI应该在页面上显示,如果员工登录招摇的用户界面,那么它应该只显示/employeeAPI。
我的项目中的 Swagger 文档有多个组。每个组都有一个Docket端点(每个组的成员)都用自定义注释进行标记。例如,这里是Docket身份验证组:
@Bean
public Docket authenticationApis() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("authentication")
.useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(AuthenticationApiGroup.class))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.securitySchemes(Collections.singletonList(securityScheme()))
.securityContexts(Collections.singletonList(securityContext()));
}
Run Code Online (Sandbox Code Playgroud)
Docket所有可用端点还有一个(默认) 。问题是,当我调用文档 URL 时,Swagger UI 默认加载最上面的组.../swagger-ui.html。就我而言,它是身份验证组,因为这些组是按字母顺序排序的。所需的行为是将默认组加载为默认 API 组。我怎样才能做到这一点?
我尝试用 来命名默认值Docket,因此.groupName("all")它是最顶层的组(all < authentication),但这个解决方案有点“脏”,在这种情况下,文档将有两个重复的组(all和default)。
Springfox 2.9.2项目中使用。
我从GitHub导入了一个类似的代码:
档案1: Settings.java
import lombok.Builder;
import lombok.Data;
import org.apache.pdfbox.pdmodel.font.PDFont;
@Data
@Builder
public class Settings {
private PDFont font;
private Integer fontSize;
//code
}
Run Code Online (Sandbox Code Playgroud)
现在这是它的用法
文件2:
private Settings settings = Settings.builder()
.font(DEFAULT_FONT)
.fontSize(DEFAULT_FONT_SIZE)
.build();
Run Code Online (Sandbox Code Playgroud)
请帮我把这两个部分转换成简单的代码我严格不想使用Lombok.
我正在尝试为 OpenAPI 3.0 规范中的响应创建链接。更具体地说,我想提供我的响应之一与其他可用操作之间的已知关系(参见Link Object)。
在我的 Spring Boot 项目中,我使用 Springdoc(版本:1.3.9)来生成 API 文档。根据@ApiResponse#links文档,我尝试使用以下端点代码来实现我的目标:
@GetMapping(value = "/avatar", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Request avatar info", operationId = "requestAvatar")
@ResponseStatus(HttpStatus.OK)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", links = {
@Link(name = "Download Avatar", operationId = "downloadAvatar",
parameters = {
@LinkParameter(name = "userId"),
@LinkParameter(name = "uuid")
})
}),
...
@ResponseBody
ResponseEntity<Avatar> requestAvatar();
Run Code Online (Sandbox Code Playgroud)
不幸的是,除了“无链接”描述之外,我在 Swagger UI 中看不到任何结果。
检查生成的 JSON 规范后,我也没有找到APIlinks的任何密钥requestAvatar。
我在创建过程中是否遗漏了某些内容,@Link或者 …
我将swagger-ui(版本2.0)集成到我的Asp.Net WebApi 4.0项目中.这是我的路由配置:
config.Routes.MapHttpRoute(
name: "Common_Get",
routeTemplate: "common/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional, action = "Get" },
constraints: new { httpMethod = new HttpMethodConstraint("GET") }
);
config.Routes.MapHttpRoute(
name: "Active_Get",
routeTemplate: "active/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional, action = "Get" },
constraints: new { httpMethod = new HttpMethodConstraint("GET") }
);
Run Code Online (Sandbox Code Playgroud)
并且swagger-ui生成文档包含无用的项目.common并active具有相同的控制器+动作.就像这样:
get /common/Advert/GetAdvertise/{id}
get /active/Advert/GetAdvertise/{id}
get /common/award/GetAward/{id}
get /active/award/GetAward/{id}
Run Code Online (Sandbox Code Playgroud)
如何避免这个问题或启用swagger支持区域(无论名称).我可以指定每个控制器的区域.正确的结果可能是这样的:
get /common/Advert/GetAdvertise/{id}
get /active/Award/GetAward/{id}
Run Code Online (Sandbox Code Playgroud) 我有一个 Maven 项目,其中的 API 定义使用 OpenaAPI v3 规范。
我使用 openapi-generator-maven-plugin 生成代码,一切正常。我还可以访问 swagger-ui 并查看和测试我的 API。
问题是我不想两次维护版本号。因此,我想在 api 规范中引用我的 maven pom 中的版本号,而不是冒着过时风险进行复制。
我尝试过maven资源过滤,这似乎有效。由于当我将版本字段放入规范中时,目标文件夹中的 yaml 文件会被很好地替换${project.version},但是当我打开 swagger-ui 时,它会按字面意思打印“${project.version}”而不是实际版本。
这是我的 pom 中的插件配置:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.resources[0].directory}/spec.yml</inputSpec>
<ignoreFileOverride>${project.build.resources[0].directory}/.openapi-codegen-ignore</ignoreFileOverride>
<language>spring</language>
<library>spring-boot</library>
<configOptions>
<!-- Use the newer java.time package instead of outdated java.util-->
<dateLibrary>java8</dateLibrary>
</configOptions>
<apiPackage>${default.package}.api</apiPackage>
<modelPackage>${default.package}.model</modelPackage>
<invokerPackage>${default.package}.invoker</invokerPackage>
<generateApiTests>false</generateApiTests>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
这是我的spec.yml:
openapi: 3.0.0
info: …Run Code Online (Sandbox Code Playgroud) swagger ×7
swagger-ui ×6
java ×5
spring-boot ×3
openapi ×2
springfox ×2
swagger-2.0 ×2
asp.net ×1
hapi-swagger ×1
hapijs ×1
lombok ×1
maven ×1
node.js ×1
performance ×1
springdoc ×1
swashbuckle ×1