swagger-api / swagger-api/swagger-codegen

[JAVA] Failed inheritance when generating objects with subtypes

Open
#6,229 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java Feature: Composition / Inheritance Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I am attempting to generate polymorphic Java model objects using a swagger 1.2 JSON file.
I've created a simple project using Gradle and a swagger example from
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/1.2.md#5272-inheritance-example

When the models are generated there is no inheritance. Is there something that I am missing?

Project example uploaded here, https://github.com/jsmithe/swagger-codgen-subtype-test

Swagger-codegen version

2.2.3

Swagger declaration file content or url

https://github.com/jsmithe/swagger-codgen-subtype-test/blob/master/src/main/resources/test.json

Command line used for generation

gradle generateApi
Using Gradle build file similar to that linked in root's readme.
https://github.com/jsmithe/swagger-codgen-subtype-test/blob/master/build.gradle

Steps to reproduce

Generate model with provided test.json

Related issues/PRs

Several old issues that indicate this should be working. Started with #116

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 linked test.json and build.gradle, then run gradle generateApi to reproduce the generated Java models. Compare the subtype models with the inheritance example in the Swagger 1.2 specification and determine where inheritance is lost. Done means the generated models preserve the declared parent/subtype relationships.

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.