按字母顺序订购SpringDoc操作参数

发布于 2025-01-26 07:36:01 字数 748 浏览 4 评论 0原文

从Springfox迁移-Springdoc

Springfox生成了一个OpenAPI定义,该定义以字母顺序排序所有参数,我已迁移到SpringDoc,但无法找到一种方法来保留参数的Springfox排序(Alpha),例如

,例如控制器:

getPerson(name, address, mobile)

SpringFox生成的OpenAPI定义:

getPersonService(address, mobile, name)

SpringDoc生成的OpenAPI定义:

getPersonService(name, address, mobile)

有属性可以订购生成的定义的其他方面,

springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tagsSorter=alpha
springdoc.writer-with-order-by-keys: true

我找不到 :属性要订购操作参数,是否有设置可以实现此目的?还是可以干净地实现: openapicustomiser操作customizer

Migrating from springfox - springdoc

springfox generated an openApi definition that ordered all the parameters in alphabetical order, I've migrated to springdoc, but have been unable to find a way to keep the springfox ordering(alpha) of the parameters, e.g.

Controller:

getPerson(name, address, mobile)

springfox generated openApi definition:

getPersonService(address, mobile, name)

springdoc generated openApi definition:

getPersonService(name, address, mobile)

There are properties to order other aspects of the generated definition with:

springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tagsSorter=alpha
springdoc.writer-with-order-by-keys: true

I have been unable to find a property to order the operation parameters, is there a setting to accomplish this? or can it be achieved cleanly with:
OpenApiCustomiser or OperationCustomizer

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

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

发布评论

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

评论(2

依 靠 2025-02-02 07:36:02

这是一种使用操作customizer(kotlin语法)的解决方案:

@Bean
fun parameterOrderCustomizer(): OperationCustomizer {
    return OperationCustomizer { operation, _ ->
        operation.apply {
            parameters = parameters?.sortedBy { it.name }
        }
    }
}

如果您使用分组API,请不要忘记还可以通过.addoperationCustomizer(parameterOrderCustomizer())添加它们

Here's a solution using the OperationCustomizer (Kotlin Syntax):

@Bean
fun parameterOrderCustomizer(): OperationCustomizer {
    return OperationCustomizer { operation, _ ->
        operation.apply {
            parameters = parameters?.sortedBy { it.name }
        }
    }
}

and in case youre using grouped apis, dont forget to also add them to the groups via .addOperationCustomizer(parameterOrderCustomizer())

梦毁影碎の 2025-02-02 07:36:02

更新您的application.property文件:

springdoc.writer-with-order-by-keys=true

或在application.yaml文件

springdoc
 writer-with-order-by-keys: true

路径,架构和属性上排序字母上的升序完美地很好地排序

Update your application.property file with:

springdoc.writer-with-order-by-keys=true

or in application.yaml file

springdoc
 writer-with-order-by-keys: true

Paths, schemas and properties is sorted ascending alphabetically perfectly fine

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