Skip to content

Allow modifying the generated model names by prefix or suffix #1255

Open
@ePaul

Description

@ePaul

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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions