blue-veery-gmbh / spring-rest-2-ts

spring rest 2 ts is typescript generator which produces data model and services in typescript based on Spring MVC annotations. It supports generation for Angular and React
MIT License
64 stars 17 forks source link

How to add custom imports on generators #23

Closed BloodWorkXGaming closed 2 years ago

BloodWorkXGaming commented 2 years ago

Hello everyone,

This is a very usefull Project! However our frontend is based on axios and therefore I modifed the fetch based client to be axios based. My current problem is adding the custom imports that are needed at the top like

import axios from 'axios';
import { AxiosResponse } from 'axios';

is there any way to add those?

Here is a gist of my attempt: https://gist.github.com/BloodWorkXGaming/30ae1c0517d191b12b2f5089d0130145

Thank you! :)

tomasz-wozniak75 commented 2 years ago

Hey Thanks for the feedback, we really appreciate that :) Coming to your problem I see that you've created already external module for axios and interfaces which you want to use from that module (lines 27-30). All you need to do, is to add to your services type usage of axios types, using method `.addComplexTypeUsage(complexType) Please check in angular generator Angular4ImplementationGenerator on line 283 it will clarify what you need to do. After that change, imports will be generated. In case of any problem just ask I wish you good luck with the implementation and if you would like to contribute your axios generator it will be welcome ;) Tomasz

BloodWorkXGaming commented 2 years ago

Awesome, thank you! That was easier than expected!

Had to do a smal workaround with new TSClass("default as axios", axiosModule, this); to get the main axios object, as imports seem to always be inside braces.

I will have to test the axios impl a few more days but then I'll gladly contribute it :)

tomasz-wozniak75 commented 2 years ago

great :) yes we don't support default exports but it is easy to add, we need to add a flag on scoped type that is exported by default and based on that info in TSImport generate import in different way. I will do it in the next release