3

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.

1

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.