[英]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>
to create UI (typescript) and BE (java) models from swagger-ui.yml file (manually written) - I从 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 unsuccessfull with combining these two approaches. 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结合这两种方法不成功。 Or is there some other way (other dependencies etc) to do this?还是有其他方法(其他依赖项等)可以做到这一点? I also need the swagger file to include endpoints documentation, like using springfox-swagger-ui.我还需要 swagger 文件来包含端点文档,例如使用 springfox-swagger-ui。 (I am using maven, spring-boot-starter-web, java 8, angular13) (我正在使用 maven,spring-boot-starter-web,java 8,angular13)
The idea is that swagger will give you the "Api" endpoints (as interfaces) and you will write the "Api Implementation" in java.这个想法是 swagger 将为您提供“Api”端点(作为接口),您将在 java 中编写“Api 实现”。
For example, from your swagger-ui.yml file:例如,从您的 swagger-ui.yml 文件中:
Your MyappApi class might look like this:您的 MyappApi class 可能如下所示:
@Api(description = "the myapp API")
@javax.annotation.Generated(...)public interface MyappApi {
... endpoints go here
}
And then you write MyappApiImpl like this:然后你像这样写 MyappApiImpl :
public class MyappApiImpl implements MyappApi {
... override methods here
}
Not that its very important the typescript classes and java Api endpoints are kept in sync.并不是说 typescript 类和 java Api 端点保持同步非常重要。 You do not want to hand write everything in java - let swagger define the API implementation (server side, for java) and you define the implementations only.您不想在 java 中手写所有内容 - 让 swagger 定义 API 实现(服务器端,用于 java),您只定义实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.