[英]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.