简体   繁体   English

从 Java -> swagger 生成 UI model

[英]generate UI model from Java -> swagger

  • I can use我可以用
     <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)模型 - 我
    do NOT want swagger to generate endpoints (I want to write them in java).不希望 swagger 生成端点(我想用 java 编写它们)。
  • I can also access new swagger file at runtime with springfox-swagger2 + springfox-swagger- ui我还可以在运行时使用 springfox-swagger2 + springfox-swagger-ui 访问新的 swagger 文件
    (2.9.2) (2.9.2)
     <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.

相关问题 Java - 如何直接从 openapi 3.0 规范生成 Swagger UI - Java - how to generate Swagger UI directly from openapi 3.0 specification 从Java自动生成Swagger文档 - Automatic generate Swagger documentation from Java 在 swagger-ui 中更改 java.sql.Time 的模型模式 - Change model schema for java.sql.Time in swagger-ui 可选的<?> java类,模型中的字段,未在swagger ui上显示 - Optional<?> field in java class, model, not showing on swagger ui 如何通过Swagger将Java POJO转换为JSON模型和示例,如swagger-ui中所示 - How to convert Java POJO to JSON model and example through Swagger like it shows in swagger-ui 从java Annotations生成swagger docus,缺少安全定义 - Generate swagger docus from java Annotations, missing security definitions Java或JavaScript库可从Swagger,RAML或API蓝图生成HTML - Java or JavaScript library to generate HTML from Swagger, RAML or API Blueprint 从Swagger API for Java REST生成单元测试代码 - Generate Unit Test Code from Swagger API for Java REST 从swagger API生成Java Google端点服务器存根 - generate java google endpoints server stub from swagger API 从swagger yaml生成Java方法以与我自己的方法一起使用 - Generate Java methods from swagger yaml to be used with my own methods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM