The following definition
openapi: 3.0.0
info:
version: 1.0.0
title: Bug
description: |
Bug example
license:
name: CC0
url: https://creativecommons.org/publicdomain/zero/1.0/
components:
schemas:
Base:
discriminator:
propertyName: discriminatorType
mapping:
SubClass: "#/components/schemas/SubClass"
type: object
required:
- discriminatorType
properties:
discriminatorType:
type: string
SubClass:
allOf:
- $ref: "#/components/schemas/Base"
type: object
required:
- discriminatorType
- subClass
- specific
- data
properties:
discriminatorType:
type: string
subClass:
type: string
specific:
type: string
data:
type: string
paths:
/:
get:
operationId: dummy
responses:
"204":
description: Nothing
Generates the following interfaces
export interface Base {
discriminatorType: string;
}
import { Base } from '../models/base';
export type SubClass = Base & {
'discriminatorType': 'SubClass';
'discriminatorType': string;
'subClass': string;
'specific': string;
'data': string;
};
As you can see the discriminatorType field has been duplicated. The first one is taken from the Base class' discriminator mapping and the second one is from the fields in the SubClass. The definition is generated from a Java record and an interface. As a Java record requires that all fields must be defined it's not possible to remove it from the subclass.
As a workaround it's possible to "fix" this by setting the discriminator property as hidden but that simply removes the property from the api definition which can cause issues when using it in other places.
After looking at the code a bit I believe the code here should include a check to see if the property is already added.
https://github.com/cyclosproject/ng-openapi-gen/lib/model.ts#L127
The following definition
Generates the following interfaces
As you can see the
discriminatorTypefield has been duplicated. The first one is taken from theBaseclass' discriminator mapping and the second one is from the fields in theSubClass. The definition is generated from a Java record and an interface. As a Java record requires that all fields must be defined it's not possible to remove it from the subclass.As a workaround it's possible to "fix" this by setting the discriminator property as hidden but that simply removes the property from the api definition which can cause issues when using it in other places.
After looking at the code a bit I believe the code here should include a check to see if the property is already added.
https://github.com/cyclosproject/ng-openapi-gen/lib/model.ts#L127