![](/img/trans.png)
[英]Java - how to generate Swagger UI directly from openapi 3.0 specification
[英]generate UI model from Java -> swagger
<dependency> <groupId>io.swagger.codegen.v3</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>${swagger-codegen-maven-plugin.version}</version> </dependency>
从 swagger-ui.yml 文件(手动编写)创建 UI(打字稿)和 BE(Java)模型 - 我 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency>
I want to write everything in Java (models and endpoints), then somehow generate swagger-ui.yml from java , and then generate typescript models from that swagger-ui.yml file (like i can with swagger.codegen), though I was结合这两种方法不成功。 还是有其他方法(其他依赖项等)可以做到这一点? 我还需要 swagger 文件来包含端点文档,例如使用 springfox-swagger-ui。 (我正在使用 maven,spring-boot-starter-web,java 8,angular13)
这个想法是 swagger 将为您提供“Api”端点(作为接口),您将在 java 中编写“Api 实现”。
例如,从您的 swagger-ui.yml 文件中:
您的 MyappApi class 可能如下所示:
@Api(description = "the myapp API")
@javax.annotation.Generated(...)public interface MyappApi {
... endpoints go here
}
然后你像这样写 MyappApiImpl :
public class MyappApiImpl implements MyappApi {
... override methods here
}
并不是说 typescript 类和 java Api 端点保持同步非常重要。 您不想在 java 中手写所有内容 - 让 swagger 定义 API 实现(服务器端,用于 java),您只定义实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.