Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Don't add unused imports to the generated file(s) #1173

Closed
KaHLK opened this issue Jan 23, 2024 · 3 comments · Fixed by #1178
Closed

Feature: Don't add unused imports to the generated file(s) #1173

KaHLK opened this issue Jan 23, 2024 · 3 comments · Fixed by #1178
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@KaHLK
Copy link
Contributor

KaHLK commented Jan 23, 2024

What are the steps to reproduce this issue?

  1. Use the split, tags, or tags-split mode
  2. Define a custom formData override.
  3. Run orval

What happens?

The generated files all include an import of the custom formData override.

What were you expecting to happen?

The formData override to only be included in files where it is needed.

What versions are you using?

Operating System: macOS 14.2.1
Package Version: 6.23.0

@melloware melloware added the enhancement New feature or request label Jan 23, 2024
@KaHLK
Copy link
Contributor Author

KaHLK commented Jan 23, 2024

I'm more than prepared to tackle this myself, if you deem it relevant for the project.
Only thing I need before moving forward, is any input on the approach to get it implemented. As in: Are there any information that would make it clean to do.
I have taken a quick stab at it in my own project and made a jank approach to it:
(packages/core/src/writers/split-tags-mode.ts:L115)

if (formData && formData.some(f => implementation.includes(f.name))) {
    implementationData += generateMutatorImports({
        mutators: formData,
        oneMore: true
    });
}

I don't really see this as a real solution, just needed to throw something quick together for testing on my local project.

@melloware
Copy link
Collaborator

Sure submit a PR!

@lukaw3d
Copy link
Contributor

lukaw3d commented Jan 24, 2024

If it adds much complexity:

  • TypeScript compilation removes unused imports unless you use preserveValueImports
  • Linters can already auto-fix this (and you can trigger them in afterAllFilesWrite)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants