Java Jersey项目使用了以下夸张的核心:
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.0.2</version>
</dependency>
文档链接指向“openapi.json”。Swagger UI dist 3.20.5版下载自
here
. Java代码如下:
@Path("/auth")
public class TestConttroller {
@GET
@Path("/{id}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response testGet(
@DefaultValue("") @HeaderParam("Authorization") String a,
@DefaultValue("") @PathParam("id") String id)
{
return Response.ok().build();
}
当邮递员发出请求时,一切正常。但是,从下面的Swagger UI中,头参数字符串“a”是空字符串,而路径参数字符串是好的。openapi.json中的部分如下:
"paths" : {
"/auth/{id}" : {
"get" : {
"operationId" : "testGet",
"parameters" : [ {
"name" : "Authorization",
"in" : "header",
"schema" : {
"type" : "string",
"default" : ""
}
}, {
"name" : "id",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string",
"default" : ""
}
} ],
"responses" : {
"default" : {
"description" : "default response",
"content" : {
"application/json" : { },
"application/xml" : { }
}
}
}
}
}
与WireShark一起检查发现头根本不在请求中。应该是在招摇过市的用户界面的问题吗?