Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

### Added
### Changed
- Removed special characters from placeholders for fields like short text, description, etc.
### Deprecated
### Removed
### Fixed
### Security

## [2.0.0] - tbd

### Changed
- **BREAKING**: Bound action paths now use simplified names by default (e.g., `.../Discount` instead of `.../ODataDemo.Discount`). To restore previous behavior, use `--openapi:fqActionPaths` or `{ 'openapi:fqActionPaths': true }`.
- Removed special characters from placeholders for fields like short text, description, etc.

### Fixed
- Autoexposed `.texts` entities are now excluded from OpenAPI document
- Generate navigation paths to CRUD-disabled entities

### Security

Expand Down
8 changes: 6 additions & 2 deletions lib/compile/csdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ class CSDLMeta {
namespaceUrl = {}
/** Map of vocabularies and terms */
voc = {}
/** Options passed from caller */
options = {}

constructor(csdl) {
constructor(csdl, options = {}) {
this.csdl = csdl;
this.options = options;
this.#preProcess()
}

Expand Down Expand Up @@ -93,7 +96,8 @@ class CSDLMeta {
element.filter(overload => overload.$IsBound).forEach(overload => {
const type = overload.$Parameter[0].$Type + (overload.$Parameter[0].$Collection ? '-c' : '');
if (!this.boundOverloads[type]) this.boundOverloads[type] = [];
this.boundOverloads[type].push({ name: (isDefaultNamespace ? iName2 : qualifiedName), overload });
const useFullyQualified = this.options?.fqActionPaths === true;
this.boundOverloads[type].push({ name: (useFullyQualified && !isDefaultNamespace ? qualifiedName : iName2), overload });
});
} else if (element.$BaseType) {
const base = this.namespaceQualifiedName(element.$BaseType);
Expand Down
12 changes: 7 additions & 5 deletions lib/compile/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
/**
* Construct an OpenAPI description from a CSDL document
* @param {CSDL} csdl CSDL document
* @param {{ url?: string, servers?: object, odataVersion?: string, scheme?: string, host?: string, basePath?: string, diagram?: boolean, maxLevels?: number }} options Optional parameters
* @param {{ url?: string, servers?: object, odataVersion?: string, scheme?: string, host?: string, basePath?: string, diagram?: boolean, maxLevels?: number, fqActionPaths?: boolean }} options Optional parameters
* @return {object} OpenAPI description
*/
module.exports.csdl2openapi = function (

Check warning on line 93 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Function has a complexity of 21. Maximum allowed is 15

Check warning on line 93 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Function has a complexity of 21. Maximum allowed is 15

Check warning on line 93 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Function has a complexity of 21. Maximum allowed is 15
csdl,
{
url: serviceRoot,
Expand All @@ -100,14 +100,15 @@
host: host = 'localhost',
basePath: basePath = '/service-root',
diagram: diagram = false,
maxLevels: maxLevels = 5
maxLevels: maxLevels = 5,
fqActionPaths: fqActionPaths = false
} = {}
) {
// as preProcess below mutates the csdl, copy it before, to avoid side-effects on the caller side
csdl = JSON.parse(JSON.stringify(csdl))

Check warning on line 108 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Assignment to function parameter 'csdl'

Check warning on line 108 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Assignment to function parameter 'csdl'

Check warning on line 108 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Assignment to function parameter 'csdl'
csdl.$Version = odataVersion ? odataVersion : '4.01'
const meta = new CSDLMeta(csdl)
const meta = new CSDLMeta(csdl, { fqActionPaths })
serviceRoot = serviceRoot ?? (`${scheme}://${host}${basePath}`);

Check warning on line 111 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Assignment to function parameter 'serviceRoot'

Check warning on line 111 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Assignment to function parameter 'serviceRoot'

Check warning on line 111 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Assignment to function parameter 'serviceRoot'
const queryOptionPrefix = csdl.$Version <= '4.01' ? '$' : '';
const typesToInline = {}; // filled in schema() and used in inlineTypes()

Expand All @@ -120,7 +121,7 @@
Object.keys(entityContainer).forEach(element => {
if (entityContainer[element].$Type) {
const fullTypeName = entityContainer[element].$Type;
const type = fullTypeName.startsWith(serviceName + '.')

Check warning on line 124 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Unexpected string concatenation

Check warning on line 124 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Unexpected string concatenation

Check warning on line 124 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected string concatenation
? fullTypeName.substring(serviceName.length + 1)
: nameParts(fullTypeName).name;
if ((csdl[serviceName]?.[type]?.['@cds.autoexpose'] || csdl[serviceName]?.[type]?.['@cds.autoexposed'])
Expand Down Expand Up @@ -406,7 +407,7 @@
.replaceAll('_', ' ')
.replace(/([a-z])([A-Z])/g, '$1 $2'); // "camelCase" to "camel Case"
if (typeof tag === 'string') {
tag = normalise(tag);

Check warning on line 410 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Assignment to function parameter 'tag'

Check warning on line 410 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Assignment to function parameter 'tag'

Check warning on line 410 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Assignment to function parameter 'tag'
} else {
tag.name = normalise(tag.name);
}
Expand Down Expand Up @@ -458,7 +459,7 @@
* @param {number} level Number of navigation segments so far
* @param {string} navigationPath Path for finding navigation restrictions
*/
function pathItems(paths, prefix, prefixParameters, element, root, sourceName, targetName, target, level, navigationPath) {

Check warning on line 462 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Function 'pathItems' has too many parameters (10). Maximum allowed is 4

Check warning on line 462 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Function 'pathItems' has too many parameters (10). Maximum allowed is 4

Check warning on line 462 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Function 'pathItems' has too many parameters (10). Maximum allowed is 4
const name = prefix.substring(prefix.lastIndexOf('/') + 1);
const type = meta.modelElement(element.$Type);
const pathItem = {};
Expand Down Expand Up @@ -540,7 +541,7 @@
* @param {object} restrictions Navigation property restrictions of navigation segment
* @param {array} nonExpandable Non-expandable navigation properties
*/
function pathItemsWithKey(paths, prefix, prefixParameters, element, root, sourceName, targetName, target, level, navigationPath, restrictions, nonExpandable) {

Check warning on line 544 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Function 'pathItemsWithKey' has too many parameters (12). Maximum allowed is 4

Check warning on line 544 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Function 'pathItemsWithKey' has too many parameters (12). Maximum allowed is 4

Check warning on line 544 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Function 'pathItemsWithKey' has too many parameters (12). Maximum allowed is 4
const targetIndexable = target == null || target[meta.voc.Capabilities.IndexableByKey] != false;
if (restrictions.IndexableByKey == true || restrictions.IndexableByKey != false && targetIndexable) {
const name = prefix.substring(prefix.lastIndexOf('/') + 1);
Expand All @@ -557,11 +558,12 @@
operationUpdate(pathItem, element, name, sourceName, target, level, restrictions, true);
operationDelete(pathItem, element, name, sourceName, target, level, restrictions, true);
}
if (Object.keys(pathItem).filter((i) => i !== "parameters").length === 0)
delete paths[path];

pathItemsForBoundOperations(paths, path, parameters, element, sourceName, true);
pathItemsWithNavigation(paths, path, parameters, type, root, sourceName, level, navigationPath);

if (Object.keys(pathItem).filter((i) => i !== "parameters").length === 0)
delete paths[path];
}
}
}
Expand All @@ -577,7 +579,7 @@
* @param {number} level Number of navigation segments so far
* @param {object} restrictions Navigation property restrictions of navigation segment
*/
function operationCreate(pathItem, element, name, sourceName, targetName, target, level, restrictions) {

Check warning on line 582 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Function 'operationCreate' has too many parameters (8). Maximum allowed is 4

Check warning on line 582 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Function 'operationCreate' has too many parameters (8). Maximum allowed is 4

Check warning on line 582 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Function 'operationCreate' has too many parameters (8). Maximum allowed is 4
const insertRestrictions = restrictions.InsertRestrictions || target?.[meta.voc.Capabilities.InsertRestrictions] || {};
const countRestrictions = target?.[meta.voc.Capabilities.CountRestrictions]?.Countable === false // count property will be added if CountRestrictions is false
if (insertRestrictions.Insertable !== false) {
Expand Down Expand Up @@ -613,7 +615,7 @@
* @param {boolean} byKey Access by key
* @return Operation Text
*/
function operationSummary(operation, name, sourceName, level, collection, byKey) {

Check warning on line 618 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Function 'operationSummary' has too many parameters (6). Maximum allowed is 4

Check warning on line 618 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Function 'operationSummary' has too many parameters (6). Maximum allowed is 4

Check warning on line 618 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Function 'operationSummary' has too many parameters (6). Maximum allowed is 4
const lname = splitName(name);
const sname = splitName(sourceName);

Expand All @@ -638,7 +640,7 @@
* @param {boolean} byKey Read by key
* @param {array} nonExpandable Non-expandable navigation properties
*/
function operationRead(pathItem, element, name, sourceName, targetName, target, level, restrictions, byKey, nonExpandable) {

Check warning on line 643 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 24

Function 'operationRead' has too many parameters (10). Maximum allowed is 4

Check warning on line 643 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Function 'operationRead' has too many parameters (10). Maximum allowed is 4

Check warning on line 643 in lib/compile/csdl2openapi.js

View workflow job for this annotation

GitHub Actions / lint

Function 'operationRead' has too many parameters (10). Maximum allowed is 4
const targetRestrictions = target?.[meta.voc.Capabilities.ReadRestrictions];
const readRestrictions = restrictions.ReadRestrictions || targetRestrictions || {};
const readByKeyRestrictions = readRestrictions.ReadByKeyRestrictions;
Expand Down
Loading
Loading