openapi-contrib / openapi3-generator

Use your API OpenAPI 3 definition to generate code, documentation, and literally anything you need.
Apache License 2.0
90 stars 27 forks source link

Suggestion: overwrite no-overwrite feature #16

Closed caligo-erik closed 5 years ago

caligo-erik commented 5 years ago

First of all: great tool, I am using it for a new project of mine and these "dynamic templates" are really helpful.

To make this tool even greater, I'd suggest the following features:

  1. don't-overwrite flag
  2. delete all folders called 'auto'

    This is what I want to achieve with the suggested features:

    • files containing "dumb code", e.g. routes/auto/$$path$$.js will be overwritten each time
    • files destined for business logic e.g. services/$$path$$.js will be written, but not overwritten.

      Advantages:

    • by deleting the 'auto' folders each time, all unused/old files will be deleted.
    • business-logic-code-files will be preserved. No more accidental losses. If you want to to re-generate a specific file, e.g. to track changes in the specs, simply move the file to another folder, re-run the code generator, and start merging the changes. For more drastic measures, just remove the don't overwrite flag and all files will be overwritten as usual.
fmvilas commented 5 years ago

I think this is a great idea, especially the "don't overwrite flag". The only thing I don't like about the first idea is the "auto" directory because that conditions the structure of the template when it shouldn't. What about passing another flag with a list of directories you want to "empty" each time? You could have something like this:

og -o ./my-docs --rm the-dumb-code --rm the-other-dumb-code-directory --no-overwrite services/* openapi.yaml express 

What do you think?

caligo-erik commented 5 years ago

I think this is a great idea, especially the "don't overwrite flag". The only thing I don't like about the first idea is the "auto" directory because that conditions the structure of the template when it shouldn't. What about passing another flag with a list of directories you want to "empty" each time? You could have something like this:

og -o ./my-docs --rm the-dumb-code --rm the-other-dumb-code-directory --no-overwrite services/* openapi.yaml express 

What do you think?

I'd prefer the recursive delete-folder feature, since it requires less maintenance effort. The delete parameter is specified only once and can be copied to other projects without any problems. This makes it easy to impose as a standard for your dev team.

I see it less a conditioning of the structure and more of a providing useful information such as: "you are about to edit code that is likely to be overwritten. Go away. Nothing important happens here." Example:

fmvilas commented 5 years ago

Fixed in #17. Thanks!