Skip to content

Commit 1beb887

Browse files
Merge pull request #324 from oasis-tcs/parameter-alias-at
2 parents 93cf081 + 842da6f commit 1beb887

File tree

2 files changed

+102
-4
lines changed

2 files changed

+102
-4
lines changed

lib/csdl2openapi.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ const TITLE_SUFFIX = {
3838
"-update": " (for update)",
3939
};
4040

41+
const SYSTEM_QUERY_OPTIONS = [
42+
"compute",
43+
"expand",
44+
"select",
45+
"filter",
46+
"search",
47+
"count",
48+
"orderby",
49+
"skip",
50+
"top",
51+
"format",
52+
"index",
53+
"schemaversion",
54+
"skiptoken",
55+
"apply",
56+
];
57+
4158
/**
4259
* Construct an OpenAPI description from a CSDL document
4360
* @param {object} csdl CSDL document
@@ -610,8 +627,8 @@ module.exports.csdl2openapi = function (
610627
(byKey
611628
? "entity from "
612629
: element.$Collection
613-
? "entities from "
614-
: "") +
630+
? "entities from "
631+
: "") +
615632
(level > 0 ? "related " : "") +
616633
name +
617634
(byKey ? " by key" : ""),
@@ -1714,7 +1731,13 @@ module.exports.csdl2openapi = function (
17141731
type?.$UnderlyingType == "Edm.Stream"
17151732
) {
17161733
param.in = "query";
1717-
if (implicitAliases) {
1734+
if (
1735+
implicitAliases &&
1736+
csdl.$Version !== "2.0" &&
1737+
SYSTEM_QUERY_OPTIONS.includes(p.$Name.toLowerCase())
1738+
) {
1739+
param.name = "@" + p.$Name;
1740+
} else if (implicitAliases) {
17181741
param.name = p.$Name;
17191742
} else {
17201743
pathSegments.push(p.$Name + "=@" + p.$Name);
@@ -1740,7 +1763,13 @@ module.exports.csdl2openapi = function (
17401763
pathSegments.push(p.$Name + "={" + p.$Name + "}");
17411764
param.in = "path";
17421765
}
1743-
param.name = p.$Name;
1766+
if (
1767+
implicitAliases &&
1768+
csdl.$Version !== "2.0" &&
1769+
SYSTEM_QUERY_OPTIONS.includes(p.$Name.toLowerCase())
1770+
)
1771+
param.name = "@" + p.$Name;
1772+
else param.name = p.$Name;
17441773
if (
17451774
!p.$Type ||
17461775
p.$Type === "Edm.String" ||

test/csdl2openapi.test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,75 @@ describe("Edge cases", function () {
929929
);
930930
});
931931

932+
it("function with @ parameter aliases", function () {
933+
const csdl = {
934+
$Version: "4.01",
935+
$Reference: {
936+
dummy: {
937+
$Include: [{ $Namespace: "Org.OData.Core.V1", $Alias: "Core" }],
938+
},
939+
},
940+
$EntityContainer: "model.Container",
941+
model: {
942+
$Alias: "this",
943+
FavoritePhotos: [
944+
{
945+
$Kind: "Function",
946+
$Parameter: [
947+
{
948+
$Name: "SKIP",
949+
$Type: "Edm.Date",
950+
$Collection: true,
951+
"@Core.Description": "Dates to be skipped",
952+
},
953+
{
954+
$Name: "filter",
955+
"@Core.Description": "Boolean expression to filter the result",
956+
},
957+
],
958+
$ReturnType: {},
959+
},
960+
],
961+
Container: {
962+
fav: { $Function: "this.FavoritePhotos" },
963+
},
964+
},
965+
};
966+
const expected = {
967+
paths: {
968+
"/fav": {
969+
get: {
970+
parameters: [
971+
{
972+
name: "@SKIP",
973+
in: "query",
974+
required: true,
975+
description:
976+
"Dates to be skipped \nThis is a URL-encoded JSON array with items of type Edm.Date, see [Complex and Collection Literals](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_ComplexandCollectionLiterals)",
977+
schema: { type: "string" },
978+
example: "[]",
979+
},
980+
{
981+
name: "@filter",
982+
in: "query",
983+
required: true,
984+
schema: { type: "string", pattern: "^'([^']|'')*'$" },
985+
description:
986+
"Boolean expression to filter the result \nString value needs to be enclosed in single quotes",
987+
},
988+
],
989+
summary: "Invoke function FavoritePhotos",
990+
tags: ["Service Operations"],
991+
},
992+
},
993+
},
994+
};
995+
const actual = csdl2openapi(csdl, { diagram: true });
996+
delete actual.paths["/$batch"];
997+
delete actual.paths["/fav"].get.responses;
998+
assert.deepStrictEqual(actual.paths, expected.paths);
999+
});
1000+
9321001
it("return type with facets", function () {
9331002
const csdl = {
9341003
$EntityContainer: "this.Container",

0 commit comments

Comments
 (0)