Skip to content

Commit

Permalink
No funny format, preserve type
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfhandl committed Aug 29, 2024
1 parent 1e41aad commit f45551d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 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
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 f45551d

Please sign in to comment.