From f074f84bab2a25d31b7bc273aab02284269ebb87 Mon Sep 17 00:00:00 2001 From: Roshni Naveena S Date: Thu, 15 May 2025 13:12:17 +0530 Subject: [PATCH 1/2] adding mapping table for openapi import --- tools/apis/cds-import.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/apis/cds-import.md b/tools/apis/cds-import.md index c51ece4a4..b906323db 100644 --- a/tools/apis/cds-import.md +++ b/tools/apis/cds-import.md @@ -68,6 +68,38 @@ const csn = await cds.import.from.openapi(OpenAPI_JSON_file) ```
+# OpenAPI to CDS (OData CSN) Conversion Mapping + +| **OpenAPI** | **OData Equivalent** | +|---------------------------------------------|--------------------------------------------------------------| +| `info.title` | `serviceName`, `@Core.Description` | +| `info.version` | `@Core.SchemaVersion` | +| `info.description` | `@Core.LongDescription` | +| `paths.{path}.{method}` | `function` (GET) or `action` (others) | +| `tags[0]` | `@Common.Label` | +| `summary` / `description` | `@Core.Description`, `@Core.LongDescription` | +| `parameters[].in` | `@openapi.in` | +| `parameters[].name` | Transformed param name + `@openapi.name` if needed | +| `parameters[].required` | `@openapi.required` | +| `parameters[].style`, `explode`, `allowReserved` | `@openapi.style`, `@openapi.explode`, `@openapi.allowReserved` | +| `parameters[].default` | `default: { val: ... }` | +| `parameters[].description` | `@description` | +| `requestBody.content.application/json.schema` | `params.body` | +| `requestBody.$ref` | Dereferenced and used | +| `responses["2XX"].content.application/json` | `returns` | +| `$ref` | `type` or `includes` | +| `components.schemas` / `definitions` | Named `types` | +| inline schema | `anonymous.typeX` | +| `enum` | `enum`, `@assert.range` | +| `format: date/time/uuid/binary` | `cds.Date`, `cds.Time`, `cds.Timestamp`, `cds.UUID`, etc. | +| `pattern` | `@assert.format` | +| `allOf`, `anyOf`, `oneOf` | `@openapi.allOf`, `@openapi.anyOf`, `@openapi.oneOf` | +| `example` / `examples[0]` | `@Core.Example.Value` | +| `type: object` with `properties` | `elements` | +| `required` (on properties) | `@mandatory` | + +--- + ## cds.import.from.asyncapi() {.method} This API can be used to convert the AsyncAPI specification file (JSON) into CSN. From cc510c003073677005ebe7e7ddb4b6cbd306cf2f Mon Sep 17 00:00:00 2001 From: Roshni Naveena S Date: Thu, 15 May 2025 13:58:39 +0530 Subject: [PATCH 2/2] Update cds-import.md --- tools/apis/cds-import.md | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/apis/cds-import.md b/tools/apis/cds-import.md index b906323db..140ea2204 100644 --- a/tools/apis/cds-import.md +++ b/tools/apis/cds-import.md @@ -89,7 +89,6 @@ const csn = await cds.import.from.openapi(OpenAPI_JSON_file) | `responses["2XX"].content.application/json` | `returns` | | `$ref` | `type` or `includes` | | `components.schemas` / `definitions` | Named `types` | -| inline schema | `anonymous.typeX` | | `enum` | `enum`, `@assert.range` | | `format: date/time/uuid/binary` | `cds.Date`, `cds.Time`, `cds.Timestamp`, `cds.UUID`, etc. | | `pattern` | `@assert.format` |