代码之家  ›  专栏  ›  技术社区  ›  brewphone

发送@PathParam时,Jersey project Swagger UI不发送@HeaderParam

  •  0
  • brewphone  · 技术社区  · 6 年前

    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一起检查发现头根本不在请求中。应该是在招摇过市的用户界面的问题吗? enter image description here

    0 回复  |  直到 6 年前
        1
  •  0
  •   brewphone    5 年前

    @HeaderParam(“Authorization”)就像HTTP的关键字?当我使用“Auth”这样的其他名称时,它就起作用了。