swagger-api / swagger-api/swagger-codegen
Allow modifying the generated model names by prefix or suffix
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
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# (#2211)
- Clojure
- Dart
- Flash
- Go
- Javascript (https://github.com/swagger-api/swagger-codegen/pull/2300)
- Java (#2211)
- ObjC (#2267)
- Perl (#2261)
- PHP (#2261)
- Python (#2161)
- Ruby (#2272)
- Scala
- Swift
- TypeScript (#2270)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DefaultCodegen.toModelName, then trace how generator parameters are exposed through swagger-codegen-cli and the swagger-codegen-maven-plugin. Review the checked and unchecked API client generators in the issue, and confirm the prefix and suffix reach model names while retaining empty defaults and existing sanitization behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, clojure, cpp, csharp, dart, go, java, javascript, objective-c, perl, php, python, ruby, scala, swift, typescript
- Domain
- devtools, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100