简体   繁体   English

如何使用具有构造函数的开放式api生成器生成类模型?

[英]How to generate class models with an open api generator that have a constructor?

I am using openapi-generator to generate typescript-fetch. 我正在使用openapi-generator生成typescript-fetch。 I like using openapi-generator because it supports DTO as a query params and if I have like 10 query params method is generated as RequestDto. 我喜欢使用openapi-generator,因为它支持DTO作为查询参数,如果我有10个查询参数,则将方法作为RequestDto生成。 That is awesome, imagine having 10 params side by side as method input, nightmare. 太棒了,想象一下并排有10个参数作为方法输入,噩梦。 Anyway, that is fine but when you use it like this: 无论如何,这很好,但是当您像这样使用它时:

java -jar openapi-generator-cli-4.0.3.jar generate -i ../swagger-spec.json -g typescript-fetch -o api-specs --enable-post-process-file --skip-validate-spec

It will generate models dir but with interfaces in it and not actual classes. 它将生成模型目录,但其中包含接口,而不是实际的类。 I can not say new Interface and it does not make much of a sense to me to manually make 50 classes that implements those interfaces. 我不能说new Interface ,手动创建50个实现这些接口的类对我来说没有多大意义。

So, is there any way that openapi generator can generate models (classes) with constructors? 那么,openapi生成器可以通过构造函数生成模型(类)的任何方式吗?

Nswag is ganarating actual classes (have constructor and interfaces) but it does not transform query params into Dto. Nswag正在整合实际的类(具有构造函数和接口),但它不会将查询参数转换为Dto。

You can modify the template file modelGeneric.mustache and then specify your custom template directory ( -t ) like this: 您可以修改模板文件modelGeneric.mustache ,然后指定自定义模板目录( -t ),如下所示:

java -jar openapi-generator-cli-4.0.3.jar generate -i ../swagger-spec.json \
-g typescript-fetch -o api-specs \
-t ../swagger-templates/typescript-fetch/ \
--enable-post-process-file --skip-validate-spec

暂无
暂无

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

相关问题 打开api 3.0 java代码生成器 - 如何生成实例化列表? - Open api 3.0 java code generator - How to generate instantiated lists? 使用来自 ocelote 的多个定义的 openapi-generator-cli 在 TS 中生成 api 和模型 - Generate api and models in TS with openapi-generator-cli from multiple definitions from ocelote 是否可以使用 Java 中的 Open API 代码生成器生成返回 void 但不返回 Void(对象类型)的 controller? - Is it possible to generate controller which returns void but not Void (object type) using Open API code generator in Java? 使用打开的 api 生成器在 int64 swagger 上不生成模式注释 - pattern annotation doesn't generate on int64 swagger using open api generator 如何从现有的猎鹰 api 生成 Open API 规范? - How to generate Open API specification from existing falcon api? 未从 Open API 生成器向 Swagger 添加安全性 - Security is not added to Swagger from Open API generator 如何使用 openapi-generator-maven-plugin 生成没有属性的基础 model class - How to generate a base model class that has no properties using openapi-generator-maven-plugin 如何仅从 SpringBoot 中的 Open Api 生成 model 类? - How to generate model classes only from Open Api in SpringBoot? 如何使用Swagger Codegen生成具有其数据类型为Currency(java.util)的变量的模型 - How to generate models that have a variable whose data type is Currency(java.util) with Swagger Codegen 如何在没有数组的情况下拥有多个无限对象 - Open API / Swagger - How to have multiple infinite objects without an array - Open API / Swagger
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM