Skip to content

Commit

Permalink
ODATA-1357: Search (#70)
Browse files Browse the repository at this point in the history
* ODATA-1357: descriptions for $filter, $sort, and $expand

* SearchRestrictions/Description
  • Loading branch information
ralfhandl authored Mar 6, 2020
1 parent 68c3a10 commit 2a04faa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
13 changes: 10 additions & 3 deletions lib/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,16 @@ module.exports.csdl2openapi = function (
const searchRestrictions = restrictions.SearchRestrictions || target && target[voc.Capabilities.SearchRestrictions] || {};

if (searchRestrictions.Searchable !== false) {
parameters.push({
$ref: '#/components/parameters/search'
});
if (searchRestrictions[voc.Core.Description]) {
parameters.push({
name: queryOptionPrefix + 'search',
description: searchRestrictions[voc.Core.Description],
in: 'query',
schema: { type: 'string' }
});
} else {
parameters.push({ $ref: '#/components/parameters/search' });
}
}
}

Expand Down
25 changes: 20 additions & 5 deletions test/csdl2openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,9 @@ describe('Edge cases', function () {
assert.deepStrictEqual(actual.paths['/Categories'].get, expected.paths['/Categories'].get, 'GET Categories');
})

it('FilterRestrictions, NavigationRestrictions, and SortRestrictions', function () {
it('FilterRestrictions, NavigationRestrictions, SearchRestrictions, and SortRestrictions', function () {
const csdl = {
$Version: '4.01',
$Reference: {
dummy: {
"$Include": [
Expand Down Expand Up @@ -1183,6 +1184,10 @@ describe('Edge cases', function () {
}
]
},
"@Capabilities.SearchRestrictions": {
"@Core.Description": "Searching has some restrictions here.",
"Searchable": true
},
"@Capabilities.SortRestrictions": {
"@Core.Description": "Sorting has some restrictions here.",
"NonSortableProperties": ["one"]
Expand All @@ -1200,6 +1205,12 @@ describe('Edge cases', function () {
parameters: [
{ $ref: "#/components/parameters/top" },
{ $ref: "#/components/parameters/skip" },
{
in: 'query',
name: 'search',
schema: { type: 'string' },
description: 'Searching has some restrictions here.'
},
{
in: 'query',
name: 'filter',
Expand Down Expand Up @@ -1309,10 +1320,14 @@ describe('Edge cases', function () {

it('ExpandRestrictions', function () {
const csdl = {
$Reference: { dummy: { "$Include": [
{ "$Namespace": "Org.OData.Core.V1", "$Alias": "Core" },
{ "$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: {
root: {
Expand Down

0 comments on commit 2a04faa

Please sign in to comment.