Javascript code generation : Self $ref attributes type not adding to import section which leads to “ReferenceError: XXXXX is not defined”

Swagger.yaml:

openapi: 3.0.1
info:
  title: Test API
  version: "1.0"
servers:
  - url: http://localhost:9005/v1
  - url: https://localhost:9005/v1
security:
  - OAuth2: []
components:
  schemas:
    Portfolio:
      allOf:
        - $ref: '#/components/schemas/DlResource'
        - type: object
          properties:
            name:
              type: string
            description:
              type: string
            isArchived:
              type: boolean
            baselinePortfolioPlanUser:
              $ref: '#/components/schemas/PortfolioPlanUser'
            fields:
              $ref: '#/components/schemas/Fields'
            projects:
              $ref: '#/components/schemas/Projects'
            portfolioPlans:
              $ref: '#/components/schemas/PortfolioPlans'
            portfolioPlanUsers:
              $ref: '#/components/schemas/PortfolioPlanUsers'
            attributes:
              $ref: '#/components/schemas/Attributes'
            isCombined:
              type: boolean
            userRegistrationToken:
              type: string
              description: user registration token string
            subPortfolios:
              $ref: '#/components/schemas/Portfolio'
            combinedPortfolios:
              $ref: '#/components/schemas/Portfolio'
            resourcePools:
              $ref: '#/components/schemas/ResourcePools'
            totalBudget:
              type: number
              format: double
              default: 0.0
            newNotificationsCount:
              type: integer
            customNames:
              $ref: '#/components/schemas/CustomNames'

Generated code:

(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['ApiClient', 'model/Attributes', 'model/CustomNames', 'model/DlResource', 'model/Fields', 'model/PortfolioPlanUser', 'model/PortfolioPlanUsers', 'model/PortfolioPlans', 'model/Projects', 'model/ResourcePools'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('../ApiClient'), require('./Attributes'), require('./CustomNames'), require('./DlResource'), require('./Fields'), require('./PortfolioPlanUser'), require('./PortfolioPlanUsers'), require('./PortfolioPlans'), require('./Projects'), require('./ResourcePools'));
} else {
// Browser globals (root is window)
if (!root.TestApi) {
root.TestApi = {};
}
root.TestApi.Portfolio = factory(root.TestApi.ApiClient, root.TestApi.Attributes, root.TestApi.CustomNames, root.TestApi.DlResource, root.TestApi.Fields, root.TestApi.PortfolioPlanUser, root.TestApi.PortfolioPlanUsers, root.TestApi.PortfolioPlans, root.TestApi.Projects, root.TestApi.ResourcePools);
}
}(this, function(ApiClient, Attributes, CustomNames, DlResource, Fields, PortfolioPlanUser, PortfolioPlanUsers, PortfolioPlans, Projects, ResourcePools) {
'use strict';

subPortfolio and combinedPortfolio has Portfolio type in Portfolio definition in YAML file. I have tried to generate the code with latest swagger-codegen-cli-3.0.46.jar, Portfolio type should be in import section but not added. Why Portfolio type not adding to module.exports, define and root.xxxx.api section.

Tested Java code and code generated as expected. Is self $ref not supported for Javascript ?

Expected code:

(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['ApiClient', 'model/Attributes', 'model/Portfolio', 'model/CustomNames', 'model/DlResource', 'model/Fields', 'model/PortfolioPlanUser', 'model/PortfolioPlanUsers', 'model/PortfolioPlans', 'model/Projects', 'model/ResourcePools'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('../ApiClient'), require('./Portfolio'), require('./Attributes'), require('./CustomNames'), require('./DlResource'), require('./Fields'), require('./PortfolioPlanUser'), require('./PortfolioPlanUsers'), require('./PortfolioPlans'), require('./Projects'), require('./ResourcePools'));
} else {
// Browser globals (root is window)
if (!root.TestApi) {
root.TestApi = {};
}
root.TestApi.Portfolio = factory(root.TestApi.ApiClient, root.TestApi.Portfolio, root.TestApi.Attributes, root.TestApi.CustomNames, root.TestApi.DlResource, root.TestApi.Fields, root.TestApi.PortfolioPlanUser, root.TestApi.PortfolioPlanUsers, root.TestApi.PortfolioPlans, root.TestApi.Projects, root.TestApi.ResourcePools);
}
}(this, function(ApiClient, Attributes, CustomNames, DlResource, Fields, Portfolio, PortfolioPlanUser, PortfolioPlanUsers, PortfolioPlans, Projects, ResourcePools) {
'use strict';