swagger-api / swagger-api/swagger-codegen-generators

[Java] The discriminator is not implicitly set in constructor of base class

Open
#296 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

For version 2.4.x There is already a solution but only for GSON.

see pull request: https://github.com/swagger-api/swagger-codegen/pull/7075/files/f3c5f57ae37d5c1f382234a7b5778b2ca5ff4371

But this should also be available for version 3.0.5 and also for all java languages.

Proposed solution:
I did the following in my local pojo.mustache file:

{{#discriminator}}
/**
 * Default constructor for implicitly setting the discriminator
 */
 public {{classname}}() {
this.{{discriminator.propertyName}} = this.getClass().getSimpleName();
 }
 {{/discriminator}}

Tests with server models (jackson) and client models (gson) worked as expected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Java pojo.mustache template and compare it with the referenced version 2.4.x pull request. Exercise the generated server models with Jackson and client models with Gson, as described in the issue. Done means the discriminator is implicitly set for version 3.0.5 across all Java languages and both model types behave as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.