question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated models not extending from base interface

See original GitHub issue

I am aware of this issue from before (marked as fixed): https://github.com/cyclosproject/ng-openapi-gen/issues/142 But I am having issues in generating models that extend from base interface. The base interface is imported in child interfaces, but they do not extend from it for some reason.

Schema:

"BaseObjDto": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
  },
 "ChildObjDto": {
        "type": "object",
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseObjDto"
          }
        ],
        "properties": {
          "name": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
},
"AnotherObjDto": {
        "type": "object",
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseObjDto"
          }
        ],
        "properties": {
          "name": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
},

Generated models (base imported as reference but never extends):

export interface BaseObjDto {
  type?: null | string;
}
import { BaseObjDto } from './base-obj-dto';
export interface ChildObjDto {
  name?: null | string;
}
import { BaseObjDto } from './base-obj-dto';
export interface AnotherObjDto {
  name?: null | string;
}

Any idea why this is happening?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
manijakcommented, Oct 27, 2021

Thanks for following up, sorry if this is a duplicate but it seem like this issue was resolved in v16.0.x

This is very confusing as the schema is generated with Swashbuckle Swagger for .net. And they state that it is perfectly valid. https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1942

This is my model in .net

[SwaggerSubType(typeof(ChildObjDto))]
[SwaggerSubType(typeof(AnotherObjDto))]
public abstract class BaseObjDto
{
    public string SomeBaseValue { get; set; }
}
public class ChildObjDto : BaseObjDto
{
    public string Name { get; set; }
}
public class AnotherObjDto : BaseObjDto
{
    public string Name { get; set; }
}
0reactions
micaelboucardcommented, Sep 5, 2022

Sorry @micaelboucard , but I don’t get what is the problem. What was fixed in 0.16.0 is that models didn’t extend the other if they had type: object and allOf in the same level. This currently works. I just added a test for the same models as #177 (comment) and the result is:

export interface Shape {
  name?: string;
}

and

import { Shape } from './shape';
export type Circle = Shape & {
'radius'?: number;
};

So, Circle is actually a Shape.

Can you provide an example of exactly what isn’t working as expected?

Hey @luisfpg ! Thanks for your reply. Sorry, I just saw that the issue was solved back again in recent releases v0.21.0. Just tried with the latest one and everything works now 👏🏽

Thank you for all what you do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript extend an interface as not required
I would like to extend ISuccessResponse interface as Not Required; I can do it as overwrite it but is there an other option?...
Read more >
Extending object-like types with interfaces in TypeScript
Extending multiple interfaces refers to the concept of composition where the interface is designed to extend attributes it needs.
Read more >
Handbook - Interfaces
Not all properties of an interface may be required. Some exist under certain ... Some properties should only be modifiable when an object...
Read more >
Protect Models to Conceal Contents - MATLAB & Simulink
If a top model references two protected models that have such a naming conflict, you cannot protect the top model, generate code for...
Read more >
Extract an interface refactoring - Visual Studio (Windows)
Extract an interface refactoring · Keyboard. Press Ctrl+R, then Ctrl+I. (Your keyboard shortcut may be different based on which profile you've ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found