@cap-js/ord 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/LICENSES/Apache-2.0.txt +73 -0
- package/README.md +66 -0
- package/data/well-known.json +14 -0
- package/lib/defaults.js +75 -0
- package/lib/index.js +5 -0
- package/lib/metaData.js +45 -0
- package/lib/ord.js +202 -0
- package/lib/plugin.js +33 -0
- package/lib/templates.js +354 -0
- package/package.json +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
|
|
37
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
38
|
+
|
|
39
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
40
|
+
|
|
41
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
42
|
+
|
|
43
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
57
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
58
|
+
|
|
59
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
60
|
+
|
|
61
|
+
Copyright [yyyy] [name of copyright owner]
|
|
62
|
+
|
|
63
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
|
+
you may not use this file except in compliance with the License.
|
|
65
|
+
You may obtain a copy of the License at
|
|
66
|
+
|
|
67
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
68
|
+
|
|
69
|
+
Unless required by applicable law or agreed to in writing, software
|
|
70
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
71
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
72
|
+
See the License for the specific language governing permissions and
|
|
73
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[](https://api.reuse.software/info/github.com/cap-js/cds-plugin-for-ord)
|
|
2
|
+
|
|
3
|
+
# CDS Plugin for ORD
|
|
4
|
+
|
|
5
|
+
## About this project
|
|
6
|
+
|
|
7
|
+
This plugin enables generation of ORD document for CAP based applications. When you adopt ORD, your application gains a single entry point, known as the Service Provider Interface. This interface allows you to discover and gather relevant information or metadata. You can use this information to construct a static metadata catalog or to perform a detailed runtime inspection of your actual system landscapes.
|
|
8
|
+
|
|
9
|
+
Open Resource Discovery [(ORD)](https://sap.github.io/open-resource-discovery/) is a protocol that enables applications and services to self-describe their available resources and capabilities. It's not only useful for describing static documentation, but it also accurately reflects tenant-specific configurations and extensions at runtime. Typically, ORD is used to describe APIs and Events, but it also supports higher-level concepts like Entity Types (Business Objects) and Data Products (beta).
|
|
10
|
+
|
|
11
|
+
## Requirements and Setup
|
|
12
|
+
|
|
13
|
+
### Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @cap-js/ord
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Usage
|
|
20
|
+
|
|
21
|
+
#### Programmatic API
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
const cds = require('@sap/cds')
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
const csn = await cds.load(cds.env.folders.srv)
|
|
29
|
+
const ord = cds.compile.to.ord(csn)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Command Line
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
cds compile <path to srv folder> --to ord [-o] [destinationFilePath]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
<img width="1300" alt="Sample Application Demo" style="border-radius:0.5rem;" src="./asset/etc/ordCLI.png">
|
|
39
|
+
|
|
40
|
+
#### ORD Endpoints
|
|
41
|
+
|
|
42
|
+
1) Run `cds watch` in the application's root.
|
|
43
|
+
2) Check the following relative paths for ORD information - `/.well-known/open-resource-discovery` , `/open-resource-discovery/v1/documents/1`.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<img width="1300" alt="Sample Application Demo" style="border-radius:0.5rem;" src="./asset/etc/ordEndpoint.gif">
|
|
47
|
+
|
|
48
|
+
### Customizing ORD Document
|
|
49
|
+
|
|
50
|
+
You can find more information, such as how to customize the ORD Document, in this [document](ord.md).
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Support, Feedback, Contributing
|
|
54
|
+
|
|
55
|
+
This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/ord/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
|
|
56
|
+
|
|
57
|
+
## Security / Disclosure
|
|
58
|
+
If you find any bug that may be a security problem, please follow our instructions at [in our security policy](https://github.com/cap-js/ord/issues/security/policy) on how to report it. Please do not create GitHub issues for security-related doubts or problems.
|
|
59
|
+
|
|
60
|
+
## Code of Conduct
|
|
61
|
+
|
|
62
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](https://github.com/cap-js/.github/blob/main/CODE_OF_CONDUCT.md) at all times.
|
|
63
|
+
|
|
64
|
+
## Licensing
|
|
65
|
+
|
|
66
|
+
Copyright 2024 SAP SE or an SAP affiliate company and cds-plugin-for-ord contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js/<your-project>).
|
package/lib/defaults.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
const regexWithRemoval = (name) => {
|
|
3
|
+
return name.replace(/[^a-zA-Z0-9]/g,'');
|
|
4
|
+
}
|
|
5
|
+
const regexWithUnderScore = (name) => {
|
|
6
|
+
return regexWithRemoval(name.charAt(0)) + name.slice(1, name.length).replace(/[^a-zA-Z0-9]/g,'_');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Module containing default configuration for ORD Document.
|
|
11
|
+
* @module defaults
|
|
12
|
+
*/
|
|
13
|
+
module.exports = {
|
|
14
|
+
openResourceDiscovery: "1.9",
|
|
15
|
+
policyLevel: "none",
|
|
16
|
+
description: "this is an application description",
|
|
17
|
+
products: (name) => [
|
|
18
|
+
{
|
|
19
|
+
ordId: `customer:product:${regexWithUnderScore(name)}:`,
|
|
20
|
+
title: `ORD App Title for ${regexWithRemoval(name)}`,
|
|
21
|
+
shortDescription: " shortDescription for products",
|
|
22
|
+
vendor: "customer:vendor:SAPCustomer:",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
groupTypeId: "sap.cds:service",
|
|
26
|
+
packages: function getPackageData (name, policyLevel,capNamespace) {
|
|
27
|
+
function createPackage(name, tag) {
|
|
28
|
+
return {
|
|
29
|
+
ordId: `${regexWithRemoval(name)}:package:${capNamespace}${tag}`,
|
|
30
|
+
title: `sample title for ${regexWithRemoval(name)}`,
|
|
31
|
+
shortDescription: "Here is the shortDescription for packages",
|
|
32
|
+
description: "Here is the description for packages",
|
|
33
|
+
version: "1.0.0",
|
|
34
|
+
partOfProducts: [`customer:product:${regexWithUnderScore(name)}:`],
|
|
35
|
+
vendor: "customer:vendor:SAP:"
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if(policyLevel.split(':')[0].toLowerCase() === 'sap') {
|
|
40
|
+
return [createPackage(name, "-api:v1"), createPackage(name, "-event:v1")];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return [createPackage(name, ":v1")];
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
consumptionBundles: (name) => [
|
|
47
|
+
{
|
|
48
|
+
ordId: `${regexWithRemoval(name)}:consumptionBundle:unknown:v1`,
|
|
49
|
+
version: "1.0.0",
|
|
50
|
+
title: "Unprotected resources",
|
|
51
|
+
shortDescription:
|
|
52
|
+
"If we have another protected API then it will be another object",
|
|
53
|
+
description:
|
|
54
|
+
"This Consumption Bundle contains all resources of the reference app which are unprotected and do not require authentication",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
|
|
58
|
+
apiResources: [],
|
|
59
|
+
eventResources: [],
|
|
60
|
+
entityTypes: [],
|
|
61
|
+
baseTemplate : {
|
|
62
|
+
openResourceDiscoveryV1: {
|
|
63
|
+
documents: [
|
|
64
|
+
{
|
|
65
|
+
url: "/open-resource-discovery/v1/documents/1",
|
|
66
|
+
accessStrategies: [
|
|
67
|
+
{
|
|
68
|
+
type: "open",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
}
|
package/lib/index.js
ADDED
package/lib/metaData.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const cds = require('@sap/cds/lib');
|
|
2
|
+
const { compile : openapi } = require('@cap-js/openapi')
|
|
3
|
+
const { compile : asyncapi } = require('@cap-js/asyncapi');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the compiled meta data for the specific service or event according to its compiled type
|
|
7
|
+
* @param {string} data
|
|
8
|
+
* @returns {string, JSON|XML} contentType, response
|
|
9
|
+
*/
|
|
10
|
+
module.exports = async (data) => {
|
|
11
|
+
const parts = data?.split("/").pop().replace(/\.json$/, '').split(".");
|
|
12
|
+
const compilerType = parts.pop();
|
|
13
|
+
const serviceName = parts.join(".");
|
|
14
|
+
const csn = cds.services[serviceName].model;
|
|
15
|
+
|
|
16
|
+
let responseFile;
|
|
17
|
+
const options = { service: serviceName, as: 'str', messages: [] }
|
|
18
|
+
if (compilerType === "oas3") {
|
|
19
|
+
try {
|
|
20
|
+
responseFile = openapi(csn, options);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error("OpenApi error:", error.message);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
} else if (compilerType === "asyncapi2") {
|
|
26
|
+
try {
|
|
27
|
+
responseFile = asyncapi(csn, options);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error("AsyncApi error:", error.message);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
} else if (compilerType === "edmx") {
|
|
33
|
+
try {
|
|
34
|
+
responseFile = await cds.compile(csn).to["edmx"](options);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error("Edmx error:", error.message);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
contentType: `application/${compilerType === "edmx" ? "xml" : "json"}`,
|
|
43
|
+
response: responseFile
|
|
44
|
+
};
|
|
45
|
+
}
|
package/lib/ord.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const cds = require("@sap/cds");
|
|
3
|
+
const { exists } = cds.utils;
|
|
4
|
+
const defaults = require("./defaults");
|
|
5
|
+
const {
|
|
6
|
+
fCreateAPIResourceTemplate,
|
|
7
|
+
fCreateEventResourceTemplate,
|
|
8
|
+
fCreateGroupsTemplateForService,
|
|
9
|
+
fCreateGroupsTemplateForEvent,
|
|
10
|
+
fCreateEntityTypeTemplate
|
|
11
|
+
} = require('./templates');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initializes global object based on package.json and CSN object.
|
|
15
|
+
* @param {Object} csn object
|
|
16
|
+
* @returns {Object} An object containing global variables.
|
|
17
|
+
*/
|
|
18
|
+
const fInitializeGlobal = (csn) => {
|
|
19
|
+
let packagejsonPath = path.join(cds.root,'package.json')
|
|
20
|
+
let packageJson;
|
|
21
|
+
if (exists(packagejsonPath)) {
|
|
22
|
+
packageJson = require(packagejsonPath);
|
|
23
|
+
} else {
|
|
24
|
+
throw new Error(`package.json not found in the project root directory`);
|
|
25
|
+
}
|
|
26
|
+
const appName = packageJson.name.replace(/^[@]/, "").replace(/[@/]/g, "-");
|
|
27
|
+
const aModelKeys = Object.keys(csn.definitions);
|
|
28
|
+
const aEvents = [];
|
|
29
|
+
const aServices = [];
|
|
30
|
+
const aODMEntity = [];
|
|
31
|
+
|
|
32
|
+
const capNamespace = csn.namespace;
|
|
33
|
+
// namespace variable value if present in cdsrc.json take it there or else from package.json
|
|
34
|
+
//if cdsrc.json does not have applicationNamespace, then use just the namespace
|
|
35
|
+
const namespace = cds.env["ord"]?.namespace || `customer.${appName}`;
|
|
36
|
+
const applicationNamespace = cds.env?.export?.asyncapi?.applicationNamespace;
|
|
37
|
+
|
|
38
|
+
if (applicationNamespace && fGetNamespaceComponents(namespace) !== fGetNamespaceComponents(applicationNamespace)) {
|
|
39
|
+
console.warn('ORD and AsyncAPI namespaces should be the same.');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const fEventFilter = (keyDefinition) => keyDefinition.kind === "event";
|
|
43
|
+
const fServicesFilter = (keyDefinition) => keyDefinition.kind === "service" && !keyDefinition['@cds.external'];
|
|
44
|
+
const fODMEntityFilter = (key, keyDefinition) => {
|
|
45
|
+
return keyDefinition.kind === "entity"
|
|
46
|
+
&& key.includes(capNamespace)
|
|
47
|
+
&& !key.includes(".texts")
|
|
48
|
+
&& keyDefinition["@ODM.entityName"];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
aModelKeys.forEach((key) => {
|
|
52
|
+
const keyDefinition = csn.definitions[key];
|
|
53
|
+
if(fServicesFilter(keyDefinition)){
|
|
54
|
+
aServices.push(key);
|
|
55
|
+
} else if(fODMEntityFilter(key, keyDefinition)) {
|
|
56
|
+
aODMEntity.push(fCreateEntityTypeTemplate(keyDefinition));
|
|
57
|
+
} else if(fEventFilter(keyDefinition)){
|
|
58
|
+
aEvents.push(key);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
env: cds.env["ord"],
|
|
65
|
+
capNamespace,
|
|
66
|
+
appName,
|
|
67
|
+
aEvents,
|
|
68
|
+
aServices,
|
|
69
|
+
aODMEntity,
|
|
70
|
+
namespace,
|
|
71
|
+
applicationNamespace
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves first two components of the namespace.
|
|
77
|
+
* @param {string} namespace
|
|
78
|
+
* @returns {string} The first two components of the namespace.
|
|
79
|
+
*/
|
|
80
|
+
const fGetNamespaceComponents = (namespace) => namespace.split('.').slice(0, 2).join('.');
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves the policy level.
|
|
84
|
+
* Hierarchy to check data: cdsrc.json > defaults
|
|
85
|
+
* @returns {string} The policy level.
|
|
86
|
+
*/
|
|
87
|
+
const fGetPolicyLevel = (global) => global.env?.policyLevel || defaults.policyLevel;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves the root level ORD document description.
|
|
91
|
+
* Hierarchy to check data: cdsrc.json > defaults
|
|
92
|
+
* @returns {string} The ORD document description.
|
|
93
|
+
*/
|
|
94
|
+
const fGetDescription = (global) => global.env?.description || defaults.description;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Retrieves the products.
|
|
98
|
+
* Hierarchy to check data: cdsrc.json > defaults
|
|
99
|
+
* @returns {Array<object>} The products array.
|
|
100
|
+
* if global.namespace is defined in cdsrc.json, then use it, else use the appName from package.json
|
|
101
|
+
*/
|
|
102
|
+
const fGetProducts = (global) => global.env?.products || defaults.products(global.namespace);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Retrieves the groups that services belongs to.
|
|
106
|
+
* Gets list of groups from CDS runtime object.
|
|
107
|
+
* @param {Object} csn object
|
|
108
|
+
* @returns {Array<object>} The groups array.
|
|
109
|
+
*/
|
|
110
|
+
const fGetGroups = (csn, global) => {
|
|
111
|
+
// storing the group ids in a set to avoid duplicates
|
|
112
|
+
let groupIds = new Set();
|
|
113
|
+
|
|
114
|
+
let serviceGroups = global.aServices
|
|
115
|
+
.map((srv) => fCreateGroupsTemplateForService(srv, csn.definitions[srv], groupIds))
|
|
116
|
+
.filter((resource) => resource !== null && resource !== undefined);
|
|
117
|
+
let eventGroups = global.aEvents
|
|
118
|
+
.map((event) => fCreateGroupsTemplateForEvent(event, csn.definitions[event], groupIds))
|
|
119
|
+
.filter((resource) => resource !== null && resource !== undefined);
|
|
120
|
+
|
|
121
|
+
return [...serviceGroups, ...eventGroups];
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Retrieves the packages.
|
|
126
|
+
* Hierarchy to check data: cdsrc.json > defaults
|
|
127
|
+
* @returns {Array<object>} The packages array.
|
|
128
|
+
*/
|
|
129
|
+
const fGetPackages = (policyLevel,global) => global.env?.packages || (global.aEvents.length) ? defaults.packages(global.namespace,policyLevel,global.capNamespace) : defaults.packages(global.namespace,policyLevel,global.capNamespace).slice(0, 1)
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Retrieves the consumption bundles.
|
|
133
|
+
* Hierarchy to check data: cdsrc.json > defaults
|
|
134
|
+
* @returns {Array<object>} The consumption bundles array.
|
|
135
|
+
*/
|
|
136
|
+
const fGetConsumptionBundles = (global) => global.env?.consumptionBundles || (global.aEvents.length) ? defaults.consumptionBundles(global.capNamespace) : defaults.consumptionBundles(global.capNamespace).slice(0,1)
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Retrieves the API Resources
|
|
140
|
+
* Gets list of services from CSN object
|
|
141
|
+
* @param {Object} csn object
|
|
142
|
+
* @returns {Array<object>} The API Resources array.
|
|
143
|
+
*/
|
|
144
|
+
const fGetAPIResources = (csn, global,packageIds) => {
|
|
145
|
+
const apiResources = [];
|
|
146
|
+
global.aServices.forEach((srv) => {
|
|
147
|
+
fCreateAPIResourceTemplate(srv, csn.definitions[srv], global,packageIds)?.forEach(
|
|
148
|
+
(resource) => {
|
|
149
|
+
if (resource !== null && resource !== undefined) {
|
|
150
|
+
apiResources.push(resource);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
return apiResources;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Retrieves the Event Resources
|
|
160
|
+
* Gets list of event from CSN object
|
|
161
|
+
* @param {Object} csn object
|
|
162
|
+
* @returns {Array<object>} The Event Resources array.
|
|
163
|
+
*/
|
|
164
|
+
const fGetEventResources = (csn, global,packageIds) => global.aEvents.map((srv) => fCreateEventResourceTemplate(srv, csn.definitions[srv], global, packageIds)).filter((resource) => resource !== null && resource !== undefined);
|
|
165
|
+
|
|
166
|
+
module.exports = (csn) => {
|
|
167
|
+
const linkedCsn = cds.linked(csn);
|
|
168
|
+
Object.assign(global, fInitializeGlobal(linkedCsn));
|
|
169
|
+
const validateSystemNamespace = new RegExp(`^${global.applicationNamespace}\\.[^.]+\\..+$`);
|
|
170
|
+
if (global.namespace === undefined && !validateSystemNamespace.test(global.namespace)) {
|
|
171
|
+
let error = new Error(`Namespace is not defined in cdsrc.json or it is not in the format of ${global.applicationNamespace}.<appName>.<service>`);
|
|
172
|
+
console.error('Namespace error:', error.message);
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let oReturn = {openResourceDiscovery: "1.9",
|
|
177
|
+
policyLevel: fGetPolicyLevel(global),
|
|
178
|
+
description: fGetDescription(global),
|
|
179
|
+
products: fGetProducts(global),
|
|
180
|
+
groups: fGetGroups(linkedCsn, global),
|
|
181
|
+
};
|
|
182
|
+
if(fGetAPIResources(linkedCsn, global).length > 0 && (fGetEventResources(linkedCsn, global).length>0)){
|
|
183
|
+
oReturn.packages = fGetPackages(oReturn.policyLevel, global);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// check if oReturn.packages is defined and extract the ordId from the packages and store in a set
|
|
187
|
+
let packageIds = new Set();
|
|
188
|
+
if(oReturn.packages){
|
|
189
|
+
oReturn.packages.forEach((pkg) => {
|
|
190
|
+
packageIds.add(pkg.ordId);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
oReturn = {
|
|
194
|
+
...oReturn,
|
|
195
|
+
consumptionBundles: fGetConsumptionBundles(global),
|
|
196
|
+
apiResources: fGetAPIResources(linkedCsn, global,packageIds),
|
|
197
|
+
};
|
|
198
|
+
if(fGetEventResources(linkedCsn, global,packageIds).length > 0) {
|
|
199
|
+
oReturn.eventResources= fGetEventResources(linkedCsn, global,packageIds);
|
|
200
|
+
}
|
|
201
|
+
return oReturn;
|
|
202
|
+
}
|
package/lib/plugin.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const { ord, getMetadata, defaults } = require("./");
|
|
2
|
+
const cds = require("@sap/cds");
|
|
3
|
+
|
|
4
|
+
cds.on("bootstrap", (app) => {
|
|
5
|
+
app.use("/.well-known/open-resource-discovery", async (req, res) => {
|
|
6
|
+
if (req.url === "/") {
|
|
7
|
+
res.status(200).send(defaults.baseTemplate);
|
|
8
|
+
} else {
|
|
9
|
+
try {
|
|
10
|
+
const { contentType, response } = await getMetadata(req.url);
|
|
11
|
+
res.status(200).contentType(contentType).send(response);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.log(error);
|
|
14
|
+
console.log('Error while generating metadata');
|
|
15
|
+
res.status(500).send(error.message);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
app.get("/open-resource-discovery/v1/documents/1", async (req, res) => {
|
|
21
|
+
try {
|
|
22
|
+
const csn = await cds.load(cds.env.folders.srv);
|
|
23
|
+
const data = ord(csn);
|
|
24
|
+
return res.status(200).send(data);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.log(error);
|
|
27
|
+
console.log('Error while creating ORD document');
|
|
28
|
+
return res.status(500).send(error.message);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
module.exports = cds.server;
|
package/lib/templates.js
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
const defaults = require("./defaults");
|
|
2
|
+
const cds = require("@sap/cds");
|
|
3
|
+
const fReplaceSpecialCharacters = (namespace) => {
|
|
4
|
+
return namespace.replace(/customer\.(.+)/, (match, group1) => 'customer.' + group1.replace(/[^a-zA-Z0-9]/g, ''))
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Reads the ORD (Open Resource Discovery) annotation from a given service definition object and returns them as an object.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} srv The service definition object.
|
|
11
|
+
* @returns {Object} An object containing ORD annotation.
|
|
12
|
+
*/
|
|
13
|
+
const fReadORDExtensions = (srv) =>
|
|
14
|
+
Object.entries(srv)
|
|
15
|
+
.filter(([key]) => key.startsWith("@ORD.Extensions."))
|
|
16
|
+
.reduce(
|
|
17
|
+
(ordExtensions, [key, value]) => ({
|
|
18
|
+
...ordExtensions,
|
|
19
|
+
[key.slice("@ORD.Extensions.".length)]: value,
|
|
20
|
+
}),
|
|
21
|
+
{}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Reads the service definition and returns an array of entryPoint paths.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} srv The service definition name.
|
|
28
|
+
* @param {Object} srvDefinition The service definition object.
|
|
29
|
+
* @returns {Array} An array containing paths and it's kind.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const fGeneratePaths = (srv, srvDefinition) => {
|
|
33
|
+
const srvObj = { name: srv, definition: srvDefinition };
|
|
34
|
+
const protocols = cds.service.protocols;
|
|
35
|
+
|
|
36
|
+
const paths = protocols.endpoints4(srvObj);
|
|
37
|
+
|
|
38
|
+
//TODO: check graphql replication in paths object and re-visit logic
|
|
39
|
+
//removing instances of graphql protocol from paths
|
|
40
|
+
for (var index = paths.length - 1; index >= 0; index--) {
|
|
41
|
+
if (paths[index].kind === "graphql") {
|
|
42
|
+
console.warn("Graphql protocol is not supported.");
|
|
43
|
+
paths.splice(index, 1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//putting default as odata in case no supported protcol is there
|
|
48
|
+
if (paths.length === 0) {
|
|
49
|
+
srvDefinition["@odata"] = true;
|
|
50
|
+
paths.push({ kind: "odata", path: protocols.path4(srvDefinition) });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return paths;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* This is a template function to create Entity Type object for Entity Type Array.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} entity The name of the entity.
|
|
60
|
+
* @returns {Object} An object for the entity type.
|
|
61
|
+
*/
|
|
62
|
+
const fCreateEntityTypeTemplate = (entity) => ({
|
|
63
|
+
ordId: `sap.odm:entityType:${entity["@ODM.entityName"]}:v1`,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This is a template function to form the group id.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} fullyQualifiedName The fully qualified name of the service or event.
|
|
70
|
+
* @param {string} groupTypeId The group type id.
|
|
71
|
+
* @returns {string} a group id.
|
|
72
|
+
*/
|
|
73
|
+
function _getGroupID(fullyQualifiedName, groupTypeId = defaults.groupTypeId, isService = true) {
|
|
74
|
+
if (isService) {
|
|
75
|
+
return `${groupTypeId}:${fReplaceSpecialCharacters(global.namespace)}:${fullyQualifiedName}`;
|
|
76
|
+
} else {
|
|
77
|
+
return `${groupTypeId}:${fReplaceSpecialCharacters(global.namespace)}:` +
|
|
78
|
+
`${fullyQualifiedName.slice(0, fullyQualifiedName.lastIndexOf("."))}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* This is a function to resolve the title of the service group.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} srv The name of the service.
|
|
87
|
+
* @returns {string} The title of the service group.
|
|
88
|
+
*/
|
|
89
|
+
function _getTitleFromServiceName(srv) {
|
|
90
|
+
let serviceName = srv.substring(srv.lastIndexOf(".") + 1);
|
|
91
|
+
let index = serviceName.indexOf("Service");
|
|
92
|
+
if (index >= 0) {
|
|
93
|
+
return `${serviceName.substring(0, index)} Service Title`;
|
|
94
|
+
} else {
|
|
95
|
+
return `${serviceName} Service Title`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* This is a template function to create group object of a service for groups array in ORD doc.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} srv The name of the service.
|
|
104
|
+
* @param {object} srvDefinition The definition of the service
|
|
105
|
+
* @param {Set} groupIds A set of group ids.
|
|
106
|
+
* @returns {Object} A group object.
|
|
107
|
+
*/
|
|
108
|
+
const fCreateGroupsTemplateForService = (srv, srvDefinition, groupIds) => {
|
|
109
|
+
const ordExtensions = fReadORDExtensions(srvDefinition);
|
|
110
|
+
|
|
111
|
+
let fullyQualifiedServiceName = srv;
|
|
112
|
+
if(!srv.includes(global.capNamespace)){
|
|
113
|
+
fullyQualifiedServiceName = global.capNamespace + "." + srv;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (checkEntityFunctionAction(srvDefinition, global).length > 0) {
|
|
117
|
+
let groupId = _getGroupID(fullyQualifiedServiceName, defaults.groupTypeId);
|
|
118
|
+
if (groupIds.has(groupId)) {
|
|
119
|
+
return null;
|
|
120
|
+
} else {
|
|
121
|
+
groupIds.add(groupId);
|
|
122
|
+
return {
|
|
123
|
+
groupId: groupId,
|
|
124
|
+
groupTypeId: `${defaults.groupTypeId}`,
|
|
125
|
+
title: ordExtensions.title ?? _getTitleFromServiceName(srv)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
*
|
|
133
|
+
* @param {string} event The name of the event.
|
|
134
|
+
* @returns {string} The title of the event group.
|
|
135
|
+
*/
|
|
136
|
+
function _getEventTitle(event) {
|
|
137
|
+
let serviceName = event.substring(0, event.lastIndexOf("."));
|
|
138
|
+
return _getTitleFromServiceName(serviceName);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* This is a template function to create group object of an event for groups array in ORD doc.
|
|
143
|
+
*
|
|
144
|
+
* @param {string} event The name of the event.
|
|
145
|
+
* @param {object} eventDefinition The definition of the event.
|
|
146
|
+
* @param {Set} groupIds A set of group ids.
|
|
147
|
+
* @returns {Object} A group object.
|
|
148
|
+
*/
|
|
149
|
+
const fCreateGroupsTemplateForEvent = (event, eventDefinition, groupIds) => {
|
|
150
|
+
const ordExtensions = fReadORDExtensions(eventDefinition);
|
|
151
|
+
|
|
152
|
+
let fullyQualifiedEventName = event;
|
|
153
|
+
if(!event.includes(global.capNamespace)){
|
|
154
|
+
fullyQualifiedEventName = global.capNamespace + "." + event;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let groupId = _getGroupID(fullyQualifiedEventName, defaults.groupTypeId, global, false);
|
|
158
|
+
if (groupIds.has(groupId)) {
|
|
159
|
+
return null;
|
|
160
|
+
} else {
|
|
161
|
+
groupIds.add(groupId);
|
|
162
|
+
return {
|
|
163
|
+
groupId: groupId,
|
|
164
|
+
groupTypeId: `${defaults.groupTypeId}`,
|
|
165
|
+
title: ordExtensions.title ?? _getEventTitle(event)
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* This is a template function to create API Resource object for API Resource Array.
|
|
172
|
+
*
|
|
173
|
+
* @param {string} srv The name of the service.
|
|
174
|
+
* @param {object} srvDefinition The definition of the service
|
|
175
|
+
* @returns {Array} An array of objects for the API Resources.
|
|
176
|
+
*/
|
|
177
|
+
const fCreateAPIResourceTemplate = (srv, srvDefinition, global,packageIds) => {
|
|
178
|
+
const ordExtensions = fReadORDExtensions(srvDefinition);
|
|
179
|
+
const paths = fGeneratePaths(srv, srvDefinition);
|
|
180
|
+
const apiResources = [];
|
|
181
|
+
|
|
182
|
+
let srvName = srv;
|
|
183
|
+
if (!srvName.includes(global.capNamespace)) {
|
|
184
|
+
srvName = global.capNamespace + "." + srv;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (checkEntityFunctionAction(srvDefinition, global).length > 0) {
|
|
188
|
+
paths.forEach((generatedPath) => {
|
|
189
|
+
let resourceDefinitions = [
|
|
190
|
+
{
|
|
191
|
+
type: "openapi-v3",
|
|
192
|
+
mediaType: "application/json",
|
|
193
|
+
url: `/.well-known/open-resource-discovery/v1/api-metadata/${srv}.oas3.json`,
|
|
194
|
+
accessStrategies: [{ type: "open" }],
|
|
195
|
+
},
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
if (generatedPath.kind !== "rest") {
|
|
199
|
+
//edmx resource definition is not generated in case of 'rest' protocol
|
|
200
|
+
resourceDefinitions.push({
|
|
201
|
+
type: "edmx",
|
|
202
|
+
mediaType: "application/xml",
|
|
203
|
+
url: `/.well-known/open-resource-discovery/v1/api-metadata/${srv}.edmx`,
|
|
204
|
+
accessStrategies: [{ type: "open" }],
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let obj = {
|
|
209
|
+
ordId: `${fReplaceSpecialCharacters(global.namespace)}:apiResource:${srvName}:v1`,
|
|
210
|
+
title:
|
|
211
|
+
ordExtensions.title ??
|
|
212
|
+
srvDefinition["@title"] ??
|
|
213
|
+
srvDefinition["@Common.Label"] ??
|
|
214
|
+
`The service is for ${srv}`,
|
|
215
|
+
shortDescription:
|
|
216
|
+
ordExtensions.shortDescription ??
|
|
217
|
+
`Here we have the shortDescription for ${srv}`,
|
|
218
|
+
description:
|
|
219
|
+
ordExtensions.description ??
|
|
220
|
+
srvDefinition["@Core.Description"] ??
|
|
221
|
+
`Here we have the description for ${srv}`,
|
|
222
|
+
version: ordExtensions.version ?? "1.0.0",
|
|
223
|
+
visibility: ordExtensions.visibility ?? "public",
|
|
224
|
+
partOfPackage: _getPackageID(global.capNamespace,packageIds,'api'),
|
|
225
|
+
partOfGroups: [_getGroupID(srvName, defaults.groupTypeId, global)],
|
|
226
|
+
releaseStatus: ordExtensions.active ?? "active",
|
|
227
|
+
partOfConsumptionBundles: [
|
|
228
|
+
{
|
|
229
|
+
ordId: `${fReplaceSpecialCharacters(global.namespace)}:consumptionBundle:noAuth:v1`,
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
apiProtocol:
|
|
233
|
+
generatedPath.kind === "odata" ? "odata-v4" : generatedPath.kind,
|
|
234
|
+
resourceDefinitions: resourceDefinitions,
|
|
235
|
+
entryPoints: [generatedPath.path],
|
|
236
|
+
extensible: {
|
|
237
|
+
supported: ordExtensions["extensible.supported"] ?? "no",
|
|
238
|
+
},
|
|
239
|
+
entityTypeMappings: [{ entityTypeTargets: global.aODMEntity }],
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
apiResources.push(obj);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (apiResources.length > 0) return apiResources;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* This is a template function to create Event Resource object for Event Resource Array.
|
|
250
|
+
*
|
|
251
|
+
* @param {string} srv The name of the event.
|
|
252
|
+
* @param {object} srvDefinition The definition of the event.
|
|
253
|
+
* @returns {Object} An object for the Event Resource.
|
|
254
|
+
*/
|
|
255
|
+
const fCreateEventResourceTemplate = (srv, srvDefinition, global,packageIds) => {
|
|
256
|
+
const ordExtensions = fReadORDExtensions(srvDefinition);
|
|
257
|
+
let srvName = srv;
|
|
258
|
+
if(!srvName.includes(global.capNamespace)){
|
|
259
|
+
srvName = global.capNamespace + "." + srv;
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
ordId: `${fReplaceSpecialCharacters(global.namespace)}:eventResource:${srvName}:v1`,
|
|
263
|
+
title: ordExtensions.title ?? srvDefinition['@title'] ?? srvDefinition['@Common.Label'] ?? `ODM ${global.appName.replace(/[^a-zA-Z0-9]/g, '')} Events`,
|
|
264
|
+
shortDescription: ordExtensions.shortDescription ?? "Example ODM Event",
|
|
265
|
+
description: ordExtensions.description ??
|
|
266
|
+
srvDefinition['@description'] ?? srvDefinition['@Core.Description'] ??
|
|
267
|
+
`This is an example event catalog that contains only a partial ODM ${global.appName} V1 event`,
|
|
268
|
+
version: ordExtensions.version ?? "1.0.0",
|
|
269
|
+
releaseStatus: ordExtensions.releaseStatus ?? "beta",
|
|
270
|
+
partOfPackage: _getPackageID(global.capNamespace,packageIds,'event'),
|
|
271
|
+
partOfGroups: [_getGroupID(srvName, defaults.groupTypeId, global, false)],
|
|
272
|
+
visibility: ordExtensions.visibility ?? "public",
|
|
273
|
+
resourceDefinitions: [
|
|
274
|
+
{
|
|
275
|
+
type: "asyncapi-v2",
|
|
276
|
+
mediaType: "application/json",
|
|
277
|
+
url: `/.well-known/open-resource-discovery/v1/api-metadata/${srvDefinition._service.name}.asyncapi2.json`,
|
|
278
|
+
accessStrategies: [
|
|
279
|
+
{
|
|
280
|
+
type: "open",
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
extensible: { supported: ordExtensions["extensible.supported"] ?? "no" },
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* This is a function to check whether entity is a function or action.
|
|
292
|
+
* @param {object} srvDefinition The definition of the event.
|
|
293
|
+
* @returns {Object} An object for the Event Resource.
|
|
294
|
+
*/
|
|
295
|
+
function checkEntityFunctionAction(srvDefinition, global) {
|
|
296
|
+
if (srvDefinition.entities) {
|
|
297
|
+
return srvDefinition.entities.map((entity) => {
|
|
298
|
+
return {
|
|
299
|
+
type: "entity",
|
|
300
|
+
name: entity.name,
|
|
301
|
+
entityType: entity.name,
|
|
302
|
+
entitySet: entity.name,
|
|
303
|
+
entityTypeMapping: `${global.namespace}:entityType:${entity.name}:v1`,
|
|
304
|
+
entitySetMapping: `${global.namespace}:entitySet:${entity.name}:v1`,
|
|
305
|
+
};
|
|
306
|
+
});
|
|
307
|
+
} else if (srvDefinition.actions) {
|
|
308
|
+
return srvDefinition.actions.map((action) => {
|
|
309
|
+
return {
|
|
310
|
+
type: "action",
|
|
311
|
+
name: action.name,
|
|
312
|
+
actionType: action.name,
|
|
313
|
+
actionMapping: `${global.namespace}:action:${action.name}:v1`,
|
|
314
|
+
};
|
|
315
|
+
});
|
|
316
|
+
} else if (srvDefinition.functions) {
|
|
317
|
+
return srvDefinition.functions.map((func) => {
|
|
318
|
+
return {
|
|
319
|
+
type: "function",
|
|
320
|
+
name: func.name,
|
|
321
|
+
functionType: func.name,
|
|
322
|
+
functionMapping: `${global.namespace}:function:${func.name}:v1`,
|
|
323
|
+
};
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* This is a function to get the corresponding package ordId mapped to the service.
|
|
330
|
+
*/
|
|
331
|
+
|
|
332
|
+
function _getPackageID(capNamespace, packageIds, apiOrEvent) {
|
|
333
|
+
if (packageIds instanceof Set) {
|
|
334
|
+
const packageArray = Array.from(packageIds);
|
|
335
|
+
|
|
336
|
+
if (apiOrEvent === "api") {
|
|
337
|
+
const apiPackage = packageArray.find(pkg => pkg.includes("-api"));
|
|
338
|
+
if (apiPackage) return apiPackage;
|
|
339
|
+
} else if (apiOrEvent === "event") {
|
|
340
|
+
const eventPackage = packageArray.find(pkg => pkg.includes("-event"));
|
|
341
|
+
if (eventPackage) return eventPackage;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return packageArray.find(pkg => pkg.includes(capNamespace));
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
module.exports = {
|
|
349
|
+
fCreateEntityTypeTemplate,
|
|
350
|
+
fCreateGroupsTemplateForService,
|
|
351
|
+
fCreateGroupsTemplateForEvent,
|
|
352
|
+
fCreateAPIResourceTemplate,
|
|
353
|
+
fCreateEventResourceTemplate,
|
|
354
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cap-js/ord",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CAP Tool for generating ORD information",
|
|
5
|
+
"repository": "cap-js/ord",
|
|
6
|
+
"author": "SAP SE (https://www.sap.com)",
|
|
7
|
+
"homepage": "https://cap.cloud.sap/",
|
|
8
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
9
|
+
"main": "./cds-plugin.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"lib",
|
|
12
|
+
"data",
|
|
13
|
+
"LICENSES"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"lint": "npx eslint ."
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"eslint": "^8"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@sap/cds": ">=7.6",
|
|
23
|
+
"@cap-js/asyncapi": "^1.0.0",
|
|
24
|
+
"@cap-js/openapi": "^1.0.2"
|
|
25
|
+
}
|
|
26
|
+
}
|