提问人:Rajesh Reddy Ananthula 提问时间:9/19/2023 最后编辑:Rajesh Reddy Ananthula 更新时间:9/19/2023 访问量:147
Javascript 代码生成:自$ref属性类型未添加到导入部分,导致“ReferenceError:未定义 XXXXX”
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'
生成的代码:
(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 和 combinedPortfolio 在 YAML 文件的 Portfolio 定义中具有 Portfolio 类型。我尝试使用最新的swagger-codegen-cli-3.0.46.jar生成代码,投资组合类型应该在导入部分,但未添加。为什么投资组合类型不添加到 module.exports、define 和 root.xxxx.api 部分。
测试了 Java 代码和按预期生成的代码。Javascript 不支持 self $ref 吗?
预期代码:
(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';
答: 暂无答案
评论