我正在开发一个简单的应用程序,我想在其中读取远程URL的文件,并将其添加到 @exampleObject
中。我能够使用CustomClass schemafilereader实现Oasfilter
,但唯一的问题是,我需要在ref中手动指定文件的 name
,例如@@ code>@ exampleObject(name =“ example1”,ref =“ example1.json”)
。
由于我正在阅读URL,因此可能有很多文件,并且我不知道所有文件的名称,因此我需要一种方法,可以在其中直接直接添加 @exampleObject
而无需指定 ref [。相反,它应该从]示例
中读取所有数据。有人可以指定有关如何实现这一目标的逻辑吗?
我已经在github上发布了完整的代码: https://github.com/aravinda93/code-with/code-with -Quarkus 。
到目前为止,我通过指定 ref
手动将2个文件添加到我的 @exampleObject
,但是我需要一种动态方法来添加>中存在的所有3个文件。 Resourses/jsonfiles
,而无需为所有文件提供 Ref
。
要运行该应用程序,请按照以下步骤:
- 打开项目的终端并运行
MVN编译Quarkus:dev
- 在命令行中按
d
,这应该打开 Swagger-UI
。
- 从
Smallrye OpenAPI
展开 Swagger-UI
- 展开
api/generate
,在示例中我们将仅看到2个文件。我需要一种方法来获取所有3个字段,而无需为所有这些字段指定 Ref
。
I am developing a simple application where I would like to read the files from a remote URL and add them to the @ExampleObject
. I am able to achieve this using CustomClass SchemaFileReader implements OASFilter
but the only problem is that I need to manually specify the name
of the file in the ref such as @ExampleObject(name = "Example1", ref = "Example1.json")
.
Since I am reading the URL there can be many files and I do not know the name of all the files so I need an approach where I can add the @ExampleObject
dynamically directly without specifying ref
. Rather it should read all the data from the examples
. Can someone please specify some logic on how to achieve this?
I have posted my complete code on GitHub: https://github.com/Aravinda93/code-with-quarkus.
As of now, I have added manually 2 files to my @ExampleObject
by specifying the ref
but I need a dynamic approach to add all the 3 files present in the resourses/jsonfiles
without providing the ref
for all the files individually.
To run the application, please follow the following steps:
- Open the terminal for the project and run
mvn compile quarkus:dev
- Press
d
in the command line this should open the Swagger-UI
.
- Select
swagger-ui
from SmallRye OpenAPI
- Expand
api/generate
and there we will see only 2 files under examples. I need an approach to get all 3 field without specifying the ref
for all of them.
发布评论
评论(1)
在尝试了一些事情之后,最后对我有用。在此处发布,因为它对将来可能对某人很有用:
以下是我的
RestControllerSponse
:以下是我的
schemafileReader
,它具有读取所有文件和具有文件和各个子文件符的能力获取文件内容并添加到示例
,将所需的URL传递到getFolderData
方法:After trying some things, finally, this worked for me. Posting here as it can be useful to someone in the future:
Following is my
RestControllerResponse
:Following is my
SchemaFileReader
which has the capability to read all files and respective subfolder with files and get the file contents and add toexamples
, pass the required URL to thegetFolderData
method: