ng-openapi-gen icon indicating copy to clipboard operation
ng-openapi-gen copied to clipboard

Support custom file suffixes/prefixes/names

Open deniszholob opened this issue 3 years ago • 8 comments

Does the tool support adding custom suffixes like attaching a .model.ts or .enum.ts to the end of every interface/enum generated? If not, can this be added in?

deniszholob avatar Jan 20 '22 16:01 deniszholob

Top-level enums are handled as models. You can set custom prefix / suffix for models or services in the configuration file.

luisfpg avatar Jan 20 '22 16:01 luisfpg

You cannot set them via a regex rule or something like that though right? SAs an example, say if its a pets-store-results.ts => pets-store-results.model.ts and if its pets-store-types.ts => pets-store-types.enum.ts or by default set it to *.models and *.enum if it ends with *-types.ts in other words, regex *-types.ts replace with *types.enum.ts

deniszholob avatar Jan 20 '22 16:01 deniszholob

No. Also, take into account that it's not just renaming a file. The class name is renamed accordingly too, and it affects all imports and references from other models and services.

luisfpg avatar Jan 20 '22 16:01 luisfpg

I wasnt really trying to rename the classes, shouldnt be affected by the filename right, i would have assumed both are driven by the api.yml itself? I was more thinking as its generating the filenames/imports it would just rename/update the path as defined in the regex config thats all. Maybe im not realizing the complexity as im not sure about the internal workings.

deniszholob avatar Jan 20 '22 17:01 deniszholob

"The Angular way" states that class HelloIamAClass should be placed in the file named hello-i-am-a-class.ts. So, renaming just the file name would break this. Also the file name is explicitly referenced when others import the class (other models or services). Also, trust me, configuring the generator by "just adding a random regex here or there" is not simple at all.

luisfpg avatar Jan 20 '22 17:01 luisfpg

Makes sense, ive tried to use the prefix config with "modelSuffix":".model" and it took my . and replaced that with a - yielding in a -model suffix :( I get you are trying to stick to the angular convention but it also has the .services, .pipes etc... suffixes which is what i am trying to do with the models. Not a huge deal in the long run, but a nice to have.

deniszholob avatar Jan 21 '22 00:01 deniszholob

Actually, the model suffix is for the class name. The file name will be derived from it. So, if you have "modelSuffix": "Model", your model User will be renamed to UserModel, and the corresponding file will be user-model.ts.

luisfpg avatar Jan 21 '22 16:01 luisfpg

Ohhh, so we misunderstood one another, so then my original question is then valid still. Attaching suffixes to file only, not the model name itself.

deniszholob avatar Jan 21 '22 18:01 deniszholob