diff --git a/guides/using-services.md b/guides/using-services.md index 7fef3d310..6e58ab92b 100644 --- a/guides/using-services.md +++ b/guides/using-services.md @@ -148,16 +148,15 @@ 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 | | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `--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 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 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,9 +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`. +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. ::: diff --git a/node.js/cds-dk.md b/node.js/cds-dk.md index 6013e14f3..9f4eaf2db 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 +