在发送@PathParam时,泽西项目Swagger-UI不会发送@HeaderParam [英] Jersey project Swagger-UI doesn't send @HeaderParam while @PathParam is sent

查看:95
本文介绍了在发送@PathParam时,泽西项目Swagger-UI不会发送@HeaderParam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下Swagger Core的Java Jersey项目:

Java Jersey project using following Swagger Core:

<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可从此处下载. Java代码是这样的:

the document link goes to "openapi.json". Swagger-UI dist ver 3.20.5 is downloaded from here. Java code is like this:

@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"为空字符串,而path-param字符串则为好字符串. openapi.json中的部分在这里:

When sending request from Postman everything works. But when from following Swagger-UI, the header-param string "a" is an empty string while the path-param string is good. The part in openapi.json is here:

  "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一起检查,发现根本没有请求标头. Swagger-UI中应该出现问题吗?

Check with WireShark found the header is not in request at all. Should the problem in Swagger-UI?

推荐答案

@HeaderParam("Authorization")就像HTTP的关键字一样?当我使用"Auth"之类的其他名称时,它会起作用.

@HeaderParam("Authorization") is like a keyword of HTTP? when I used other name like "Auth" then it works.

这篇关于在发送@PathParam时,泽西项目Swagger-UI不会发送@HeaderParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