Skip to content

Add modelNamePrefix/modelNameSuffix settings for generated beans - #519

Open
matheusandre1 wants to merge 1 commit into
Apitomy:mainfrom
matheusandre1:issue518
Open

matheusandre1 wants to merge 1 commit into
Apitomy:mainfrom
matheusandre1:issue518

Conversation

@matheusandre1

Copy link
Copy Markdown
Contributor

Closes: #518

Problem

classNamePrefix and classNameSuffix are applied in CodegenUtil.toClassName(...), which is used
for both beans and JAX-RS interfaces. Setting classNameSuffix=Dto gives BeerDto, but also
BeersResourceDto. There is no way to rename only the models.

The use case comes from quarkiverse/quarkus-openapi-generator#1724: generated models are DTOs that
live next to hand-written domain classes with the same simple names.

Change

  • New modelNamePrefix and modelNameSuffix in JaxRsProjectSettings (default "").
  • New CodegenUtil.toBeanClassName(...), used wherever a bean class name is resolved:
    OpenApi2JaxRs#generateJavaBean (bean name and the $ref lookup) and
    CodegenUtil#schemaRefToFQCN.
  • toClassName(...) is unchanged and is now used only for interfaces.

For beans the settings are combined:
classNamePrefix + modelNamePrefix + name + modelNameSuffix + classNameSuffix.

Result

With modelNamePrefix=My and modelNameSuffix=Dto on beer-api.json:

Before After
beans/Beer beans/MyBeerDto
beans/Brewery beans/MyBreweryDto
BeersResource BeersResource
BreweriesResource BreweriesResource

Interfaces reference the renamed beans, e.g. MyBeerDto getBeer(...).

Compatibility

Both settings default to empty, so existing output is unchanged. The existing prefixed/suffixed
tests pass without changes to their expected files.

Tests and docs

  • OpenApi2JaxRsTest#testGenerateFullModelSuffixed with expected files in
    _expected-full-model-suffixed/.
  • configuration-reference.md and maven-plugin.md document the new settings.

Open question

I chose to combine the model prefix/suffix with the class-level ones rather than replace them for
beans. Happy to switch if replacing is preferred.

@matheusandre1

Copy link
Copy Markdown
Contributor Author

cc: @mathecruz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support a class name suffix/prefix that applies only to generated beans

1 participant