Swagger/OpenAPI-如何在Spring Boot项目中记录导入的模块?
我有一个身份验证模块,该模块在我们的项目中导入以提供与身份验证相关的API。
appconfig.java
@Configuration
@ComponentScan({"com.my.package.ldap.security"})
@EnableCaching
@EnableRetry
public class ApplicationConfig {
...
}
我在项目中配置了Swagger/OpenAPI,我希望找到一种管理这些导入的端点的方法:
具体而言,我希望在示例对象的字段。现在,默认情况下将其按字母顺序排序。 这样做的原因是因为许多这些字段都是“可选的”,我们必须每次从示例对象中删除这些字段,以便对用户进行浪费的时间来验证。
我已经尝试使用@jsonpropertyorder
注释对象,但没有任何更改:
@JsonPropertyOrder({
"domain",
"username",
"password"
})
有什么方法可以实现这一目标吗?
I have an authentication module which is imported inside our projects to provide authentication related APIs.
AppConfig.java
@Configuration
@ComponentScan({"com.my.package.ldap.security"})
@EnableCaching
@EnableRetry
public class ApplicationConfig {
...
}
I've configured Swagger/OpenAPI in my projects and I wish to find a way to manage these imported endpoints:
Specifically, I wish to set an order on the Example object's fields. Right now it is sorted alphabetically by default.
The reason for doing that is because a lot of these fields are "optional" and we have to remove these fields every time from the example object in order to authenticate a user which is a waste of time.
I've tried annotating the Object with @JsonPropertyOrder
but it makes no change:
@JsonPropertyOrder({
"domain",
"username",
"password"
})
Is there any way to achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了一个小POC。它不是很漂亮或非常扩展,但确实可以按预期工作。也许可以使其更灵活,重新使用元数据对象上的属性位置,但是此示例不包括在内。这样,您可以循环定义和模型,手动完成该框架目前无法做的工作。
另外,请确保不要使它变得太重,因为每当有人打开摇摇晃晃的文档时,它都会被执行。这是一块中间件,可以改变原始的Swagger API定义结构。它不会改变原始的。
I made a small POC. It isn't pretty or very extendible, but it does work as intended. Perhaps one could make it more flexible, re-using the property position on the metadata object, but this example does not include that. This way you can loop definitions and models, manually doing the work that the framework fails to do at the moment.
Also, be sure not to make this too heavy because it will be executed every time someone opens up the swagger documentation. It's a piece of middleware that transforms the original Swagger API definition structure. It does not change the original one.