Skip to content

Commit

Permalink
Nullable function parameters (#310)
Browse files Browse the repository at this point in the history
* No funny format, preserve type

* 0.28.1
  • Loading branch information
ralfhandl authored Aug 29, 2024
1 parent 1e41aad commit b6f930e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/csdl-16.1.openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -1884,8 +1884,8 @@
"in": "query",
"name": "Rating",
"schema": {
"type": "string",
"format": "int32,null",
"type": "integer",
"format": "int32",
"nullable": true,
"default": "null"
}
Expand Down
2 changes: 0 additions & 2 deletions lib/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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|");
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 7 additions & 7 deletions test/csdl2openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
},
Expand All @@ -702,7 +702,7 @@ describe("Edge cases", function () {
required: true,
schema: {
type: "string",
format: "base64url,null",
format: "base64url",
nullable: true,
default: "null",
},
Expand All @@ -727,7 +727,7 @@ describe("Edge cases", function () {
name: "booleanNull",
required: true,
schema: {
type: "string",
type: "boolean",
nullable: true,
default: "null",
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -784,7 +784,7 @@ describe("Edge cases", function () {
required: true,
schema: {
type: "string",
format: "duration,null",
format: "duration",
nullable: true,
default: "null",
example: "'P4DT15H51M04S'",
Expand Down

0 comments on commit b6f930e

Please sign in to comment.