强大骆驼盒在摇摇欲坠的gen中进行参数

发布于 2025-01-30 10:03:06 字数 618 浏览 4 评论 0原文

问题:< / strong>

我的休息端点带有路由参数,看起来像这样的路线

    [HttpDelete("{id}")]
    public async Task<IActionResult> DeleteDocument([FromRoute] DeleteDocumentRequest request)

,“ deletedocumentRequest”具有一个gettor / settor,

    public Guid Id {get; set;}

但是,当Swagger Gen将其序列序列化为OpenAPI 3.0时,它会产生错误,因为它的情况是类中的属性“ ID”与路由中的属性“ ID”不匹配。

问题:

如何覆盖序列化器将其所有属性更改为骆驼以确保合规性?

使用.NET 6中的Newtonsoft JSON,我尝试使用CamelCasePropertyNamesContractresolver以及覆盖propertyname和createProperties的覆盖,但是控制器端点中的参数不是“属性”的“属性”。

Problem:

I have Rest Endpoint with route params that look something like this

    [HttpDelete("{id}")]
    public async Task<IActionResult> DeleteDocument([FromRoute] DeleteDocumentRequest request)

Where the "DeleteDocumentRequest" has a gettor / settor

    public Guid Id {get; set;}

However, when swagger gen serializes this into OpenApi 3.0, it generates an error because the case of the property "Id" in the class does not match the property "id" in the route.

Question:

How can I override the serializer for it to change all of my properties to camelCase to ensure conformity?

Using Newtonsoft Json in .NET 6, I have tried to use CamelCasePropertyNamesContractResolver as well as overrides for ResolvePropertyName and CreateProperties, but the parameters in the controller endpoint are not "properties" that get hit.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是我以为 2025-02-06 10:03:06

我能够通过在Swagger Gen设置中添加以下内容来解决它。感谢@JSPCAL提供了一个相关问题的链接。

services.AddSwaggerGen(c =>
            {
                c.DescribeAllParametersInCamelCase();
            });

I was able to solve it by adding the following to the Swagger Gen setup. Thanks to @jspcal for the link to a related question.

services.AddSwaggerGen(c =>
            {
                c.DescribeAllParametersInCamelCase();
            });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文