Add ng-swagger-gen to automatically generate models and services with

swagger.yaml

Signed-off-by: sshijun <sshijun@vmware.com>
This commit is contained in:
sshijun 2020-01-09 14:17:52 +08:00
parent a3e84380fa
commit 679a6e0b05
5 changed files with 253 additions and 5 deletions

3
.gitignore vendored
View File

@ -34,6 +34,7 @@ src/portal/typings/
src/portal/src/**/*.js
src/portal/src/**/*.js.map
src/portal/src/lib/coverage
src/portal/ng-swagger-gen
**/npm*.log
**/*ngsummary.json
@ -44,4 +45,4 @@ src/portal/src/lib/coverage
src/core/conf/app.conf
src/server/v2.0/models/
src/server/v2.0/restapi/
src/server/v2.0/restapi/

View File

@ -3641,6 +3641,12 @@
"multicast-dns-service-types": "^1.1.0"
}
},
"boolean": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/boolean/-/boolean-3.0.0.tgz",
"integrity": "sha512-OElxJ1lUSinuoUnkpOgLmxp0DC4ytEhODEL6QJU0NpxE/mI4rUSh8h1P1Wkvfi3xQEBcxXR2gBIPNYNuaFcAbQ==",
"dev": true
},
"boxen": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/boxen/-/boxen-3.2.0.tgz",
@ -4103,6 +4109,12 @@
}
}
},
"call-me-maybe": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/call-me-maybe/-/call-me-maybe-1.0.1.tgz",
"integrity": "sha1-JtII6onje1y95gJQoV8DHBak1ms=",
"dev": true
},
"caller-callsite": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/caller-callsite/-/caller-callsite-2.0.0.tgz",
@ -4670,6 +4682,16 @@
}
}
},
"config-chain": {
"version": "1.1.12",
"resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.12.tgz",
"integrity": "sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==",
"dev": true,
"requires": {
"ini": "^1.3.4",
"proto-list": "~1.2.1"
}
},
"configstore": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/configstore/-/configstore-4.0.0.tgz",
@ -5878,6 +5900,12 @@
"next-tick": "^1.0.0"
}
},
"es6-error": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz",
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
"dev": true
},
"es6-iterator": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
@ -6605,6 +6633,12 @@
"mime-types": "^2.1.12"
}
},
"format-util": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/format-util/-/format-util-1.0.4.tgz",
"integrity": "sha512-8eUnkZC88UPFI3YqH6bTlt0H+I2dhWg6HICJS3caSw6AbV1bEu0AUi92tP1HUYxUfyE6wmbz+tf6DonzZrvQJQ==",
"dev": true
},
"forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
@ -6767,6 +6801,50 @@
"is-glob": "^4.0.1"
}
},
"global-agent": {
"version": "2.1.7",
"resolved": "https://registry.npmjs.org/global-agent/-/global-agent-2.1.7.tgz",
"integrity": "sha512-ooK7eqGYZku+LgnbfH/Iv0RJ74XfhrBZDlke1QSzcBt0bw1PmJcnRADPAQuFE+R45pKKDTynAr25SBasY2kvow==",
"dev": true,
"requires": {
"boolean": "^3.0.0",
"core-js": "^3.4.1",
"es6-error": "^4.1.1",
"matcher": "^2.0.0",
"roarr": "^2.14.5",
"semver": "^6.3.0",
"serialize-error": "^5.0.0"
},
"dependencies": {
"core-js": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.2.tgz",
"integrity": "sha512-hIE5dXkRzRvnZ5vhkRfQxUvDxQZmD9oueA08jDYRBKJHx+VIl/Pne/e0A4x9LObEEthC/TqiZybUoNM4tRgnKg==",
"dev": true
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
},
"serialize-error": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-5.0.0.tgz",
"integrity": "sha512-/VtpuyzYf82mHYTtI4QKtwHa79vAdU5OQpNPAmE/0UDdlGT0ZxHwC+J6gXkw29wwoVI8fMPsfcVHOwXtUQYYQA==",
"dev": true,
"requires": {
"type-fest": "^0.8.0"
}
},
"type-fest": {
"version": "0.8.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz",
"integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==",
"dev": true
}
}
},
"global-dirs": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-0.1.1.tgz",
@ -6775,12 +6853,33 @@
"ini": "^1.3.4"
}
},
"global-tunnel-ng": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/global-tunnel-ng/-/global-tunnel-ng-2.7.1.tgz",
"integrity": "sha512-4s+DyciWBV0eK148wqXxcmVAbFVPqtc3sEtUE/GTQfuU80rySLcMhUmHKSHI7/LDj8q0gDYI1lIhRRB7ieRAqg==",
"dev": true,
"requires": {
"encodeurl": "^1.0.2",
"lodash": "^4.17.10",
"npm-conf": "^1.1.3",
"tunnel": "^0.0.6"
}
},
"globals": {
"version": "9.18.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz",
"integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==",
"dev": true
},
"globalthis": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.1.tgz",
"integrity": "sha512-mJPRTc/P39NH/iNG4mXa9aIhNymaQikTrnspeCa2ZuJ+mH2QN/rXwtX3XwKrHqWgUQFbNZKtHM105aHzJalElw==",
"dev": true,
"requires": {
"define-properties": "^1.1.3"
}
},
"globby": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/globby/-/globby-7.1.1.tgz",
@ -8333,7 +8432,7 @@
"dependencies": {
"form-data": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-1.0.1.tgz",
"resolved": "http://registry.npmjs.org/form-data/-/form-data-1.0.1.tgz",
"integrity": "sha1-rjFduaSQf6BlUCMEpm13M0de43w=",
"requires": {
"async": "^2.0.1",
@ -8682,6 +8781,35 @@
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",
"integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM="
},
"json-schema-ref-parser": {
"version": "5.1.3",
"resolved": "https://registry.npmjs.org/json-schema-ref-parser/-/json-schema-ref-parser-5.1.3.tgz",
"integrity": "sha512-CpDFlBwz/6la78hZxyB9FECVKGYjIIl3Ms3KLqFj99W7IIb7D00/RDgc++IGB4BBALl0QRhh5m4q5WNSopvLtQ==",
"dev": true,
"requires": {
"call-me-maybe": "^1.0.1",
"debug": "^3.1.0",
"js-yaml": "^3.12.0",
"ono": "^4.0.6"
},
"dependencies": {
"debug": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"dev": true,
"requires": {
"ms": "^2.1.1"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
}
}
},
"json-schema-traverse": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz",
@ -9856,6 +9984,23 @@
"resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz",
"integrity": "sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg=="
},
"matcher": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/matcher/-/matcher-2.1.0.tgz",
"integrity": "sha512-o+nZr+vtJtgPNklyeUKkkH42OsK8WAfdgaJE2FNxcjLPg+5QbeEoT6vRj8Xq/iv18JlQ9cmKsEu0b94ixWf1YQ==",
"dev": true,
"requires": {
"escape-string-regexp": "^2.0.0"
},
"dependencies": {
"escape-string-regexp": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz",
"integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==",
"dev": true
}
}
},
"md5.js": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
@ -10193,6 +10338,12 @@
"duplexer2": "0.0.2"
}
},
"mustache": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-2.3.2.tgz",
"integrity": "sha512-KpMNwdQsYz3O/SBS1qJ/o3sqUJ5wSb8gb0pul8CO0S56b9Y2ALm8zCfsjPXsqGFfoNBkDwZuZIAjhsZI03gYVQ==",
"dev": true
},
"mutationobserver-shim": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/mutationobserver-shim/-/mutationobserver-shim-0.3.2.tgz",
@ -10251,7 +10402,7 @@
},
"next-tick": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
"resolved": "http://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
},
"ng-packagr": {
@ -10673,6 +10824,20 @@
}
}
},
"ng-swagger-gen": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/ng-swagger-gen/-/ng-swagger-gen-1.8.1.tgz",
"integrity": "sha512-JyvRMgyNk+mx1hS9HdZjN26DiXAZTPQjb5/++es+GFygH4HgmS8m7HM2TSttIS2RUcHw9Enu+wd3AkAU1B+bAg==",
"dev": true,
"requires": {
"argparse": "^1.0.10",
"global-agent": "^2.0.1",
"global-tunnel-ng": "^2.7.1",
"json-schema-ref-parser": "^5.1.3",
"mustache": "^2.3.2",
"npm-conf": "^1.1.3"
}
},
"ngx-clipboard": {
"version": "12.2.1",
"resolved": "https://registry.npmjs.org/ngx-clipboard/-/ngx-clipboard-12.2.1.tgz",
@ -10839,6 +11004,16 @@
"integrity": "sha512-8/JCaftHwbd//k6y2rEWp6k1wxVfpFzB6t1p825+cUb7Ym2XQfhwIC5KwhrvzZRJu+LtDE585zVaS32+CGtf0g==",
"dev": true
},
"npm-conf": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/npm-conf/-/npm-conf-1.1.3.tgz",
"integrity": "sha512-Yic4bZHJOt9RCFbRP3GgpqhScOY4HH3V2P8yBj6CeYq118Qr+BLXqT2JvpJ00mryLESpgOxf5XlFv4ZjXxLScw==",
"dev": true,
"requires": {
"config-chain": "^1.1.11",
"pify": "^3.0.0"
}
},
"npm-package-arg": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/npm-package-arg/-/npm-package-arg-6.1.0.tgz",
@ -11051,6 +11226,15 @@
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=",
"dev": true
},
"ono": {
"version": "4.0.11",
"resolved": "https://registry.npmjs.org/ono/-/ono-4.0.11.tgz",
"integrity": "sha512-jQ31cORBFE6td25deYeD80wxKBMj+zBmHTrVxnc6CKhx8gho6ipmWM5zj/oeoqioZ99yqBls9Z/9Nss7J26G2g==",
"dev": true,
"requires": {
"format-util": "^1.0.3"
}
},
"open": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/open/-/open-6.4.0.tgz",
@ -11961,6 +12145,12 @@
}
}
},
"proto-list": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz",
"integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=",
"dev": true
},
"protoduck": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/protoduck/-/protoduck-5.0.1.tgz",
@ -12874,7 +13064,7 @@
},
"reselect": {
"version": "2.5.4",
"resolved": "https://registry.npmjs.org/reselect/-/reselect-2.5.4.tgz",
"resolved": "http://registry.npmjs.org/reselect/-/reselect-2.5.4.tgz",
"integrity": "sha1-t9I/3wC4P6etAnlUb427vXZccEc="
},
"resolve": {
@ -12969,6 +13159,28 @@
"inherits": "^2.0.1"
}
},
"roarr": {
"version": "2.14.6",
"resolved": "https://registry.npmjs.org/roarr/-/roarr-2.14.6.tgz",
"integrity": "sha512-qjbw0BEesKA+3XFBPt+KVe1PC/Z6ShfJ4wPlx2XifqH5h2Lj8/KQT5XJTsy3n1Es5kai+BwKALaECW3F70B1cg==",
"dev": true,
"requires": {
"boolean": "^3.0.0",
"detect-node": "^2.0.4",
"globalthis": "^1.0.0",
"json-stringify-safe": "^5.0.1",
"semver-compare": "^1.0.0",
"sprintf-js": "^1.1.2"
},
"dependencies": {
"sprintf-js": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz",
"integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==",
"dev": true
}
}
},
"rollup": {
"version": "0.41.6",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-0.41.6.tgz",
@ -13402,6 +13614,12 @@
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA=="
},
"semver-compare": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz",
"integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=",
"dev": true
},
"semver-diff": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/semver-diff/-/semver-diff-2.1.0.tgz",
@ -13496,7 +13714,7 @@
},
"serialize-error": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-2.1.0.tgz",
"resolved": "http://registry.npmjs.org/serialize-error/-/serialize-error-2.1.0.tgz",
"integrity": "sha1-ULZ51WNc34Rme9yOWa9OW4HV9go="
},
"serialize-javascript": {
@ -14929,6 +15147,12 @@
"integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=",
"dev": true
},
"tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
"dev": true
},
"tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",

View File

@ -4,6 +4,7 @@
"description": "Harbor UI with Clarity",
"angular-cli": {},
"scripts": {
"postinstall": "node scripts/convert-yaml-to-json.js && ng-swagger-gen -i ng-swagger-gen/swagger.json -o ng-swagger-gen && node scripts/delete-swagger-json.js",
"start": "ng serve --ssl true --ssl-key ssl/server.key --ssl-cert ssl/server.crt --host 0.0.0.0 --proxy-config proxy.config.json",
"lint": "tslint \"src/**/*.ts\"",
"lint_fix": "tslint --fix \"src/**/*.ts\"",
@ -69,6 +70,7 @@
"codelyzer": "~5.0.0",
"enhanced-resolve": "^3.0.0",
"jasmine-spec-reporter": "~4.2.1",
"js-yaml": "^3.13.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "^1.0.1",
@ -78,6 +80,7 @@
"karma-jasmine-html-reporter": "^0.2.2",
"karma-mocha-reporter": "^2.2.4",
"karma-remap-istanbul": "^0.6.0",
"ng-swagger-gen": "^1.8.1",
"protractor": "^5.4.2",
"rollup": "^0.41.6",
"rollup-plugin-commonjs": "^8.0.2",

View File

@ -0,0 +1,17 @@
/**
before execute:
1.npm install js-yaml --save-dev
2.npm install ng-swagger-gen --save-dev
*/
//configuration
const inputFile = '../../api/v2.0/swagger.yaml';
const outputDir = 'ng-swagger-gen';
//convert swagger.yaml to swagger.json
const yaml = require('js-yaml');
const fs = require('fs');
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
const swaggerObj = yaml.load(fs.readFileSync(inputFile, {encoding: 'utf-8'}));
fs.writeFileSync(outputDir + '/swagger.json', JSON.stringify(swaggerObj, null, 2));

View File

@ -0,0 +1,3 @@
const fs = require('fs');
const filePath = 'ng-swagger-gen/swagger.json';
fs.unlinkSync(filePath);