openapi-generator-plus icon indicating copy to clipboard operation
openapi-generator-plus copied to clipboard

Allow file generation exclusion

Open Nirei opened this issue 3 years ago • 3 comments

It would be nice to have some mechanism to exclude certain files from being generated.

For example, a list of files in some kind of .openapi-generator-plus-ignore file. This would come in handy when you only need a part of an implementation or don't want certain files (i.e.: a README or impl file) to regenerate each time the command is run.

Nirei avatar Nov 11 '21 17:11 Nirei

I've shuffled over the code for a while now and it would seem that individual file responsibility is delegated to the client generators? So this might be a bit of a fuzz to implement.

Assuming that's correct:

  • Maybe, to do it in a backwards compatible way, it'd be possible to optionally allow generators to access such a list of filenames and let them inhibit themselves.
  • If backwards compatibility is not an issue, it'd might be cleaner to make individual generators send objects describing files back to openapi-generator-plus and let it handle the writing responsibility?

Nirei avatar Nov 11 '21 21:11 Nirei

@Nirei Thanks for your comments and thoughts. Yes, that's right, generators do currently take on the responsibility of writing all of their files. There is a generator-common module that they all use, which includes the emit function... so it would be possible to add support there and then have it adopted in all generators quite easily.

It's interesting to consider whether generators should be responsible for outputting their own files... I think that's still the right approach, as there could be a variety of mechanisms for outputting files.

The .ignore file idea is a good one. If support for it was added to that emit function, I presume it would look like a function that takes an output filename and then it looks in that dir for the ignore file and all parent dirs to then check for a matching pattern, using glob?

Are you keen to try implementing this?

karlvr avatar Nov 15 '21 02:11 karlvr

Why, yes! I can sure give it a try 😄

Nirei avatar Nov 15 '21 17:11 Nirei