OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.01k stars 6.6k forks source link

[typescript-fetch] Remove barrel imports #12081

Open orrin-naylor-instacart opened 2 years ago

orrin-naylor-instacart commented 2 years ago

Is your feature request related to a problem? Please describe.

At instacart we are power users of openapi-generator. We have thousands of files in the /models directory. Because of the barrel imports, importing one file from models or apis imports everything from models or apis. EG

import {
  GetAdminProductMappingRequestsParamData,
  GetAdminProductMappingRequestsParamDataFromJSON,
  GetAdminProductMappingRequestsParamDataFromJSONTyped,
} from './' // This imports the index.ts file, which imports than exports everything (AKA barrel import)

Parsing all that typescript causes our tests to run significantly slower. We've experimented with manually removing the barrel imports. Which resulted in a ~3x speedup. Individual test ran in 12s rather than 33s.

Describe the solution you'd like

I'd like to add a --noBarrelImports flag to the generator

Describe alternatives you've considered

We tried creating our own .mustache templates. And it worked! It'd be nice to it have built in, so we can continue to get updates and bug fixes.

orrin-naylor-instacart commented 2 years ago

This demonstrates the issue really well

Running a mock test sweet with our no barrel imports version of openAPI 5s Screen Shot 2022-04-07 at 7 27 28 PM With the existing version 15s Screen Shot 2022-04-07 at 7 28 14 PM

The worst part is it continues to scale like this as you add tests. EG I'm running this test 14 times together. No barrel 9s Screen Shot 2022-04-07 at 7 33 57 PM

Existing 28s Screen Shot 2022-04-07 at 7 32 47 PM

orrin-naylor-instacart commented 2 years ago

I might not even need to add a new parameter. If I could just change the defaults templates from generating imports that look like this.

import {
  GetAdminProductMappingRequestsParamData,
  GetAdminProductMappingRequestsParamDataFromJSON,
  GetAdminProductMappingRequestsParamDataFromJSONTyped,
} from './'

To this

import {
  GetAdminProductMappingRequestsParamData,
  GetAdminProductMappingRequestsParamDataFromJSON,
  GetAdminProductMappingRequestsParamDataFromJSONTyped,
} from './GetAdminProductMappingRequestsParamData'

We'd be good. It's not a breaking change. The barrel exports can still exist, but people who choose not to use them can import directly.

orrin-naylor-instacart commented 2 years ago

@macjohnny We finished rooting this issue out of our codebase today. Result: Our CI tests are running in half the time. I'd love to contribute this back to the community. I just need the go ahead so I don't waste my time.

macjohnny commented 2 years ago

Sounds good, happy to review your PR