From f45551dd2c7b6f0c844c78b9a7c04c35994f2609 Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Thu, 29 Aug 2024 12:15:54 +0200 Subject: [PATCH 1/2] No funny format, preserve type --- CHANGELOG.md | 6 ++++++ examples/csdl-16.1.openapi3.json | 4 ++-- lib/csdl2openapi.js | 2 -- test/csdl2openapi.test.js | 14 +++++++------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00e2f475..8301828e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.28.1 - 2024-08-29 + +### Fixed + +- Nullable function parameters no longer get a funny format and a wrong type + ## 0.28.0 - 2024-08-06 ### Added diff --git a/examples/csdl-16.1.openapi3.json b/examples/csdl-16.1.openapi3.json index 50f99723..9b95465b 100644 --- a/examples/csdl-16.1.openapi3.json +++ b/examples/csdl-16.1.openapi3.json @@ -1884,8 +1884,8 @@ "in": "query", "name": "Rating", "schema": { - "type": "string", - "format": "int32,null", + "type": "integer", + "format": "int32", "nullable": true, "default": "null" } diff --git a/lib/csdl2openapi.js b/lib/csdl2openapi.js index c444defb..8961c780 100644 --- a/lib/csdl2openapi.js +++ b/lib/csdl2openapi.js @@ -2728,8 +2728,6 @@ module.exports.csdl2openapi = function ( s.pattern = "^'([^']|'')*'$"; } if (element.$Nullable) { - if (!s.anyOf && !s.allOf) s.type = "string"; - if (s.format) s.format += ",null"; s.default = "null"; //TODO: @Core.OptionalParameter.DefaultValue if (s.pattern) { s.pattern = s.pattern.replace(/^\^/, "^(null|"); diff --git a/test/csdl2openapi.test.js b/test/csdl2openapi.test.js index ee522a6f..b485c41f 100644 --- a/test/csdl2openapi.test.js +++ b/test/csdl2openapi.test.js @@ -648,7 +648,7 @@ describe("Edge cases", function () { required: true, schema: { type: "string", - format: "uuid,null", + format: "uuid", nullable: true, default: "null", example: "01234567-89ab-cdef-0123-456789abcdef", @@ -674,8 +674,8 @@ describe("Edge cases", function () { name: "int32Null", required: true, schema: { - type: "string", - format: "int32,null", + type: "integer", + format: "int32", nullable: true, default: "null", }, @@ -702,7 +702,7 @@ describe("Edge cases", function () { required: true, schema: { type: "string", - format: "base64url,null", + format: "base64url", nullable: true, default: "null", }, @@ -727,7 +727,7 @@ describe("Edge cases", function () { name: "booleanNull", required: true, schema: { - type: "string", + type: "boolean", nullable: true, default: "null", }, @@ -755,7 +755,7 @@ describe("Edge cases", function () { required: true, schema: { anyOf: [{ type: "number" }, { type: "string" }], - format: "decimal,null", + format: "decimal", nullable: true, default: "null", example: 0, @@ -784,7 +784,7 @@ describe("Edge cases", function () { required: true, schema: { type: "string", - format: "duration,null", + format: "duration", nullable: true, default: "null", example: "'P4DT15H51M04S'", From 6ac22fb2d83089b2bd09f40763c029078d612669 Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Thu, 29 Aug 2024 12:16:12 +0200 Subject: [PATCH 2/2] 0.28.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e7135bfa..1522501c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "odata-openapi", - "version": "0.28.0", + "version": "0.28.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "odata-openapi", - "version": "0.28.0", + "version": "0.28.1", "license": "SEE LICENSE IN LICENSE.md", "dependencies": { "@discoveryjs/json-ext": "^0.6.0", diff --git a/package.json b/package.json index 537fdf2b..15913725 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "odata-openapi", - "version": "0.28.0", + "version": "0.28.1", "description": "Convert OData CSDL XML or CSDL JSON to OpenAPI", "homepage": "https://github.com/oasis-tcs/odata-openapi/blob/master/lib/README.md", "bugs": "https://github.com/oasis-tcs/odata-openapi/issues",