swagger-api / swagger-api/swagger-codegen-generators
Javascript code generation : Self $ref attributes type not adding to import section which leads to "ReferenceError: XXXXX is not defined"
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
JS code generator not working
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.DecisionLensApi) {
root.DecisionLensApi = {};
}
root.DecisionLensApi.Portfolio = factory(root.DecisionLensApi.ApiClient, root.DecisionLensApi.Attributes, root.DecisionLensApi.CustomNames, root.DecisionLensApi.DlResource, root.DecisionLensApi.Fields, root.DecisionLensApi.PortfolioPlanUser, root.DecisionLensApi.PortfolioPlanUsers, root.DecisionLensApi.PortfolioPlans, root.DecisionLensApi.Projects, root.DecisionLensApi.ResourcePools);
}
}(this, function(ApiClient, Attributes, CustomNames, DlResource, Fields, PortfolioPlanUser, PortfolioPlanUsers, PortfolioPlans, Projects, ResourcePools) {
'use strict';
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.DecisionLensApi) {
root.DecisionLensApi = {};
}
root.DecisionLensApi.Portfolio = factory(root.DecisionLensApi.ApiClient, root.DecisionLensApi.Portfolio, root.DecisionLensApi.Attributes, root.DecisionLensApi.CustomNames, root.DecisionLensApi.DlResource, root.DecisionLensApi.Fields, root.DecisionLensApi.PortfolioPlanUser, root.DecisionLensApi.PortfolioPlanUsers, root.DecisionLensApi.PortfolioPlans, root.DecisionLensApi.Projects, root.DecisionLensApi.ResourcePools);
}
}(this, function(ApiClient, Attributes, CustomNames, DlResource, Fields, Portfolio, 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 ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the JavaScript generator's handling of self-referencing $ref values and compare the generated Portfolio module with the expected AMD, CommonJS, and browser-global sections shown in the issue. Done means Portfolio is included consistently in those dependency lists and factory arguments, without breaking the other generated model imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100