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.

[BUG] 5.2 Typescript not generating inheritances for allOf

See original GitHub issue

When using the latest version (5.2) with this command:

docker run -v "[output]":/out openapitools/openapi-generator-cli generate -i http://host.docker.internal:64483/swagger/v1/swagger.json -g typescript-angular -o ./out

...
  "IObject": {
	"type": "object",
	"allOf": [
	  {
		"$ref": "#/components/schemas/IBase1"
	  },
	  {
		"$ref": "#/components/schemas/IBase2"
	  }
	],
	"properties": {
	  "x": {
		"type": "string",
		"nullable": true
	  }
	},
	"additionalProperties": false
  },
  "IBase1": {
	"type": "object",
	"properties": {
	  "a": {
		"type": "string",
		"nullable": true
	  }
	},
	"additionalProperties": false
  },
  "IBase2": {
	"type": "object",
	"properties": {
	  "b": {
		"type": "string",
		"nullable": true
	  }
	},
	"additionalProperties": false
  }
...

IObject gets the related interfaces linked, but does not extend them:

import { IBase1 } from './iBase1';
import { IBase2 } from './iBase2';


export interface IObject { 
    x?: string | null;
    a?: string | null;
    b?: string | null;
}

but that’s the result I’d love to see:

import { IBase1 } from './iBase1';
import { IBase2 } from './iBase2';

export interface IObject extends IBase1, IBase2 { 
    x?: string | null;
}

Please don’t tell me this isn’t possible! It took me already a hell of work to make my own Swashbuckle fork understand Interface inheritances.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

2reactions
Tynamixcommented, Dec 6, 2021

The specification tells nothing about discriminator is mandatory! https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/

Quote: OpenAPI lets you combine and extend model definitions using the allOf keyword. allOf takes an array of object definitions that are used for independent validation but together compose a single object. Still, it does not imply a hierarchy between the models. For that purpose, you should include the discriminator.

So, when hierarchy is not important or the allof array does only have one element no discriminator is needed.

For me this is a bug!

1reaction
angelakicommented, Sep 30, 2021

But we are just talking about models here! If they are used with a discriminator behind the curtain is a different thing! I just want my models to be generated clean & corrent!

No hope for it to come back? Is there anything I can do about it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] [typescript] 'allOf' Inheritance causes enums to not be ...
When using allOf , an enum defined in the child object is not generated. openapi-generator version. Discovered with 5.0.0 , validated against ...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
Bug :1523 - "[IDEA] Offload work by distributing trivial ebuild ... could not be found by inherit()" status:RESOLVED resolution:OBSOLETE severity:normal ...
Read more >
Spring Boot Reference Documentation
Executable jars (sometimes called “fat jars”) are archives containing your compiled classes along with all of the jar dependencies that your code needs...
Read more >
Changelog | Finsemble
Fixed a bug where the FinsembleWindow closed event did not work. ... The Typescript interface for Finsemble's API has been made more accurate....
Read more >
CodeSmith Generator Release Notes - Spaces - Confluence
Fixed a bug where template and generated documents were not being opened or saved with the ... Updated all of the CodeSmith Generator...
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