OpenAPITools / OpenAPITools/openapi-generator

[BUG] Multilevel inheritance not generated correctly

Open
#13,023 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

There is a bug in generating multilevel inheritance.
We tested it in several languages, for example typescript or C#.
I am using the latest version (6.0.1 JAR).

The generated code looks like the following:

    public partial class WeatherForecast : IEquatable<WeatherForecast>, IValidatableObject
    {

        public WeatherForecast(DateTime date = default(DateTime), int temperatureC = default(int), string summary = default(string), string baseProperty = default(string))
        {
            this.Date = date;
            this.TemperatureC = temperatureC;
            this.Summary = summary;
            this.BaseProperty = baseProperty;
        }

        public DateTime Date { get; set; }

        public int TemperatureC { get; set; }

        public int TemperatureF { get; private set; }

        public bool ShouldSerializeTemperatureF()
        {
            return false;
        }

        public string Summary { get; set; }

        public string BaseProperty { get; set; }

    }



    public partial class WeatherForecastBase : IEquatable<WeatherForecastBase>, IValidatableObject
    {
        public WeatherForecastBase(string baseProperty = default(string))
        {
            this.BaseProperty = baseProperty;
        }

        public string BaseProperty { get; set; }

    }



    public partial class WeatherForecastSub : IEquatable<WeatherForecastSub>, IValidatableObject
    {

        public WeatherForecastSub(string subProperty = default(string), string baseProperty = default(string))
        {
            this.SubProperty = subProperty;
            this.BaseProperty = baseProperty;
        }

        public string SubProperty { get; set; }

        public string BaseProperty { get; set; }

    }

Expected code for the WeatherForecastSub class:

public partial class WeatherForecastSub : IEquatable<WeatherForecastSub>, IValidatableObject
    {

        public WeatherForecastSub(string subProperty = default(string), string baseProperty = default(string), DateTime date = default(DateTime), int temperatureC = default(int), string summary = default(string))
        {
            this.SubProperty = subProperty;
            this.BaseProperty = baseProperty;
            this.Date = date;
            this.TemperatureC = temperatureC;
            this.Summary = summary;
        }

        public string BaseProperty { get; set; }

        public string SubProperty { get; set; }

        public DateTime Date { get; set; }

        public int TemperatureC { get; set; }

        public int TemperatureF { get; private set; }

        public bool ShouldSerializeTemperatureF()
        {
            return false;
        }

        public string Summary { get; set; }

    }

In typescript the code looks like the following:

/**
 * 
 * @export
 * @interface WeatherForecast
 */
export interface WeatherForecast {
    /**
     * 
     * @type {string}
     * @memberof WeatherForecast
     */
    'date'?: string;
    /**
     * 
     * @type {number}
     * @memberof WeatherForecast
     */
    'temperatureC'?: number;
    /**
     * 
     * @type {number}
     * @memberof WeatherForecast
     */
    'temperatureF'?: number;
    /**
     * 
     * @type {string}
     * @memberof WeatherForecast
     */
    'summary'?: string | null;
    /**
     * 
     * @type {string}
     * @memberof WeatherForecast
     */
    'baseProperty'?: string | null;
}
/**
 * 
 * @export
 * @interface WeatherForecastBase
 */
export interface WeatherForecastBase {
    /**
     * 
     * @type {string}
     * @memberof WeatherForecastBase
     */
    'baseProperty'?: string | null;
}
/**
 * 
 * @export
 * @interface WeatherForecastSub
 */
export interface WeatherForecastSub {
    /**
     * 
     * @type {string}
     * @memberof WeatherForecastSub
     */
    'subProperty'?: string | null;
    /**
     * 
     * @type {string}
     * @memberof WeatherForecastSub
     */
    'baseProperty'?: string | null;
}

Expected code for WeatherForecastSub:

export interface WeatherForecastSub {
    /**
     * 
     * @type {string}
     * @memberof WeatherForecast
     */
    'date'?: string;
    /**
     * 
     * @type {number}
     * @memberof WeatherForecast
     */
    'temperatureC'?: number;
    /**
     * 
     * @type {number}
     * @memberof WeatherForecast
     */
    'temperatureF'?: number;
    /**
     * 
     * @type {string}
     * @memberof WeatherForecast
     */
    'summary'?: string | null;
    /**
     * 
     * @type {string}
     * @memberof WeatherForecastSub
     */
    'subProperty'?: string | null;
    /**
     * 
     * @type {string}
     * @memberof WeatherForecastSub
     */
    'baseProperty'?: string | null;
}
OpenAPI declaration file content or url

https://gist.github.com/cs-nero/ed1a23f4d848be5eef37864d4c0b5ab3

Steps to reproduce

Use the following command in your cmd:
java -jar .\openapi-generator-cli-6.0.1.jar generate -i swagger.json -g csharp-netcore -o generated --skip-validate-spec

Related issues/PRs

You can see a similar issue here:
https://github.com/OpenAPITools/openapi-generator/issues/3058
They say it was fixed, but at least for C# and TypeScript, it's not working.

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 OpenAPI declaration and reproduce the Java CLI command for the C# generator, then compare the generated WeatherForecastSub output with the expected inheritance shown in the issue. Check the corresponding TypeScript generation as well; done means multilevel inherited properties appear correctly in both generated outputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, openapi, typescript
Domain
api, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.