From c1b947711e078f8a3a84289e094a6b2f7d0888cf Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Fri, 30 Jun 2023 16:36:37 +0200 Subject: [PATCH] Fix/252 (#253) * maxLevels reduced to 4, made a command-line option * 0.23.3 * Update CHANGELOG.md * Bump eslint --- CHANGELOG.md | 10 + examples/containment.openapi3.json | 334 ----------------------------- lib/cli.js | 26 ++- lib/csdl2openapi.js | 2 +- package-lock.json | 54 ++--- package.json | 4 +- 6 files changed, 60 insertions(+), 370 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed8bf511..64a91cee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [0.23.3] - 2023-06-30 + +### Added + +- Add cli support for maximum level of containment navigation properties using `--levels` + +### Fixed + +- Reduced default maximum level of containment navigation properties from 5 to 4 + ## [0.23.2] - 2023-06-16 ### Fixed diff --git a/examples/containment.openapi3.json b/examples/containment.openapi3.json index a230388e..eda0e635 100644 --- a/examples/containment.openapi3.json +++ b/examples/containment.openapi3.json @@ -4559,340 +4559,6 @@ } } }, - "/Folders('{Name}')/Folders('{Name_1}')/Folders('{Name_2}')/Folders('{Name_3}')/Folders('{Name_4}')": { - "parameters": [ - { - "description": "key: Name", - "in": "path", - "name": "Name", - "required": true, - "schema": { - "type": "string" - } - }, - { - "description": "key: Name", - "in": "path", - "name": "Name_1", - "required": true, - "schema": { - "type": "string" - } - }, - { - "description": "key: Name", - "in": "path", - "name": "Name_2", - "required": true, - "schema": { - "type": "string" - } - }, - { - "description": "key: Name", - "in": "path", - "name": "Name_3", - "required": true, - "schema": { - "type": "string" - } - }, - { - "description": "key: Name", - "in": "path", - "name": "Name_4", - "required": true, - "schema": { - "type": "string" - } - } - ], - "get": { - "summary": "Get entity from related Folders by key", - "tags": [ - "Folders" - ], - "parameters": [ - { - "name": "select", - "description": "Select properties to be returned, see [Select](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_SystemQueryOptionselect)", - "in": "query", - "explode": false, - "schema": { - "type": "array", - "uniqueItems": true, - "items": { - "type": "string", - "enum": [ - "Name", - "Description" - ] - } - } - }, - { - "name": "expand", - "description": "Expand related entities, see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_SystemQueryOptionexpand)", - "in": "query", - "explode": false, - "schema": { - "type": "array", - "uniqueItems": true, - "items": { - "type": "string", - "enum": [ - "*", - "Folders" - ] - } - } - } - ], - "responses": { - "200": { - "description": "Retrieved entity", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Containment.Folder" - } - } - } - }, - "4XX": { - "$ref": "#/components/responses/error" - } - } - }, - "patch": { - "summary": "Update entity in related Folders", - "tags": [ - "Folders" - ], - "requestBody": { - "description": "New property values", - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Containment.Folder-update" - } - } - } - }, - "responses": { - "204": { - "description": "Success" - }, - "4XX": { - "$ref": "#/components/responses/error" - } - } - }, - "delete": { - "summary": "Delete entity from related Folders", - "tags": [ - "Folders" - ], - "responses": { - "204": { - "description": "Success" - }, - "4XX": { - "$ref": "#/components/responses/error" - } - } - } - }, - "/Folders('{Name}')/Folders('{Name_1}')/Folders('{Name_2}')/Folders('{Name_3}')/Folders('{Name_4}')/Folders": { - "parameters": [ - { - "description": "key: Name", - "in": "path", - "name": "Name", - "required": true, - "schema": { - "type": "string" - } - }, - { - "description": "key: Name", - "in": "path", - "name": "Name_1", - "required": true, - "schema": { - "type": "string" - } - }, - { - "description": "key: Name", - "in": "path", - "name": "Name_2", - "required": true, - "schema": { - "type": "string" - } - }, - { - "description": "key: Name", - "in": "path", - "name": "Name_3", - "required": true, - "schema": { - "type": "string" - } - }, - { - "description": "key: Name", - "in": "path", - "name": "Name_4", - "required": true, - "schema": { - "type": "string" - } - } - ], - "get": { - "summary": "Get entities from related Folders", - "tags": [ - "Folders" - ], - "parameters": [ - { - "$ref": "#/components/parameters/top" - }, - { - "$ref": "#/components/parameters/skip" - }, - { - "$ref": "#/components/parameters/search" - }, - { - "name": "filter", - "description": "Filter items by property values, see [Filtering](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_SystemQueryOptionfilter)", - "in": "query", - "schema": { - "type": "string" - } - }, - { - "$ref": "#/components/parameters/count" - }, - { - "name": "orderby", - "description": "Order items by property values, see [Sorting](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_SystemQueryOptionorderby)", - "in": "query", - "explode": false, - "schema": { - "type": "array", - "uniqueItems": true, - "items": { - "type": "string", - "enum": [ - "Name", - "Name desc", - "Description", - "Description desc" - ] - } - } - }, - { - "name": "select", - "description": "Select properties to be returned, see [Select](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_SystemQueryOptionselect)", - "in": "query", - "explode": false, - "schema": { - "type": "array", - "uniqueItems": true, - "items": { - "type": "string", - "enum": [ - "Name", - "Description" - ] - } - } - }, - { - "name": "expand", - "description": "Expand related entities, see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_SystemQueryOptionexpand)", - "in": "query", - "explode": false, - "schema": { - "type": "array", - "uniqueItems": true, - "items": { - "type": "string", - "enum": [ - "*", - "Folders" - ] - } - } - } - ], - "responses": { - "200": { - "description": "Retrieved entities", - "content": { - "application/json": { - "schema": { - "type": "object", - "title": "Collection of Folder", - "properties": { - "@count": { - "$ref": "#/components/schemas/count" - }, - "value": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Containment.Folder" - } - } - } - } - } - } - }, - "4XX": { - "$ref": "#/components/responses/error" - } - } - }, - "post": { - "summary": "Add new entity to related Folders", - "tags": [ - "Folders" - ], - "requestBody": { - "description": "New entity", - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Containment.Folder-create" - } - } - } - }, - "responses": { - "201": { - "description": "Created entity", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Containment.Folder" - } - } - } - }, - "4XX": { - "$ref": "#/components/responses/error" - } - } - } - }, "/Headers": { "get": { "summary": "Get entities from Headers", diff --git a/lib/cli.js b/lib/cli.js index 90561a8d..b0c193d5 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -13,7 +13,18 @@ const { stringifyStream } = require("@discoveryjs/json-ext"); var unknown = false; var argv = minimist(process.argv.slice(2), { - string: ["o", "openapi-version", "t", "target", "scheme", "host", "basePath", "title", "description"], + string: [ + "o", + "openapi-version", + "t", + "target", + "basePath", + "description", + "host", + "levels", + "scheme", + "title", + ], boolean: [ "d", "diagram", @@ -34,8 +45,9 @@ var argv = minimist(process.argv.slice(2), { u: "used-schemas-only", }, default: { + levels: 4, pretty: false, - skipBatchPath: false + skipBatchPath: false, }, unknown: (arg) => { if (arg.substring(0, 1) == "-") { @@ -50,16 +62,17 @@ if (unknown || argv._.length == 0 || argv.h) { console.log(`Usage: odata-openapi3 Options: --basePath base path (default: /service-root) + --description default description if none is annotated -d, --diagram include YUML diagram -h, --help show this info --host host (default: localhost) + --levels maximum number of path segments -o, --openapi-version 3.0.0 to 3.0.3 or 3.1.0 (default: 3.0.2) -p, --pretty pretty-print JSON result --scheme scheme (default: http) - -t, --target target file (default: source file basename + .openapi3.json) --skipBatchPath skips the generation of the $batch path, (default: false) - --title default title if none is annotated - --description default description if none is annotated`); + -t, --target target file (default: source file basename + .openapi3.json) + --title default title if none is annotated`); } else { //TODO: further input parameters reserved for e.g. referenced CSDL documents // for (var i = 0; i < argv._.length; i++) { @@ -91,11 +104,12 @@ function convert(source) { host: argv.host, basePath: argv.basePath, diagram: argv.diagram, + maxLevels: Number(argv.levels), openapiVersion: argv.o, messages, skipBatchPath: argv.skipBatchPath, defaultTitle: argv.title, - defaultDescription: argv.description + defaultDescription: argv.description, }); stringifyStream(openapi, null, argv.pretty ? 4 : 0).pipe( diff --git a/lib/csdl2openapi.js b/lib/csdl2openapi.js index 7491db81..3c890c84 100644 --- a/lib/csdl2openapi.js +++ b/lib/csdl2openapi.js @@ -52,7 +52,7 @@ module.exports.csdl2openapi = function ( basePath = "/service-root", diagram = false, openapiVersion = "3.0.2", - maxLevels = 5, + maxLevels = 4, messages = [], skipBatchPath = false, defaultTitle = null, diff --git a/package-lock.json b/package-lock.json index 8ebcc6ff..ee73cdeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "odata-openapi", - "version": "0.23.2", + "version": "0.23.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "odata-openapi", - "version": "0.23.2", + "version": "0.23.3", "license": "SEE LICENSE IN LICENSE.md", "dependencies": { "@discoveryjs/json-ext": "^0.5.7", @@ -22,13 +22,22 @@ "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", "c8": "^8.0.0", - "eslint": "^8.42.0", + "eslint": "^8.43.0", "mocha": "^10.2.0" }, "engines": { "node": ">=14.0.0" } }, + "node_modules/@aashutoshrathi/word-wrap": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", + "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/@apidevtools/openapi-schemas": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@apidevtools/openapi-schemas/-/openapi-schemas-2.1.0.tgz", @@ -122,9 +131,9 @@ "dev": true }, "node_modules/@eslint/js": { - "version": "8.42.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.42.0.tgz", - "integrity": "sha512-6SWlXpWU5AvId8Ac7zjzmIOqMOba/JWY8XZ4A7q7Gn1Vlfg/SFFIlrtHXt9nPn4op9ZPAkl91Jao+QQv3r/ukw==", + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.43.0.tgz", + "integrity": "sha512-s2UHCoiXfxMvmfzqoN+vrQ84ahUSYde9qNO1MdxmoEhyHWsfmwOpFlwYV+ePJEVc7gFnATGUi376WowX1N7tFg==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -239,9 +248,9 @@ "dev": true }, "node_modules/acorn": { - "version": "8.8.2", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", - "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz", + "integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -650,15 +659,15 @@ } }, "node_modules/eslint": { - "version": "8.42.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.42.0.tgz", - "integrity": "sha512-ulg9Ms6E1WPf67PHaEY4/6E2tEn5/f7FXGzr3t9cBMugOmf1INYvuUwwh1aXQN4MfJ6a5K2iNwP3w4AColvI9A==", + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.43.0.tgz", + "integrity": "sha512-aaCpf2JqqKesMFGgmRPessmVKjcGXqdlAYLLC3THM8t5nBRZRQ+st5WM/hoJXkdioEXLLbXgclUpM0TXo5HX5Q==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.4.0", "@eslint/eslintrc": "^2.0.3", - "@eslint/js": "8.42.0", + "@eslint/js": "8.43.0", "@humanwhocodes/config-array": "^0.11.10", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", @@ -1457,17 +1466,17 @@ } }, "node_modules/optionator": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", - "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "version": "0.9.3", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", + "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", "dev": true, "dependencies": { + "@aashutoshrathi/word-wrap": "^1.2.3", "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", - "type-check": "^0.4.0", - "word-wrap": "^1.2.3" + "type-check": "^0.4.0" }, "engines": { "node": ">= 0.8.0" @@ -1902,15 +1911,6 @@ "node": ">= 8" } }, - "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/workerpool": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz", diff --git a/package.json b/package.json index 16560a03..80ed157d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "odata-openapi", - "version": "0.23.2", + "version": "0.23.3", "description": "Convert OData CSDL XML or CSDL JSON to OpenAPI", "homepage": "https://github.com/oasis-tcs/odata-openapi/blob/master/lib/README.md", "bugs": "https://github.com/oasis-tcs/odata-openapi/issues", @@ -30,7 +30,7 @@ "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", "c8": "^8.0.0", - "eslint": "^8.42.0", + "eslint": "^8.43.0", "mocha": "^10.2.0" }, "scripts": {