如何公开其他模型:从 Springfox 迁移到 Springdoc [英] How to expose additional models : Migrating from Springfox to Springdoc

查看:81
本文介绍了如何公开其他模型:从 Springfox 迁移到 Springdoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要公开一些不直接在 REST API 方法中使用的模型.

I need to expose some models which don't used directly in REST API methods.

在 springfox 中,我使用 Docket 的 additionalModels 方法以编程方式将模型添加到规范中:

With springfox I used Docket's additionalModels method to programmatically add models to specification:

docket.additionalModels(
  typeResolver.resolve(XModel1.class),
  typeResolver.resolve(XModel2.class)
)

如何用springdoc来做?

How to do it with springdoc?

我创建了一个带有 dummy-parameter 的虚拟操作,其中包含所有必需的模型.但我觉得这种方法还有改进的空间.

I've created a dummy operation with dummy-parameter which includes all required models. But I feel the approach has space for improvement.

推荐答案

使用 OpenApiCustomiser ,您可以访问 OpenAPI 对象.您可以添加任何您想要的对象/操作,而无需在代码中添加注释.

With OpenApiCustomiser , you have access to the OpenAPI Object. You can add any object/operation you want without having to add annotations on your code.

您可以查看文档了解更多详情:

You can have a look at the documentation for more details:

这篇关于如何公开其他模型:从 Springfox 迁移到 Springdoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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