如何按字母顺序对方法进行排序,例如DELETE,GET,POST,PUT。
我已经阅读了这篇文章,但是它是HTML格式的,但就我而言,我将Swagger集成到了Spring Boot中,因此在创建Docket时需要对其进行排序。
然后我operationOrdering()在Docket中注意到了这种方法,但是我仍然无法使它起作用。
我有一个Spring boot 2应用程序(其余API),并使用Springfox Swagger 2库,包括UI库。当我打开swagger界面时,发现http://localhost:8080/swagger-ui.html所有功能都按预期运行,但是发出了两个请求,在logger中给出了404结果:
http:// localhost:8080 /(没有映射到我的应用程序的根目录)
http:// localhost:8080 / csfr(此映射也不存在,但我知道它代表“跨站点伪造的请求”)
显然Swagger这样做是因为它“支持”某种csfr令牌检查,如此处所述。现在已经进行了几个月的调查,以确定是否可以配置这些404调用,因此我现在正在考虑实现端点。我没有找到有关通常要执行的操作的信息。昂首阔步地期待什么样的标题/令牌,它将对其中的信息有什么作用?我可以使用它来使我的应用程序(或摇摇欲坠的端点)更加安全或可访问吗?简而言之:有什么意义:)?
你们中的任何人都可以为基于Spring MVC的REST API实现Swagger提出其他建议吗?仅供参考,这不是Spring Boot。我已经尝试过Springfox,但是恕我直言,这是一辆越野车。
我无法理解为什么使用Springfox 2.5.0在我的api中没有发送"Authorization:Bearer __".我有以下配置:
private ApiKey apiKey() {
return new ApiKey(
"Authorization", // name: My key - Authorization
"api_key", // keyname: api_key
"header");
}
@Bean
SecurityConfiguration security() {
return new SecurityConfiguration(
null, null, null,
"Docserver2_fwk", // app name
"BEARER", // api key value
ApiKeyVehicle.HEADER, "Authorization", ",");
}
Run Code Online (Sandbox Code Playgroud)
看来我无法在springfox(2.5.0)中发送"Authorization:Bearer Token",这可能吗?,这是一个已知的问题吗?
类似的问题:https://github.com/springfox/springfox/issues/1812
PS:OpenAPI 3.0允许"承载"格式,例如:https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#jwt-bearer-sample
谢谢.
我已经使用 Swagger API 文档配置了一个 Spring Boot 应用程序并配置了 Swagger UI。
我还在一个反向代理后面运行我的后端应用程序,该代理将所有请求映射host:port/api到backend_host:port/,当我在本地本地运行时映射到localhost:8082/api。在生产中应用了类似的映射。
当我从中打开 Swagger UI 时,localhost:8082/api/swagger-ui.html它会在标题下方显示以下几行:
[ 基本 URL: localhost:8080 ]
http://localhost:8082/api/v2/api-docs
当我调用任何休息操作时,swagger 总是尝试针对 localhost:8080 执行它,然后由于相同的来源策略而失败。
我知道使用pathProvider但它只影响基本 URL 的路径部分,而不影响域和端口。所以我只能使用它来将基本 URL 更改为 localhost:8080/api 但我需要将其更改为 localhost:8082/api。有没有办法将主机动态设置为浏览器中活动的当前主机和端口?
.pathProvider (new RelativePathProvider (servletContext) {
@Override
public String getApplicationBasePath() {
return "/api";
}
})
Run Code Online (Sandbox Code Playgroud) 我有这个弹簧控制器:
@RestController
@RequestMapping("/communications")
class CommunicationController(private val service: CommunicationService) {
@ApiOperation(
produces = APPLICATION_JSON_VALUE,
consumes = APPLICATION_JSON_VALUE
)
@GetMapping(
consumes = [APPLICATION_JSON_VALUE],
produces = [APPLICATION_JSON_VALUE]
)
fun findAll(
criterias: CommunicationCriterias,
page: Pageable
): List<CommunicationDTO> = service.findCommunications(criterias, page)
}
Run Code Online (Sandbox Code Playgroud)
当我通过swagger-ui(springfox)界面测试此端点时,出现415: content type invalid错误.似乎content-type: application/json没有在标题中设置.
缺什么 ?
我想大方地记录我的项目。我在项目中添加了大张旗鼓的批注和io.springfox依赖项,但运行时mvn clean package出现很多错误:
PS D:\parent-project> mvn clean package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent-project [pom]
[INFO] module-common-lib [jar]
[INFO] module1 [jar]
[INFO] module2 [jar]
[INFO]
[INFO] ------------< parent-project:parent-project >-------------
[INFO] Building parent-project 0.0.1-SNAPSHOT [1/4]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ parent-project ---
[INFO]
[INFO] -------< parent-project:module-common-lib >-------
[INFO] Building module-common-lib 0.0.1-SNAPSHOT [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module-common-lib ---
[INFO]
[INFO] --- …Run Code Online (Sandbox Code Playgroud) 在我的 Spring Boot 应用程序中,我有一个 DTO 对象,其中包含 DTO 对象的嵌套列表。班级:
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "contact")
public class ContactDTO {
@ApiModelProperty(value = "id", example = "1", hidden = true)
private Long id;
@ApiModelProperty(value = "first name", example = "John")
private String firstName;
@ApiModelProperty(value = "last name", example = "Doe")
private String lastName;
@Builder.Default
@ApiModelProperty(value = "list of phone numbers", name = "phonenumbers")
List<PhoneNumberDTO> phoneNumberDTOList = new ArrayList<>();
}
Run Code Online (Sandbox Code Playgroud)
post 请求的 swagger 示例值:
{
"firstName": "John",
"lastName": "Doe",
"phoneNumberDTOList": [
{ …Run Code Online (Sandbox Code Playgroud) 这是我的第一篇文章,所以请随时留下一些反馈,或者如果我做错了什么:)
我正在使用 spring-boot 和 resteasy :
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.paypal.springboot</groupId>
<artifactId>resteasy-spring-boot-starter</artifactId>
<version>2.3.4-RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 Swagger 来查看我的端点,所以我添加了这个依赖项:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
此依赖项已加载到我的存储库中,一切看起来都不错。
我添加了这个类来制作最简单的配置类:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
当我在调试模式中启动应用程序时,我输入了这个以前的 Bean。一切看起来都很好。
当我启动 Spring 应用程序时:
@SpringBootApplication
@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class,RabbitAutoConfiguration.class})
public class SituationServicesApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(SituationServicesApplication.class, args);
}
@Override …Run Code Online (Sandbox Code Playgroud) 我正在使用通过 Springfox 2.9.2 实现的 Swagger-UI。
我通过在 UiConfiguration 中将“filter”设置为 true 来启用“Filter By tag”。
@Configuration
@EnableSwagger2
@Import({BeanValidatorPluginsConfiguration.class})
//https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
public class SwaggerConfiguration {
.
.
.
@Bean
public UiConfiguration uiConfig() {
return UiConfigurationBuilder.builder()
.defaultModelRendering(ModelRendering.MODEL)
.defaultModelsExpandDepth(-1)
.displayRequestDuration(true)
.displayOperationId(false)
.filter(true)
.deepLinking(true).build();
}
}
Run Code Online (Sandbox Code Playgroud)
但是这个过滤器区分大小写。我需要在没有大小写条件的情况下进行搜索..
我怎样才能让这个标签过滤器不区分大小写..?
springfox ×10
java ×6
swagger ×6
swagger-ui ×6
spring-boot ×5
spring ×2
swagger-2.0 ×2
filter ×1
kotlin ×1
maven ×1
spring-mvc ×1
tags ×1