Description
This is a feature request for a new (optional) generator parameter.
Summary
It should be possible to specify a prefix and/or suffix which will be added to all model type names when generating the types.
Background
The model names generated from the swagger definition have usually quite natural names ... in Java, I got (in my case) for example Supplier, Organization, BusinessUnit.
I also have same-named domain classes in the service implementing the API. Now of course I need to write a mapper between those two, and here I can't import both the domain and the API classes. One of them needs to be written out with full package name in the source, and this is ugly:
private Organization mapOrganization(final
de.zalando.einkaufshelden.purchase_order.api.rest.model.Organization organization) {
For the similar problem previously with Soap services we used the suffix DTO
(for Data Transfer Object) for the objects sent over the wire.
In other projects I've seen a prefix used for all class names to distinguish them from similar ones (think the Swing J* classes).
Proposed solution
There should be two configuration parameters (as a command line parameter in swagger-codegen-cli, as a maven configuration parameter in swagger-codegen-maven-plugin) for specifying a prefix and a suffix to be appended to the model names. Default values would be the empty string. (My name proposals would be modelNamePrefix
and modelNameSuffix
.)
These could be applied in DefaultCodegen.toModelName before passing the name to the sanitizing transformation.
Alternatively there could be also one single parameter somehow specifying the complete transformation, using a regular expression replacement or similar.
UPDATE
API client generators that need to be updated to support model prefix/suffix:
- Android
- C++
- C# (Feature/1255 suffix+prefix for model name #2211)
- Clojure
- Dart
- Flash
- Go
- Javascript ([JavaScript] Add model name prefix/suffix to JavaScript client #2300)
- Java (Feature/1255 suffix+prefix for model name #2211)
- ObjC ([ObjC] add prefix and suffix support to ObjC models #2267)
- Perl ([PHP][Python][Perl] add prefix/suffix support to model name #2261)
- PHP ([PHP][Python][Perl] add prefix/suffix support to model name #2261)
- Python (JS client: allOf mishandled, composition impossible #2161)
- Ruby ([TypeScript] add prefix, suffix to TS model #2272)
- Scala
- Swift
- TypeScript ([Ruby] add prefix, suffix support to Ruby's model #2270)