简体   繁体   English

在 helidon 项目中自动添加 openapi 文件

[英]Automatic add openapi file in helidon project

I want instrument for automatic generate openapi in my helidon project (Java 1.8, helidon SE 1.3.1)我想要在我的 helidon 项目(Java 1.8,helidon SE 1.3.1)中自动生成 openapi 的工具

I read documenttation/example and make:我阅读文档/示例并制作:

  1. add depends in maven添加依赖于 maven
  2. add openapi.yml in META-INF在 META-INF 中添加 openapi.yml
  3. add endpoint for router.为路由器添加端点。
  4. add apifilter and apimodelreader添加 apifilter 和 apimodelreader

pom.xml: pom.xml:

<dependency>
   <groupId>io.helidon.openapi</groupId>
   <artifactId>helidon-openapi</artifactId>
   <version>1.3.1</version>
</dependency>

main.java: main.java:

return Routing.builder()
                .register(JsonSupport.create())
                .register(health)                   // Health at "/health"
                .register(metrics)                  // Metrics at "/metrics"
                .register("/file", fileService)
                .register("/card", cardService)
                .register(OpenAPISupport.create(config))
                .build();

application.yaml应用程序.yaml

openapi:
  filter: ru.ittest.feezio.openapi.SimpleAPIFilter
  model:
    reader: ru.ittest.feezio.openapi.SimpleAPIModelReader

Now I have openapi document in endpoint: http://127.0.0.1:8456/openapi And it is my openapi.yml.现在我在端点中有openapi文档: http://127.0.0.1:8456/openapi这是我的openapi.yml。 But I don't want write by hand openapi.yml, I want auto generate yml for my classes: fileService and cardService.但我不想手动编写 openapi.yml,我想为我的类自动生成 yml:fileService 和 cardService。 This classes work and response success (API work, I make documentation now)此类工作和响应成功(API 工作,我现在制作文档)

As the OP noted, Helidon SE cannot automatically generate the OpenAPI document for your app.正如 OP 所指出的,Helidon SE 无法为您的应用自动生成 OpenAPI 文档。 You provide either a static openapi.yml file or your own model reader and/or filter classes.您提供static openapi.yml文件您自己的 model 阅读器和/或过滤器类。 You can provide the static file and the classes if you want to but that is not required.如果需要,您可以提供 static 文件和类,但这不是必需的。 For other interested readers here's the doc .对于其他感兴趣的读者,这里是doc

Probably most developers who want OpenAPI support in their Helidon SE app will use a tool to define their API and then export the OpenAPI document from the tool, adding that YAML file to their application JAR (typically at META-INF/openapi.yml ).可能大多数希望在其 Helidon SE 应用程序中支持 OpenAPI 的开发人员将使用一个工具来定义他们的 API,然后从该工具导出 OpenAPI 文档,并将 YAML 文件添加到他们的应用程序META-INF/openapi.yml中。

Note that if you use Helidon MP (which implements MicroProfile OpenAPI) and add the normal JAX-RS annotations to your endpoints, then Helidon MP can generate the OpenAPI document for you automatically.请注意,如果您使用 Helidon MP(实现 MicroProfile OpenAPI)并将普通的 JAX-RS 注释添加到您的端点,那么 Helidon MP 可以自动为您生成 OpenAPI 文档。 Here's the doc for that.这是文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM