Skip to content

Commit 160b2dc

Browse files
committed
Merge remote-tracking branch 'origin/main' into csdl2openapi/create-key
2 parents 8ef8f65 + 861be30 commit 160b2dc

25 files changed

Lines changed: 1014 additions & 977 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.29.0 - 2025-01-27
4+
5+
### Fixed
6+
7+
- Apply default value `true` for `Capabilities.NavigationRestrictions/RestrictedProperties/TopSupported` and `.../SkipSupported`
8+
39
## 0.28.2 - 2024-10-30
410

511
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
<h3>Further Description of this Repository</h3>
3636

37-
The OData TC has published the [OData to OpenAPI Mapping Version 1.0](http://docs.oasis-open.org/odata/odata-openapi/v1.0/odata-openapi-v1.0.html), a recommendation on how to create OpenAPI descriptions for OData services. This project contains two proof-of-concept implementations of that mapping, [one using JavaScript](https://github.com/oasis-tcs/odata-openapi/blob/main/lib), and [one using XSLT](https://github.com/oasis-tcs/odata-openapi/blob/main/tools).
37+
The OData TC has published the [OData to OpenAPI Mapping Version 1.0](http://docs.oasis-open.org/odata/odata-openapi/v1.0/odata-openapi-v1.0.html), a recommendation on how to create OpenAPI descriptions for OData services. This project contains two proof-of-concept implementations of that mapping, [one using JavaScript](https://github.com/oasis-tcs/odata-openapi/blob/main/lib), and [one using XSLT](https://github.com/oasis-tcs/odata-openapi/blob/main/tools). The latter also evaluates certain "OData V2 style" annotations that are explained [here](https://sap.github.io/odata-vocabularies/docs/v2-annotations.html).
3838

3939
The [`examples` folder](https://github.com/oasis-tcs/odata-openapi/blob/main/examples) contains [OpenAPI 3.0.2](https://github.com/OAI/OpenAPI-Specification) descriptions that have been created from the XML `$metadata` documents of live and example OData services with these proof-of-concept implementations.
4040

examples/annotations.openapi3.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,14 @@
20672067
"ReadOnlySingleton",
20682068
"TwoReadOnlySet"
20692069
],
2070-
"parameters": [],
2070+
"parameters": [
2071+
{
2072+
"$ref": "#/components/parameters/top"
2073+
},
2074+
{
2075+
"$ref": "#/components/parameters/skip"
2076+
}
2077+
],
20712078
"responses": {
20722079
"200": {
20732080
"description": "Retrieved entities",

lib/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ Options:
5151
## Supported Annotations
5252

5353
The mapping can be fine-tuned via [annotations](https://github.com/oasis-tcs/odata-openapi/blob/main/doc/Annotations.md) in the CSDL (`$metadata`) XML documents.
54+
55+
This tool generates OpenAPI documents for OData V4 services that allow deep insert/upsert only for _containment_ navigation properties. Such OpenAPI documents are suitable for CAP-based services, see also the [`@cap-js/openapi` package](https://github.com/cap-js/openapi) that was forked from this repository.

lib/csdl2openapi.js

Lines changed: 37 additions & 8 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" : ""),
@@ -1073,8 +1090,8 @@ module.exports.csdl2openapi = function (
10731090
*/
10741091
function optionSkip(parameters, target, restrictions) {
10751092
const supported =
1076-
restrictions.SkipSupported !== undefined
1077-
? restrictions.SkipSupported
1093+
Object.keys(restrictions).length > 0
1094+
? restrictions.SkipSupported !== false
10781095
: target == null || target[voc.Capabilities.SkipSupported] !== false;
10791096

10801097
if (supported) {
@@ -1092,8 +1109,8 @@ module.exports.csdl2openapi = function (
10921109
*/
10931110
function optionTop(parameters, target, restrictions) {
10941111
const supported =
1095-
restrictions.TopSupported !== undefined
1096-
? restrictions.TopSupported
1112+
Object.keys(restrictions).length > 0
1113+
? restrictions.TopSupported !== false
10971114
: target == null || target[voc.Capabilities.TopSupported] !== false;
10981115

10991116
if (supported) {
@@ -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" ||

0 commit comments

Comments
 (0)