Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rajesh505 opened this issue Sep 18, 2023 · 0 comments

Comments

@rajesh505
Copy link

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant