OpenAPITools / OpenAPITools/openapi-generator

[Question][Java] Trying to generate classes for swagger with variable field names

Open
#5,806 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I need help generating classes for a third party swagger that I can't change (unless there is a way to easily find/replace the instances where this happens.)

Some parts of the definition are like this:

  Trip:
    description: The trip.
    type: object
    properties:
      journeysAvailableByMarket:
        description: Journeys per market.
        type: object
        properties:
          '*':
            type: array
            items:
              $ref: '#/definitions/AvailableJourney'

This ' * ' can return any string, and not have a ' * ' as a name, and can have multiple fields. So, for example, the response could be something like this:

	"journeysAvailableByMarket": {
		"EPA|COR": [
			{ ...
			}
		],
		"COR|EPA": [
			{ ...
			}
		]
	}

When I generate the classes this property becomes this:

  public static final String SERIALIZED_NAME_STAR = "*";
  @SerializedName(SERIALIZED_NAME_STAR)
  private List<AvailableJourney> star = null;

And so the deserialization doesn't work.
Is this possible to do with a swagger defined in this manner?

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

No repository file or test entry point is named. Start by reproducing Java generation and deserialization with the supplied Swagger schema, then trace how the wildcard property is represented; done means generated classes handle arbitrary keys such as EPA|COR and COR|EPA instead of treating * as a literal field.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.