From ed0b20734279ab56eafc0dded170cacff2f567fb Mon Sep 17 00:00:00 2001 From: Muskan Sethi Date: Thu, 27 Apr 2023 14:54:37 +0530 Subject: [PATCH 1/3] updating for asyncapi import --- guides/using-services.md | 9 +++++---- node.js/cds-dk.md | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/guides/using-services.md b/guides/using-services.md index 87d045d55..014ccf8ad 100644 --- a/guides/using-services.md +++ b/guides/using-services.md @@ -148,7 +148,7 @@ By default, CAP works with OData V4 and the EDMX export is in this protocol vers Import the API to your project using `cds import`. ```sh -cds import ~/Downloads/API_BUSINESS_PARTNER.edmx --keep-namespace --as cds +cds import --as cds ``` | Option | Description | @@ -157,7 +157,7 @@ cds import ~/Downloads/API_BUSINESS_PARTNER.edmx --keep-namespace --as cds | `--as cds` | The import creates a CDS file (for example _API_BUSINESS_PARTNER.cds_) instead of a CSN file. | -This adds the API in CSN format to the _srv/external_ folder and also copies the EDMX file into that folder. Additionally, for **Node.js** it adds the API as an external OData service to your _package.json_. You use this declaration later to connect to the remote service [using a destination](#use-destinations-with-node-js). +This adds the API in CSN format to the _srv/external_ folder and also copies the input file into that folder. Additionally, for **Node.js** it adds the API as an external service to your _package.json_. You use this declaration later to connect to the remote service [using a destination](#use-destinations-with-node-js). ```json "cds": { @@ -189,7 +189,8 @@ Now run `cds import ` - `--force` is applicable only in combination with `--as` option. By default the `--force` flag is set to false. > If set to true, existing CSN/CDS files from previous imports are overwritten. -The kind `odata-v2` is set when importing EDMX definitions of OData V2 format. When importing OData V4, the kind `odata` is set, which is an alias for kind `odata-v4`. +The kind `odata-v2` is set when importing EDMX definitions of OData V2 format. When importing OData V4, the kind `odata` is set, which is an alias for kind `odata-v4`. +For OpenAPI documents, the kind is set to `rest` and for AsyncAPI documents, it is set to `odata`. [Learn more about type mappings from OData to CDS and vice versa.](../node.js/cds-dk#special-type-mappings){.learn-more} ::: tip @@ -1348,7 +1349,7 @@ Add the services to your microservice's `services` list in the _manifest.yml_ fi [Push](deployment/to-cf#push-the-application) the application. -```sh +```bash cf create-service-push # or `cf cspush` in short from 1.3.2 onwards ``` diff --git a/node.js/cds-dk.md b/node.js/cds-dk.md index 205053d31..ef0fc164f 100644 --- a/node.js/cds-dk.md +++ b/node.js/cds-dk.md @@ -35,7 +35,7 @@ const cds = require('@sap/cds-dk') ## cds.import (file, options) → [csn](../cds/csn) { #import } -As an application developer, you have the option to convert OData specification (EDMX / XML), or OpenAPI specification (JSON) files to CSN from JavaScript API as an alternative to the `cds import` command. +As an application developer, you have the option to convert OData specification (EDMX / XML), OpenAPI specification (JSON) or AsyncAPI specification (JSON) files to CSN from JavaScript API as an alternative to the `cds import` command. > `cds.import` is available in the CDS development tool kit *version 4.3.1* onwards . @@ -90,6 +90,15 @@ const csn = await cds.import.from.openapi(OpenAPI_JSON_file) ```
+## cds.import.from.asyncapi (file) → [csn](../cds/csn) { #import-from-asyncapi } + +This API can be used to convert the AsyncAPI specification file (JSON) into CSN. +The API signature looks like this: +```js +const csn = await cds.import.from.asyncapi(AsyncAPI_JSON_file) +``` +
+ Example: ```js @@ -100,10 +109,14 @@ module.exports = async (srv) => { cds.import('./odata_sample.edmx', { includeNamespaces: 'sap,c4c', keepNamespace: true }), // for openapi cds.import('./openapi_sample.json'), + // for asyncapi + cds.import('./asyncapi_sample.json'), // for odata cds.import.from.edmx('./odata_sample.xml', { includeNamespaces: '*', keepNamespace: false }), // for openapi cds.import.from.openapi('./openapi_sample.json') + // for asyncapi + cds.import.from.asyncapi('./asyncapi_sample.json') ]); for (let i = 0; i < csns.length; i++) { @@ -129,3 +142,4 @@ The following mapping is used during the import of an external service API, see | _Edm.DateTime
Precision : Second_ 1 | `cds.DateTime` + `@odata.Type:'Edm.DateTime'` + `@odata.Precision:0` | 1 only OData V2 + From 0130b68a21c9adebafa50a01168844e6fbfac33f Mon Sep 17 00:00:00 2001 From: Muskan Sethi Date: Thu, 27 Apr 2023 14:58:19 +0530 Subject: [PATCH 2/3] revert change --- guides/using-services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/using-services.md b/guides/using-services.md index 014ccf8ad..7c966d2d9 100644 --- a/guides/using-services.md +++ b/guides/using-services.md @@ -1349,7 +1349,7 @@ Add the services to your microservice's `services` list in the _manifest.yml_ fi [Push](deployment/to-cf#push-the-application) the application. -```bash +```sh cf create-service-push # or `cf cspush` in short from 1.3.2 onwards ``` From d690702ca6ad77b38bf914dc71c47634b76f8e62 Mon Sep 17 00:00:00 2001 From: Rene Jeglinsky Date: Tue, 2 May 2023 21:48:22 +0200 Subject: [PATCH 3/3] added table and some edits --- guides/using-services.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/guides/using-services.md b/guides/using-services.md index 7c966d2d9..3b7028235 100644 --- a/guides/using-services.md +++ b/guides/using-services.md @@ -153,11 +153,10 @@ cds import --as cds | Option | Description | | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `--keep-namespace` | Keep the namespace of the existing service. Otherwise, the namespace is changed to the file's base name when converting the file to CSN.
**Note:** In this example, it would be still `API_BUSINESS_PARTNER`. | | `--as cds` | The import creates a CDS file (for example _API_BUSINESS_PARTNER.cds_) instead of a CSN file. | -This adds the API in CSN format to the _srv/external_ folder and also copies the input file into that folder. Additionally, for **Node.js** it adds the API as an external service to your _package.json_. You use this declaration later to connect to the remote service [using a destination](#use-destinations-with-node-js). +This adds the API in CDS format to the _srv/external_ folder and also copies the input file into that folder. Additionally, for **Node.js** it adds the API as an external service to your _package.json_. You use this declaration later to connect to the remote service [using a destination](#use-destinations-with-node-js). ```json "cds": { @@ -189,10 +188,17 @@ Now run `cds import ` - `--force` is applicable only in combination with `--as` option. By default the `--force` flag is set to false. > If set to true, existing CSN/CDS files from previous imports are overwritten. -The kind `odata-v2` is set when importing EDMX definitions of OData V2 format. When importing OData V4, the kind `odata` is set, which is an alias for kind `odata-v4`. -For OpenAPI documents, the kind is set to `rest` and for AsyncAPI documents, it is set to `odata`. +When importing definitions, the `kind` is set according to the following mapping: + +|Imported Format | Used `kind` | +|---------|---------| +| OData V2 | `odata-v2` | +| OData V4 | `odata` (alias for `odata-v4`) | +| OpenAPI | `rest` | +| AsyncAPI | `odata` | [Learn more about type mappings from OData to CDS and vice versa.](../node.js/cds-dk#special-type-mappings){.learn-more} + ::: tip Always use OData V4 (`odata`) when calling another CAP service. :::