嵌入式摇摇欲坠会产生X-WWW形式的肉体编码的身体缺少什么?

发布于 2025-02-03 12:02:43 字数 1522 浏览 2 评论 0原文

我正在尝试找出为什么OpenAPI Generator生成的春季服务器在带有X-WWW-Form-urlenCoded Body的Postman Post请求中适当接受“ user = foo”,“ password = bar”的请求(如预期)使用Springfox-Swagger2嵌入服务器中的Swagger页面生成了一个

curl -X 'POST' \
  'http://localhost:8080/v1.0/login?username=foo&password=bar' \
  -H 'accept: */*' \
  -d ''

请求,该请求返回415个未支撑的媒体类型。对于记录,来自OpenAPI规范的生成的Java客户端显示相同的行为。生成的Java方法看起来像:(

    @Operation(
        operationId = "loginPost",
        responses = {
            @ApiResponse(responseCode = "200", description = "User successfully logged in."),
            @ApiResponse(responseCode = "400", description = "User login failed."),
            @ApiResponse(responseCode = "415", description = "Unsupported Media Type")
        }
    )
    @RequestMapping(
        method = RequestMethod.POST,
        value = "/login",
        consumes = { "application/x-www-form-urlencoded" }
    )
    default ResponseEntity<Void> loginPost(
        @Parameter(name = "username", description = "", required = true) @Valid @RequestParam(value = "username", required = true) String username,
        @Parameter(name = "password", description = "", required = true) @Valid @RequestParam(value = "password", required = true) String password
    ) {
        return getDelegate().loginPost(username, password);
    }

自动生成,我的代码在getDelegate()委托)中。

我的猜测是,生成的Java代码上的属性略有关闭,因此我想找出需要修复的内容,以便我可以向OpenAPI Generator Project报告一个错误,希望使用补丁。

我看到的原因是什么?

I am trying to find out why my Spring server generated by OpenAPI generator properly accepts requests with "user=foo", "password=bar" in a Postman POST request with x-www-form-urlencoded body (as expected), but the Swagger page embedded in the server using springfox-swagger2 generates a

curl -X 'POST' \
  'http://localhost:8080/v1.0/login?username=foo&password=bar' \
  -H 'accept: */*' \
  -d ''

request, which returns a 415 Unsupported Media Type. For the record, the generated Java client from the OpenAPI specification shows the same behavior. The generated Java method looks like:

    @Operation(
        operationId = "loginPost",
        responses = {
            @ApiResponse(responseCode = "200", description = "User successfully logged in."),
            @ApiResponse(responseCode = "400", description = "User login failed."),
            @ApiResponse(responseCode = "415", description = "Unsupported Media Type")
        }
    )
    @RequestMapping(
        method = RequestMethod.POST,
        value = "/login",
        consumes = { "application/x-www-form-urlencoded" }
    )
    default ResponseEntity<Void> loginPost(
        @Parameter(name = "username", description = "", required = true) @Valid @RequestParam(value = "username", required = true) String username,
        @Parameter(name = "password", description = "", required = true) @Valid @RequestParam(value = "password", required = true) String password
    ) {
        return getDelegate().loginPost(username, password);
    }

(automatically generated, my code is in the getDelegate() delegate).

My guess is that the attributes on the generated Java code is slightly off, so I would like to find out what needs to be fixed so I can report a bug to the OpenAPI generator project, hopefully with a patch.

What is the reason for what I see?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文