Skip to content

Commit

Permalink
ODATA-1357: BatchSupport - Supported, @Core.Description, @Core.LongDe…
Browse files Browse the repository at this point in the history
…scription (#71)
  • Loading branch information
ralfhandl authored Mar 9, 2020
1 parent 2a04faa commit 3a5b247
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
11 changes: 6 additions & 5 deletions lib/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ module.exports.csdl2openapi = function (
function vocabularies(voc, alias) {
const terms = {
Authorization: ['Authorizations', 'SecuritySchemes'],
Capabilities: ['BatchSupported', 'ChangeTracking', 'CountRestrictions', 'DeleteRestrictions', 'DeepUpdateSupport', 'ExpandRestrictions',
Capabilities: ['BatchSupport', 'BatchSupported', 'ChangeTracking', 'CountRestrictions', 'DeleteRestrictions', 'DeepUpdateSupport', 'ExpandRestrictions',
'FilterRestrictions', 'IndexableByKey', 'InsertRestrictions', 'KeyAsSegmentSupported', 'NavigationRestrictions',
'SearchRestrictions', 'SelectSupport', 'SkipSupported', 'SortRestrictions',
'ReadRestrictions', 'TopSupported', 'UpdateRestrictions'],
Expand Down Expand Up @@ -1251,14 +1251,15 @@ module.exports.csdl2openapi = function (
* @param {object} container Entity container
*/
function pathItemBatch(paths, container) {
const supported = container[voc.Capabilities.BatchSupported] != false;
const batchSupport = container[voc.Capabilities.BatchSupport] || {};
const supported = container[voc.Capabilities.BatchSupported] !== false && batchSupport.Supported !== false;
if (supported) {
const firstEntitySet = Object.keys(container).filter(child => isIdentifier(child) && container[child].$Collection)[0];
paths['/$batch'] = {
post: {
summary: 'Send a group of requests',
description: 'Group multiple requests into a single request payload, see '
+ '[Batch Requests](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_BatchRequests).'
summary: batchSupport[voc.Core.Description] || 'Send a group of requests',
description: (batchSupport[voc.Core.LongDescription] || 'Group multiple requests into a single request payload, see '
+ '[Batch Requests](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_BatchRequests).')
+ '\n\n*Please note that "Try it out" is not supported for this request.*',
tags: ['Batch Requests'],
requestBody: {
Expand Down
26 changes: 21 additions & 5 deletions test/csdl2openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,23 @@ describe('Edge cases', function () {
assert.deepStrictEqual(operations(actual), operations(expected), 'Operations');
})

it('inherited key', function () {
it('inherited key, BatchSupport/Supported:false', function () {
const csdl = {
$EntityContainer: 'this.Container',
$Reference: { dummy: { $Include: [{ $Namespace: 'Org.OData.Capabilities.V1', $Alias: 'Capabilities' }] } },
this: {
Base: { $Kind: 'EntityType', $Key: ['key'], key: {} },
Derived: { $Kind: 'EntityType', $BaseType: 'this.Base' },
Container: { Set: { $Collection: true, $Type: 'this.Derived' } }
Container: {
'@Capabilities.BatchSupport': { Supported: false },
Set: { $Collection: true, $Type: 'this.Derived' }
}
}
};
const expected = {
paths: {
'/Set': { get: {}, post: {} },
"/Set('{key}')": { get: {}, patch: {}, delete: {} },
'/$batch': { post: {} }
"/Set('{key}')": { get: {}, patch: {}, delete: {} }
}
};
const actual = lib.csdl2openapi(csdl, {});
Expand All @@ -325,12 +328,23 @@ describe('Edge cases', function () {

it('key-as-segment', function () {
const csdl = {
$Reference: { dummy: { $Include: [{ $Namespace: 'Org.OData.Capabilities.V1', $Alias: 'Capabilities' }] } },
$Reference: {
dummy: {
'$Include': [
{ '$Namespace': 'Org.OData.Core.V1', '$Alias': 'Core' },
{ '$Namespace': 'Org.OData.Capabilities.V1', '$Alias': 'Capabilities' }
]
}
},
$EntityContainer: 'this.Container',
this: {
Type: { $Kind: 'EntityType', $Key: ['key'], key: {} },
Type2: { $Kind: 'EntityType', $Key: ['key1', 'key2'], key1: {}, key2: {} },
Container: {
'@Capabilities.BatchSupport': {
'@Core.Description': 'BatchSupport - Description',
'@Core.LongDescription': 'BatchSupport - LongDescription'
},
'@Capabilities.KeyAsSegmentSupported': true,
Set: { $Collection: true, $Type: 'this.Type' },
Set2: { $Collection: true, $Type: 'this.Type2' }
Expand All @@ -349,6 +363,8 @@ describe('Edge cases', function () {
const actual = lib.csdl2openapi(csdl);
assert.deepStrictEqual(paths(actual), paths(expected), 'Paths');
assert.deepStrictEqual(operations(actual), operations(expected), 'Operations');
assert.equal(actual.paths['/$batch'].post.summary, 'BatchSupport - Description', 'Batch summary');
assert.equal(actual.paths['/$batch'].post.description, 'BatchSupport - LongDescription\n\n*Please note that "Try it out" is not supported for this request.*', 'Batch description');
})

it('function without parameters', function () {
Expand Down

0 comments on commit 3a5b247

Please sign in to comment.