@sap/cds-dk 7.9.6 → 8.0.3

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.
Files changed (291) hide show
  1. package/CHANGELOG.md +2136 -0
  2. package/bin/add.js +18 -52
  3. package/bin/bind.js +2 -2
  4. package/bin/build.js +29 -4
  5. package/bin/cds.js +31 -14
  6. package/bin/compile/index.js +7 -6
  7. package/bin/completion/index.js +70 -46
  8. package/bin/completion/scripts/cds-bash.sh +4 -1
  9. package/bin/completion/scripts/cds-fish.fish +13 -0
  10. package/bin/completion/scripts/cds-ps.ps1 +2 -1
  11. package/bin/completion/scripts/cds-zsh.sh +2 -1
  12. package/bin/deploy/index.js +6 -5
  13. package/bin/deploy/to-sqlite.js +2 -2
  14. package/bin/extend.js +19 -50
  15. package/bin/help.js +2 -2
  16. package/bin/init.js +10 -77
  17. package/bin/login.js +13 -5
  18. package/bin/migrate.js +1 -1
  19. package/bin/pull.js +11 -0
  20. package/bin/repl.js +3 -0
  21. package/bin/test.js +5 -0
  22. package/bin/version.js +7 -7
  23. package/bin/watch.js +13 -14
  24. package/lib/bind/KubernetesApiAccessor.js +10 -9
  25. package/lib/build/buildTaskEngine.js +11 -7
  26. package/lib/build/buildTaskFactory.js +15 -43
  27. package/lib/build/buildTaskProviderFactory.js +16 -44
  28. package/lib/build/constants.js +4 -3
  29. package/lib/build/index.js +2 -2
  30. package/lib/build/{buildPlugin.js → plugin.js} +65 -46
  31. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/Chart.yaml +1 -1
  32. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/values.yaml +1 -1
  33. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/Chart.yaml +1 -1
  34. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/templates/_helpers.tpl +7 -0
  35. package/lib/build/plugins/helm/files/subcharts/service-instance/templates/servicebinding.yaml +32 -0
  36. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/templates/serviceinstance.yaml +3 -0
  37. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/values.schema.json +63 -0
  38. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/values.yaml +23 -1
  39. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/Chart.yaml +1 -1
  40. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/deployment.yaml +2 -0
  41. package/lib/build/plugins/helm/files/subcharts/web-application/templates/hpa.yaml +22 -0
  42. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/pod-disruption-budget.yaml +1 -0
  43. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/values.schema.json +49 -0
  44. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/values.yaml +8 -2
  45. package/lib/{init/template/helm/files/chart → build/plugins/helm/files}/templates/_deployment_helpers.tpl +5 -0
  46. package/lib/build/plugins/helm/files/templates/_helpers.tpl +13 -0
  47. package/lib/build/plugins/helm/index.js +81 -0
  48. package/lib/build/plugins.js +12 -15
  49. package/lib/build/provider/featureToggleBuildPlugin.js +7 -39
  50. package/lib/build/provider/hana/2migration.js +168 -124
  51. package/lib/build/provider/hana/index.js +69 -56
  52. package/lib/build/provider/hana/template/package.json +4 -3
  53. package/lib/build/provider/internalBuildPlugin.js +32 -97
  54. package/lib/build/provider/internalBuildTaskProvider.js +12 -48
  55. package/lib/build/provider/java/index.js +2 -3
  56. package/lib/build/provider/mtx/index.js +5 -4
  57. package/lib/build/provider/mtx-extension/index.js +5 -2
  58. package/lib/build/provider/mtx-sidecar/index.js +2 -2
  59. package/lib/build/provider/nodejs/index.js +4 -3
  60. package/lib/build/util.js +83 -12
  61. package/lib/compile/to-mermaid.js +108 -0
  62. package/lib/compile/to_asyncapi.js +7 -0
  63. package/lib/compile/to_openapi.js +7 -0
  64. package/lib/deploy/to-hana/hana.js +37 -34
  65. package/lib/deploy/to-hana/hdiDeployUtil.js +8 -6
  66. package/lib/env/schemas/cds-rc.js +1 -1
  67. package/lib/import/common.js +2 -2
  68. package/lib/import/odata/metadataconverter/MetadataConverter.js +4 -4
  69. package/lib/import/odata/v2parser.js +83 -197
  70. package/lib/import/odata/v4parser.js +1 -38
  71. package/lib/import/openapi/importOpenAPI.js +164 -42
  72. package/lib/index.js +10 -12
  73. package/lib/init/bas.js +91 -0
  74. package/lib/init/constants.js +21 -11
  75. package/lib/init/index.js +72 -150
  76. package/lib/init/merge.js +12 -20
  77. package/lib/init/mvn.js +103 -150
  78. package/lib/init/plugin.js +11 -7
  79. package/lib/init/projectReader.js +53 -20
  80. package/lib/init/registries/mta.js +51 -6
  81. package/lib/init/template/application-logging/files/package.json.hbs +7 -0
  82. package/lib/init/template/application-logging/index.js +13 -1
  83. package/lib/init/template/approuter/files/containerize.yaml.hbs +10 -0
  84. package/lib/init/template/approuter/files/mta.yaml.hbs +1 -2
  85. package/lib/init/template/approuter/files/values.yaml.hbs +19 -4
  86. package/lib/init/template/approuter/files/xs-app.json.hbs +12 -3
  87. package/lib/init/template/approuter/index.js +29 -25
  88. package/lib/init/template/attachments/files/mta.yaml.hbs +14 -0
  89. package/lib/init/template/attachments/files/package.json.hbs +5 -0
  90. package/lib/init/template/attachments/files/values.yaml +7 -0
  91. package/lib/init/template/attachments/index.js +53 -0
  92. package/lib/init/template/{redis-messaging → audit-logging}/files/mta.yaml.hbs +4 -4
  93. package/lib/init/template/audit-logging/files/package.json.hbs +7 -0
  94. package/lib/init/template/audit-logging/index.js +66 -0
  95. package/lib/init/template/cf-manifest/index.js +4 -0
  96. package/lib/init/template/completion/completionSetup.js +54 -33
  97. package/lib/init/template/completion/index.js +7 -1
  98. package/lib/init/template/connectivity/index.js +4 -4
  99. package/lib/init/template/containerize/files/containerize.yaml.hbs +26 -0
  100. package/lib/init/template/containerize/index.js +24 -0
  101. package/lib/init/template/data/index.js +4 -0
  102. package/lib/init/template/destination/files/mta.yaml.hbs +31 -1
  103. package/lib/init/template/destination/files/package.sidecar.json +7 -0
  104. package/lib/init/template/destination/index.js +22 -2
  105. package/lib/init/template/enterprise-messaging/index.js +6 -3
  106. package/lib/init/template/enterprise-messaging-shared/index.js +5 -1
  107. package/lib/init/template/extensibility/files/package.json.hbs +1 -1
  108. package/lib/init/template/extensibility/files/xs-security.json.hbs +2 -8
  109. package/lib/init/template/extensibility/index.js +3 -1
  110. package/lib/init/template/file-based-messaging/index.js +4 -0
  111. package/lib/init/template/h2/index.js +4 -0
  112. package/lib/init/template/hana/files/containerize.yaml.hbs +10 -0
  113. package/lib/init/template/hana/files/db/package.json +3 -2
  114. package/lib/init/template/hana/files/package.json.hbs +4 -7
  115. package/lib/init/template/hana/files/values.yaml.hbs +1 -2
  116. package/lib/init/template/hana/index.js +15 -7
  117. package/lib/init/template/helm/files/Chart.yaml.hbs +2 -3
  118. package/lib/init/template/helm/files/values.schema.json +2173 -0
  119. package/lib/init/template/helm/files/values.yaml.hbs +11 -6
  120. package/lib/init/template/helm/index.js +77 -18
  121. package/lib/init/template/helm-unified-runtime/index.js +19 -56
  122. package/lib/init/template/html5-repo/files/app-package.json.hbs +11 -7
  123. package/lib/init/template/html5-repo/files/manifest.json +13 -0
  124. package/lib/init/template/html5-repo/files/mta.yaml.hbs +14 -33
  125. package/lib/init/template/html5-repo/files/package.sidecar.json +7 -0
  126. package/lib/init/template/html5-repo/files/ui5-deploy.yaml.hbs +21 -0
  127. package/lib/init/template/html5-repo/files/ui5.yaml.hbs +2 -29
  128. package/lib/init/template/html5-repo/files/values.yaml.hbs +6 -2
  129. package/lib/init/template/html5-repo/files/xs-app.json.hbs +6 -7
  130. package/lib/init/template/html5-repo/index.js +41 -35
  131. package/lib/init/template/http/index.js +36 -12
  132. package/lib/init/template/java/index.js +18 -12
  133. package/lib/init/template/kafka/index.js +4 -0
  134. package/lib/init/template/lint/index.js +7 -2
  135. package/lib/init/template/liquibase/index.js +4 -0
  136. package/lib/init/template/local-messaging/index.js +4 -0
  137. package/lib/init/template/malware-scanner/files/mta.yaml.hbs +14 -0
  138. package/lib/init/template/malware-scanner/files/package.json.hbs +17 -0
  139. package/lib/init/template/malware-scanner/files/values.yaml +7 -0
  140. package/lib/init/template/malware-scanner/index.js +47 -0
  141. package/lib/init/template/mta/files/mta.yaml.hbs +3 -3
  142. package/lib/init/template/mta/files/package.json +1 -1
  143. package/lib/init/template/mta/index.js +4 -0
  144. package/lib/init/template/mtx/index.js +4 -0
  145. package/lib/init/template/multitenancy/files/containerize.yaml.hbs +10 -0
  146. package/lib/init/template/multitenancy/files/mta.yaml.hbs +0 -1
  147. package/lib/init/template/multitenancy/files/package.json.hbs +1 -1
  148. package/lib/init/template/multitenancy/files/package.sidecar.json.hbs +6 -5
  149. package/lib/init/template/multitenancy/files/values.yaml.hbs +14 -24
  150. package/lib/init/template/multitenancy/index.js +50 -28
  151. package/lib/init/template/nodejs/files/eslint.config.mjs +2 -0
  152. package/lib/init/template/nodejs/files/package.json.hbs +2 -3
  153. package/lib/init/template/nodejs/index.js +4 -0
  154. package/lib/init/template/notifications/files/mta.yaml.hbs +2 -2
  155. package/lib/init/template/notifications/index.js +4 -0
  156. package/lib/init/template/pipeline/files/.pipeline/config.yml +1 -1
  157. package/lib/init/template/pipeline/files/Jenkinsfile +1 -1
  158. package/lib/init/template/pipeline/index.js +4 -0
  159. package/lib/init/template/portal/files/mta.yaml.hbs +52 -0
  160. package/lib/init/template/portal/files/package.json.hbs +11 -0
  161. package/lib/init/template/portal/files/package.sidecar.json +7 -0
  162. package/lib/init/template/portal/files/portal-site/CommonDataModel.json.hbs +97 -0
  163. package/lib/init/template/portal/files/portal-site/i18n/catalog.properties +1 -0
  164. package/lib/init/template/portal/files/portal-site/i18n/catalog_de.properties +1 -0
  165. package/lib/init/template/portal/files/portal-site/i18n/group.properties +1 -0
  166. package/lib/init/template/portal/files/portal-site/i18n/group_de.properties +1 -0
  167. package/lib/init/template/portal/index.js +84 -0
  168. package/lib/init/template/postgres/index.js +5 -1
  169. package/lib/init/template/redis/files/mta.yaml.hbs +25 -0
  170. package/lib/init/template/redis/files/package.json.hbs +5 -0
  171. package/lib/init/template/redis/index.js +44 -0
  172. package/lib/init/template/redis-messaging/files/package.json.hbs +0 -3
  173. package/lib/init/template/redis-messaging/index.js +8 -18
  174. package/lib/init/template/sample/files/app/admin-books/webapp/i18n/i18n_de.properties +3 -0
  175. package/lib/init/template/sample/files/app/admin-books/webapp/i18n/i18n_en.properties +3 -0
  176. package/lib/init/template/sample/files/app/admin-books/webapp/manifest.json +13 -1
  177. package/lib/init/template/sample/files/app/browse/webapp/i18n/i18n.properties +2 -2
  178. package/lib/init/template/sample/files/app/browse/webapp/i18n/i18n_de.properties +3 -0
  179. package/lib/init/template/sample/files/app/browse/webapp/i18n/i18n_en.properties +4 -0
  180. package/lib/init/template/sample/files/app/browse/webapp/manifest.json +3 -3
  181. package/lib/init/template/sample/files/app/index.html +1 -1
  182. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Authors.csv +5 -5
  183. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Books.csv +6 -6
  184. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Books_texts.csv +5 -5
  185. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Genres.csv +16 -16
  186. package/lib/init/template/sample/files/nodejs/cat-service.js +2 -2
  187. package/lib/init/template/sample/files/package.json.hbs +3 -0
  188. package/lib/init/template/sample/index.js +16 -9
  189. package/lib/init/template/sqlite/index.js +4 -0
  190. package/lib/init/template/tiny-sample/files/nodejs/db/data/my.bookshop-Books.csv +3 -3
  191. package/lib/init/template/tiny-sample/files/nodejs/srv/cat-service.cds.hbs +1 -1
  192. package/lib/init/template/tiny-sample/index.js +4 -0
  193. package/lib/init/template/toggles/files/package.json.hbs +1 -1
  194. package/lib/init/template/toggles/index.js +4 -0
  195. package/lib/init/template/typer/index.js +4 -0
  196. package/lib/init/template/typescript/files/package.json +12 -0
  197. package/lib/init/template/typescript/files/tsconfig.json +13 -0
  198. package/lib/init/template/typescript/index.js +39 -0
  199. package/lib/init/template/workzone/index.js +9 -0
  200. package/lib/init/template/workzone-standard/files/manifest.json.hbs +6 -0
  201. package/lib/init/template/workzone-standard/files/mta.yaml.hbs +59 -0
  202. package/lib/init/template/workzone-standard/index.js +46 -0
  203. package/lib/init/template/xsuaa/files/package.json.hbs +1 -1
  204. package/lib/init/template/xsuaa/files/values.yaml.hbs +3 -2
  205. package/lib/init/template/xsuaa/index.js +11 -7
  206. package/lib/init/validate.js +27 -0
  207. package/lib/lint/generators.js +1 -1
  208. package/lib/lint/io.js +25 -7
  209. package/lib/mtx/auth_manager.js +64 -30
  210. package/lib/mtx/download_legacy.js +2 -2
  211. package/lib/mtx/index.js +0 -4
  212. package/lib/mtx/params.js +32 -38
  213. package/lib/mtx/pull.js +151 -43
  214. package/lib/mtx/push.js +3 -3
  215. package/lib/mtx/settings_manager.js +75 -35
  216. package/lib/mtx/tenant_action.js +1 -1
  217. package/lib/mtx/util/cf.js +1 -1
  218. package/lib/mtx/util/fs.js +26 -1
  219. package/lib/mtx/util/logging.js +7 -3
  220. package/lib/util/command.js +0 -2
  221. package/lib/util/fs.js +2 -3
  222. package/lib/util/question.js +28 -0
  223. package/lib/util/term.js +5 -3
  224. package/npm-shrinkwrap.json +225 -1083
  225. package/package.json +13 -8
  226. package/bin/activate.js +0 -77
  227. package/lib/compile/asyncapi/channels.js +0 -22
  228. package/lib/compile/asyncapi/components/messageTraits/index.js +0 -89
  229. package/lib/compile/asyncapi/components/messages/index.js +0 -173
  230. package/lib/compile/asyncapi/components/schemas/annotations.js +0 -33
  231. package/lib/compile/asyncapi/components/schemas/array.js +0 -8
  232. package/lib/compile/asyncapi/components/schemas/cache.js +0 -14
  233. package/lib/compile/asyncapi/components/schemas/definition.js +0 -187
  234. package/lib/compile/asyncapi/components/schemas/enum.js +0 -16
  235. package/lib/compile/asyncapi/components/schemas/examples.js +0 -10
  236. package/lib/compile/asyncapi/components/schemas/index.js +0 -14
  237. package/lib/compile/asyncapi/components/schemas/localized.js +0 -29
  238. package/lib/compile/asyncapi/components/schemas/primitiveElement.js +0 -41
  239. package/lib/compile/asyncapi/components/schemas/ref.js +0 -45
  240. package/lib/compile/asyncapi/components/schemas/utils.js +0 -108
  241. package/lib/compile/asyncapi/index.js +0 -247
  242. package/lib/compile/asyncapi/message.js +0 -13
  243. package/lib/compile/asyncapi/utils.js +0 -27
  244. package/lib/compile/openapi/csdl2openapi.js +0 -2448
  245. package/lib/compile/openapi/index.js +0 -68
  246. package/lib/init/template/helm/files/chart/templates/NOTES.txt +0 -14
  247. package/lib/init/template/helm/files/chart/templates/_helpers.tpl +0 -28
  248. package/lib/init/template/helm/files/chart/values.root.schema.json +0 -61
  249. package/lib/init/template/helm/files/chart/values.schema.json +0 -366
  250. package/lib/init/template/helm-unified-runtime/files/Chart.yaml.hbs +0 -10
  251. package/lib/init/template/helm-unified-runtime/files/templates/_deployment_helpers.tpl +0 -90
  252. package/lib/init/template/helm-unified-runtime/files/templates/_helpers.tpl +0 -28
  253. package/lib/init/template/helm-unified-runtime/files/values.root.schema.json +0 -61
  254. package/lib/init/template/helm-unified-runtime/files/values.schema.json +0 -366
  255. package/lib/init/template/helm-unified-runtime/files/values.yaml.hbs +0 -26
  256. package/lib/init/template/helm-unified-runtime/package.json +0 -4
  257. package/lib/init/template/multitenancy/files/mtxs-configmap-java-approuter.yaml +0 -20
  258. package/lib/init/template/multitenancy/files/mtxs-configmap-java.yaml +0 -18
  259. package/lib/init/template/multitenancy/files/mtxs-configmap-nodejs-approuter.yaml +0 -12
  260. package/lib/init/template/multitenancy/files/mtxs-configmap-nodejs.yaml +0 -12
  261. package/lib/init/template/multitenancy/files/saas-registry-secret.yaml +0 -9
  262. package/lib/init/template/nodejs/files/eslint.config.js +0 -13
  263. package/lib/init/template/notebook/index.js +0 -11
  264. package/lib/init/template/samples/index.js +0 -9
  265. package/lib/mtx/activate.js +0 -238
  266. package/lib/mtx/extend.js +0 -173
  267. package/lib/util/exec.d.ts +0 -54
  268. package/lib/util/exec.js +0 -211
  269. /package/lib/{init/template/approuter/files → build/plugins/helm/files/plugins/approuter}/approuter-configmap.yaml +0 -0
  270. /package/lib/{init/template/connectivity/files → build/plugins/helm/files/plugins/connectivity}/connectivity-proxy-info.yaml +0 -0
  271. /package/lib/{init/template/html5-repo/files → build/plugins/helm/files/plugins/html5-repo}/html5-apps-deployer-configmap.yaml +0 -0
  272. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/_helpers.tpl +0 -0
  273. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/job.yaml +0 -0
  274. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/secret.yaml +0 -0
  275. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/service-account.yaml +0 -0
  276. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/service-binding.yaml +0 -0
  277. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/values.schema.json +0 -0
  278. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/NOTES.txt +0 -0
  279. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/_api.tpl +0 -0
  280. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/_helpers.tpl +0 -0
  281. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/api-rule.yaml +0 -0
  282. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/network-policy.yaml +0 -0
  283. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/rbac.yaml +0 -0
  284. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/secret.yaml +0 -0
  285. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/service-account.yaml +0 -0
  286. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/service-binding.yaml +0 -0
  287. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/service.yaml +0 -0
  288. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/virtual-service.yaml +0 -0
  289. /package/lib/{init/template/helm-unified-runtime → build/plugins/helm}/files/templates/NOTES.txt +0 -0
  290. /package/lib/init/template/{nodejs/files → java}/.cdsrc.json +0 -0
  291. /package/lib/init/template/tiny-sample/files/nodejs/db/{data-model.cds → schema.cds} +0 -0
