I am using openapi-generator to generate 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. That is awesome, imagine having 10 params side by side as method input, nightmare. 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.
So, is there any way that openapi generator can generate models (classes) with constructors?
Nswag is ganarating actual classes (have constructor and interfaces) but it does not transform query params into Dto.
You can modify the template file modelGeneric.mustache and then specify your custom template directory (-t
) like this:
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