@@ -104,6 +104,8 @@ function operations(context, csn, input) {
104
104
  cdsOperation["@openapi.method"] = method.toUpperCase();
105
105
  cdsOperation["@openapi.path"] = path;
106
106
 
107
+ let bodyParam;
108
+
107
109
  for (let param of globalParameters.concat(operation.parameters || [])) {
108
110
  if (param.$ref) {
109
111
  // resolve reuse parameter
@@ -116,7 +118,10 @@ function operations(context, csn, input) {
116
118
  param = reuseParameters[param.$ref.substring(expectedPrefix.length)];
117
119
  }
118
120
 
119
- if (param.in === "body") continue;
121
+ if (param.in === "body") {
122
+ bodyParam = param;
123
+ continue;
124
+ }
120
125
  if (STANDARD_HEADERS.includes(param.name.toLowerCase())) continue;
121
126
 
122
127
  const cdsParam = cdsType(
@@ -160,11 +165,13 @@ function operations(context, csn, input) {
160
165
  cdsOperation.params[name] = cdsParam;
161
166
  }
162
167
 
163
- const schema = requestBodySchema(context, operation);
164
- if (schema) {
165
- cdsOperation.params.body = cdsType(context, schema);
166
- cdsOperation.params.body["@openapi.in"] = "body";
167
- }
168
+ const schema = context.v3
169
+ ? requestBodySchema(context, operation.requestBody, input.components)
170
+ : v2Schema(context, bodyParam?.schema, operation.consumes);
171
+ if (schema) {
172
+ cdsOperation.params.body = cdsType(context, schema);
173
+ cdsOperation.params.body["@openapi.in"] = "body";
174
+ }
168
175
 
169
176
  if (!operation.responses)
170
177
  throw new Error(`TODO: no responses for path ${path}, method ${method}`);
@@ -186,8 +193,8 @@ function operations(context, csn, input) {
186
193
  reuseResponses[response.$ref.substring(expectedPrefix.length)];
187
194
  }
188
195
  const responseSchema = context.v3
189
- ? response.content?.["application/json"]?.schema
190
- : response.schema;
196
+ ? v3Schema(context, response)
197
+ : v2Schema(context, response.schema, operation.produces);
191
198
  if (responseSchema)
192
199
  cdsOperation.returns = cdsType(context, responseSchema);
193
200
  else if (method === "get")
@@ -209,13 +216,64 @@ function operations(context, csn, input) {
209
216
  }
210
217
  }
211
218
 
212
- function requestBodySchema(context, operation) {
213
- const requestBody = context.v3
214
- ? operation.requestBody
215
- : operation.parameters?.find((p) => p.in === "body");
216
- return context.v3
217
- ? requestBody?.content["application/json"]?.schema
218
- : requestBody?.schema;
219
+ function requestBodySchema(context, requestBody, components) {
220
+ while (requestBody?.$ref) {
221
+ const expectedPrefix = "#/components/requestBodies/";
222
+ if (!requestBody.$ref.startsWith(expectedPrefix)) {
223
+ requestBody = undefined;
224
+ throw new Error(`TODO: unexpected request body reference ${requestBody.$ref}`)
225
+ }
226
+ else {
227
+ requestBody =
228
+ components?.requestBodies[
229
+ requestBody.$ref.substring(expectedPrefix.length)
230
+ ];
231
+ }
232
+ }
233
+
234
+ return v3Schema(context, requestBody);
235
+ }
236
+
237
+ function v3Schema(context, body) {
238
+ if (!body?.content) return undefined;
239
+
240
+ const contentTypes = Object.keys(body.content);
241
+ if (contentTypes.includes("application/json"))
242
+ return body.content["application/json"].schema;
243
+
244
+ if (contentTypes.length === 0) return undefined;
245
+
246
+ if (contentTypes.length > 1)
247
+ context.messages.push({
248
+ message: `Multiple requestBody content-types not including application/json`,
249
+ input: contentTypes,
250
+ });
251
+
252
+ const contentType = contentTypes[0];
253
+
254
+ return {
255
+ $contentType: contentType,
256
+ ...body.content[contentType]?.schema,
257
+ };
258
+ }
259
+
260
+ function v2Schema(context, schema, contentTypes) {
261
+ if (
262
+ !schema ||
263
+ !contentTypes ||
264
+ contentTypes.includes("application/json") ||
265
+ contentTypes.includes("application/json;charset=utf-8") ||
266
+ contentTypes.includes("application/json;charset=UTF-8")
267
+ )
268
+ return schema;
269
+
270
+ // take the first content type if there are multiple
271
+ const contentType = contentTypes[0];
272
+
273
+ return {
274
+ $contentType: contentType,
275
+ ...schema,
276
+ };
219
277
  }
220
278
 
221
279
  function cdsType(
@@ -230,9 +288,23 @@ function cdsType(
230
288
 
231
289
  if (!arrayItem) if (schema.title) type["@title"] = schema.title;
232
290
  if (schema.description) type["@description"] = schema.description;
291
+ if (schema.$contentType && schema.$contentType !== '*/*')
292
+ type['@openapi.contentType'] = schema.$contentType;
293
+
233
294
 
234
295
  if (schema.$ref) {
235
- type.type = referencedType(context, schema.$ref).name;
296
+ const refType = referencedType(context, schema.$ref);
297
+ let nRefType = refType;
298
+ if (refType.schema?.$ref)
299
+ nRefType = indirectlyReferencedType(context, refType.schema);
300
+ if (namedType && normalizeSchemaType(nRefType.schema) === "object") {
301
+ type.kind = "type";
302
+ type.includes = [refType.name];
303
+ type.elements = {};
304
+ } else {
305
+ type.type = refType.name;
306
+ if (schema.maxLength) type.length = schema.maxLength;
307
+ }
236
308
  return type;
237
309
  }
238
310
 
@@ -241,7 +313,7 @@ function cdsType(
241
313
  switch (schemaType) {
242
314
  case "array":
243
315
  //TODO: complain if "xml"
244
- {
316
+ if (schema.items) {
245
317
  const itemsType = cdsType(
246
318
  context,
247
319
  schema.items,
@@ -258,6 +330,8 @@ function cdsType(
258
330
  } else {
259
331
  type.items = itemsType;
260
332
  }
333
+ } else {
334
+ type = someJSON(context, schema, arrayItem, type);
261
335
  }
262
336
  break;
263
337
 
@@ -354,33 +428,62 @@ function cdsType(
354
428
 
355
429
  case undefined:
356
430
  schemaType = bestMatchingType(context, schema);
431
+ if (
432
+ (!namedType || schemaType !== "object") && schema.allOf && schema.allOf.length === 1 &&
433
+ Object.keys(schema).filter(
434
+ (k) => !["description", "nullable"].includes(k) && !k.startsWith("x-")
435
+ ).length === 1) {
436
+ const normalizedSchema = { ...schema.allOf[0] };
437
+ if (schema.description) normalizedSchema.description = schema.description;
438
+ type = cdsType(context, normalizedSchema, arrayItem, namedType, forParameter);
439
+ break;
440
+ }
441
+ if (schema.allOf && schema.allOf.length === 2 && schema.allOf[0].$ref && !schema.allOf[1].$ref && normalizeSchemaType(schema.allOf[1]) !== "object") {
442
+ const normalizedSchema = Object.assign(
443
+ { ...schema.allOf[0] },
444
+ schema.allOf[1]
445
+ );
446
+ type = cdsType(
447
+ context,
448
+ normalizedSchema,
449
+ arrayItem,
450
+ namedType,
451
+ forParameter
452
+ );
453
+ break;
454
+ }
455
+
357
456
  if (schemaType) {
358
457
  schema.type = schemaType;
359
- type = cdsType(context, schema, arrayItem, namedType);
458
+ type = cdsType(context, schema, arrayItem, namedType, forParameter);
360
459
  break;
361
460
  }
362
461
 
363
462
  // last resort
364
463
  // eslint-disable-next-line no-fallthrough
365
464
  default:
366
- {
367
- context.JSON = true;
368
- const jsonSchema = minimalSchema(schema);
369
- if (arrayItem && jsonSchema !== "{}") {
370
- type = anonymousType(context, {
371
- type: "common.JSON",
372
- "@JSON.Schema": jsonSchema,
373
- });
374
- } else {
375
- type.type = "common.JSON";
376
- if (jsonSchema !== "{}") type["@JSON.Schema"] = jsonSchema;
377
- }
378
- }
465
+ type = someJSON(context, schema, arrayItem, type);
379
466
  break;
380
467
  }
381
468
  return type;
382
469
  }
383
470
 
471
+ function someJSON(context, schema, arrayItem, type) {
472
+ context.JSON = true;
473
+ const jsonSchema = minimalSchema(schema);
474
+ if (arrayItem && jsonSchema !== "{}") {
475
+ type = anonymousType(context, {
476
+ type: "common.JSON",
477
+ "@openapi.schema": jsonSchema,
478
+ });
479
+ }
480
+ else {
481
+ type.type = "common.JSON";
482
+ if (jsonSchema !== "{}") type["@openapi.schema"] = jsonSchema;
483
+ }
484
+ return type;
485
+ }
486
+
384
487
  function addDefault(type, schema, forParameter) {
385
488
  if (schema.default !== undefined) type.default = { val: schema.default };
386
489
  if (forParameter) return;
@@ -397,6 +500,7 @@ function minimalSchema(schema) {
397
500
  const s = { ...schema };
398
501
  delete s.title;
399
502
  delete s.description;
503
+ delete s.$contentType;
400
504
  return JSON.stringify(s);
401
505
  }
402
506
 
@@ -420,19 +524,17 @@ function bestMatchingType(context, schema) {
420
524
  for (const subSchema of xOf) {
421
525
  // determine overall type of this construct
422
526
  if (subSchema.$ref) {
423
- let refType = { schema: subSchema };
424
- let limit = 10;
425
- while (refType.schema.$ref && limit-- > 0)
426
- refType = referencedType(context, refType.schema.$ref);
427
- if (
428
- refType.schema.allOf ||
429
- refType.schema.anyOf ||
430
- refType.schema.oneOf
431
- ) {
527
+ const refType = indirectlyReferencedType(context, subSchema);
528
+ if (!refType.schema) return undefined;
529
+
530
+ if (refType.schema.allOf || refType.schema.anyOf || refType.schema.oneOf) {
432
531
  const subType = bestMatchingType(context, refType.schema);
433
532
  type = betterType(type, { type: subType });
434
- } else type = betterType(type, refType.schema);
435
- } else {
533
+ }
534
+
535
+ else type = betterType(type, refType.schema);
536
+ }
537
+ else {
436
538
  //TODO: nested xOf - not yet encountered
437
539
  type = betterType(type, subSchema);
438
540
  }
@@ -441,6 +543,14 @@ function bestMatchingType(context, schema) {
441
543
  return type;
442
544
  }
443
545
 
546
+ function indirectlyReferencedType(context, subSchema) {
547
+ let refType = { schema: subSchema };
548
+ let limit = 10;
549
+ while (refType.schema?.$ref && limit-- > 0)
550
+ refType = referencedType(context, refType.schema.$ref);
551
+ return refType;
552
+ }
553
+
444
554
  function referencedType(context, ref) {
445
555
  const expectedPrefix = context.v3
446
556
  ? "#/components/schemas/"
@@ -457,7 +567,13 @@ function referencedType(context, ref) {
457
567
  }
458
568
 
459
569
  function normalizeSchemaType(schema) {
570
+ if (!schema) return undefined;
460
571
  if (!schema.type && schema.items) return "array";
572
+ if (!schema.type && schema.maxLength) return "string";
573
+ if (!schema.type && schema.pattern) return "string";
574
+
575
+ if (!schema.type && schema.enum?.every((v) => typeof v === "string"))
576
+ return "string";
461
577
 
462
578
  if (
463
579
  !schema.type &&
@@ -476,6 +592,12 @@ function normalizeSchemaType(schema) {
476
592
  schemaType.splice(index, 1);
477
593
  }
478
594
  if (schemaType.length === 1) schemaType = schemaType[0];
595
+ if (
596
+ schemaType.length === 2 &&
597
+ schemaType[0] === "integer" &&
598
+ schemaType[1] === "number"
599
+ )
600
+ return "number";
479
601
  }
480
602
  return schemaType;
481
603
  }
package/lib/index.js CHANGED
@@ -7,22 +7,19 @@ class CdsDk {
7
7
  return super.import = require('./import/importapi')
8
8
  }
9
9
 
10
+ /** @type { import('./cds').compile } */
10
11
  get compile() {
11
12
  let compile = require(_local('@sap/cds/lib/compile/cds-compile'))
12
13
  cds.extend (compile.to.constructor) .with (class {
13
- get asyncapi() { return super.asyncapi = require('./compile/asyncapi') }
14
- get openapi() { return super.openapi = require('./compile/openapi') }
14
+ get asyncapi() { return super.asyncapi = require('./compile/to_asyncapi') }
15
+ get openapi() { return super.openapi = require('./compile/to_openapi') }
15
16
  get xsuaa(){ return super.xsuaa = require('./compile/to-xsuaa') }
17
+ get mermaid(){ return super.mermaid = require('./compile/to-mermaid') }
16
18
  'edmx-v2'(csn,o) { return cds.compile.to.edmx(csn,{...o,flavor:'v2'}) }
17
19
  'edmx-v4'(csn,o) { return cds.compile.to.edmx(csn,{...o,flavor:'v4'}) }
18
20
  'edmx-w4'(csn,o) { return cds.compile.to.edmx(csn,{...o,flavor:'w4'}) }
19
21
  'edmx-x4'(csn,o) { return cds.compile.to.edmx(csn,{...o,flavor:'x4'}) }
20
22
  })
21
- // Compat to cds <=6. Esp. BAS tools need it, see cap/issues#13918
22
- // TODO remove compat w/ cds-dk 8
23
- if (compile.to.constructor.name === 'Object') { // not a class as in cds 7
24
- compile.to.xsuaa = require('./compile/to-xsuaa')
25
- }
26
23
  return super.compile = compile
27
24
  }
28
25
 
@@ -52,15 +49,16 @@ if (process.argv[2] in { add:1, init:1, help:1 }) {
52
49
  cds.extend (cds.constructor) .with (CdsDkBuild)
53
50
  }
54
51
 
55
- const MIN_SUPPORTED_CDS_VERSION = 6
56
- const [cdsVersion] = cds.version.split('.')
57
- if (parseInt(cdsVersion) < MIN_SUPPORTED_CDS_VERSION) {
52
+ const REQUIRED_CDS_MAJOR = 7, REQUIRED_CDS_MINOR = 2
53
+ const [major, minor] = cds.version.split('.').map(Number)
54
+ if (major < REQUIRED_CDS_MAJOR || major === REQUIRED_CDS_MAJOR && minor < REQUIRED_CDS_MINOR) {
58
55
  const [dkVersion] = require('../package.json').version.split('.')
56
+
59
57
  console.error(`
60
- This application uses '@sap/cds' version ${cdsVersion}, which is not compatible with the installed '@sap/cds-dk' version ${dkVersion}.
58
+ This application uses '@sap/cds' version ${major}.${minor}, which is not compatible with the installed '@sap/cds-dk' version ${dkVersion}.
61
59
  You can either:
62
60
  - update '@sap/cds' to the latest version (recommended)
63
- - downgrade '@sap/cds-dk' to version ${MIN_SUPPORTED_CDS_VERSION}
61
+ - downgrade '@sap/cds-dk' to version ${REQUIRED_CDS_MAJOR}
64
62
  `)
65
63
  process.exit(1)
66
64
  }
@@ -0,0 +1,91 @@
1
+ const path = require('node:path')
2
+ const cds = require('../../lib/cds')
3
+ const validate = require('./validate')
4
+ const { bold } = require('../util/term')
5
+ const { OPTIONS } = require('./constants')
6
+ const {
7
+ NODEJS, JAVA,
8
+ HANA, APPROUTER, XSUAA, APPLICATION_LOGGING, ENTERPRISE_MESSAGING,
9
+ MTA, MULTITENANCY, PIPELINE,
10
+ TINY_SAMPLE, SAMPLE
11
+ } = OPTIONS
12
+ const cwd = process.cwd()
13
+
14
+ module.exports = [{
15
+ title: 'Project Name',
16
+ description: 'Enter your project name.',
17
+ default: '',
18
+ target: 'projectName',
19
+ validate: async projectName => {
20
+ try {
21
+ cds.root = path.resolve(cwd, projectName || '.')
22
+ validate.projectName(projectName)
23
+ validate.projectFolder(path.join(cwd, projectName), cwd)
24
+ } catch (e) {
25
+ return e // BAS Yeoman generator requires error to be returned
26
+ }
27
+ return true
28
+ },
29
+ guiOptions: {
30
+ hint: 'This name is restricted to certain characters. A valid project name is compatible across platforms.',
31
+ mandatory: true
32
+ }
33
+ }, {
34
+ title: 'Type',
35
+ description: `Select your runtime.`,
36
+ default: NODEJS,
37
+ choices: [
38
+ { name: 'Node.js', value: NODEJS },
39
+ { name: 'Java', value: JAVA }
40
+ ],
41
+ multiple: false,
42
+ target: 'add',
43
+ guiOptions: {
44
+ hint: `The preferred runtime can't be changed afterwards. To use a different runtime, create a new project.`,
45
+ mandatory: true
46
+ }
47
+ }, {
48
+ title: 'Features',
49
+ description: 'Choose productive runtime capabilities for your application.',
50
+ default: '',
51
+ choices: [
52
+ { name: 'SAP HANA Cloud', value: HANA },
53
+ { name: 'SAP Application Router', value: APPROUTER },
54
+ { name: 'User Authentication via XSUAA', value: XSUAA },
55
+ { name: 'Application Logging', value: APPLICATION_LOGGING },
56
+ { name: 'SAP BTP Event Mesh', value: ENTERPRISE_MESSAGING }
57
+ ],
58
+ multiple: true,
59
+ target: 'add',
60
+ guiOptions: {
61
+ hint: `Choose any combination of features enriching the capabilities of your project. You can also add features later with ${bold('cds add')}`
62
+ }
63
+ }, {
64
+ title: 'Deployment',
65
+ description: 'Choose which way to deploy your project.',
66
+ default: '',
67
+ choices: [
68
+ { name: 'Cloud Foundry: MTA Deployment', value: MTA },
69
+ // { name: 'Kyma: Helm Deployment', value: HELM },
70
+ { name: 'Multitenancy', value: MULTITENANCY },
71
+ { name: 'CI/CD Pipeline Integration', value: PIPELINE },
72
+ ],
73
+ multiple: true,
74
+ target: 'add',
75
+ guiOptions: {
76
+ hint: `Choose any combination of features enriching the capabilities of your project. You can also add features later with ${bold('cds add')}`
77
+ }
78
+ }, {
79
+ title: 'Samples',
80
+ description: `Add sample content to your project.`,
81
+ default: '',
82
+ choices: [
83
+ { name: 'Minimal Sample', value: TINY_SAMPLE },
84
+ { name: 'Extended Sample with UI', value: SAMPLE }
85
+ ],
86
+ multiple: true,
87
+ target: 'add',
88
+ guiOptions: {
89
+ hint: 'Speed up your ramp-up phase with sample files in your project.'
90
+ }
91
+ }]
@@ -5,9 +5,10 @@ module.exports = {
5
5
  COMMAND_ADD: 'add',
6
6
 
7
7
  JAVA_LTS_VERSIONS: [17, 21],
8
- MAVEN_ARCHETYPE_VERSION: '2.10.1',
8
+ MAVEN_ARCHETYPE_VERSION: '3.0.0',
9
9
 
10
10
  OPTIONS: Object.freeze({
11
+ COMPLETION: 'completion',
11
12
  JAVA: 'java',
12
13
  JAVA_MVN: 'java:mvn',
13
14
  JAVA_PACKAGE: 'java:package',
@@ -15,22 +16,24 @@ module.exports = {
15
16
  SAMPLES: 'samples', // deprecated
16
17
  TINY_SAMPLE: 'tiny-sample',
17
18
  SAMPLE: 'sample',
18
- PIPELINE: 'pipeline',
19
- HELM_UNIFIED_RUNTIME: 'helm-unified-runtime',
20
- HELM: 'helm',
21
19
  MTA: 'mta',
22
- CONNECTIVITY: 'connectivity',
23
20
  CF_MANIFEST: 'cf-manifest',
24
- MTX: 'mtx',
21
+ HELM: 'helm',
22
+ HELM_UNIFIED_RUNTIME: 'helm-unified-runtime',
23
+ CONTAINERIZE: 'containerize',
25
24
  MULTITENANCY: 'multitenancy',
26
25
  TOGGLES: 'toggles',
27
26
  EXTENSIBILITY: 'extensibility',
27
+ MTX: 'mtx',
28
28
  XSUAA: 'xsuaa',
29
29
  HANA: 'hana',
30
30
  POSTGRES: 'postgres',
31
31
  SQLITE: 'sqlite',
32
32
  H2: 'h2',
33
33
  LIQUIBASE: 'liquibase',
34
+ REDIS: 'redis',
35
+ ATTACHMENTS: 'attachments',
36
+ MALWARE_SCANNER: 'malware-scanner',
34
37
  LOCAL_MESSAGING: 'local-messaging',
35
38
  FILE_BASED_MESSAGING: 'file-based-messaging',
36
39
  ENTERPRISE_MESSAGING: 'enterprise-messaging',
@@ -38,24 +41,31 @@ module.exports = {
38
41
  REDIS_MESSAGING: 'redis-messaging',
39
42
  KAFKA: 'kafka',
40
43
  APPROUTER: 'approuter',
44
+ CONNECTIVITY: 'connectivity',
41
45
  DESTINATION: 'destination',
42
- DATA: 'data',
46
+ HTML5_REPO: 'html5-repo',
47
+ PORTAL: 'portal',
43
48
  APPLICATION_LOGGING: 'application-logging',
49
+ AUDIT_LOGGING: 'audit-logging',
50
+ NOTIFICATIONS: 'notifications',
51
+ WORKZONE: 'workzone',
52
+ WORKZONE_STANDARD: 'workzone-standard',
53
+ DATA: 'data',
54
+ HTTP: 'http',
44
55
  LINT: 'lint',
45
56
  LINT_GLOBAL: 'lint:global',
46
57
  LINT_DEV: 'lint:dev',
58
+ PIPELINE: 'pipeline',
47
59
  TYPER: 'typer',
48
- HTML5_REPO: 'html5-repo',
49
- NOTIFICATIONS: 'notifications'
60
+ TYPESCRIPT: 'typescript'
50
61
  }),
51
62
 
52
63
  REGEX_JAVA_PACKAGE: /^[a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)*$/g,
53
64
  // copied from mbt error message
54
65
  REGEX_JAVA_VERSION: /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/,
55
- REGEX_PROJECT_NAME: /[^0-9a-zA-Z_-]+/g,
56
66
 
57
67
  URLS: Object.freeze({
58
- PIPELINE_HELP: 'https://sap.github.io/jenkins-library/',
68
+ PIPELINE_HELP: 'https://www.project-piper.io/',
59
69
  SAMPLES: 'https://github.com/SAP-samples/cloud-cap-samples',
60
70
  CAPIRE: 'https://cap.cloud.sap',
61
71
  MAVEN_ARCHETYPE_HELP: `https://cap.cloud.sap/docs/java/developing-applications/building#the-maven-archetype`,