joi-to-json 5.0.4 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -84,7 +84,8 @@ class JoiOpenApiSchemaParser extends JoiJsonSchemaParser {
84
84
  super._addNullTypeIfNullable(fieldSchema, fieldDefn)
85
85
 
86
86
  if (fieldSchema.type === 'null') {
87
- delete fieldSchema.type
87
+ // OpenAPI 3.0 does not support type with value 'null', so we need to set type to 'object' and nullable to true
88
+ fieldSchema.type = 'object'
88
89
  fieldSchema.nullable = true
89
90
  } else if (_.isArray(fieldSchema.type) && fieldSchema.type.includes('null')) {
90
91
  _.remove(fieldSchema.type, (i) => {
@@ -94,11 +95,14 @@ class JoiOpenApiSchemaParser extends JoiJsonSchemaParser {
94
95
 
95
96
  if (fieldSchema.type.length === 1) {
96
97
  fieldSchema.type = fieldSchema.type[0]
98
+ } else if (!fieldSchema.type) {
99
+ // if the only type is null, we need to set type to object because open-api 3.0 does not support type with value 'null'
100
+ fieldSchema.type = 'object'
97
101
  }
98
102
  }
99
103
 
100
104
  if (_.isArray(fieldSchema.type)) {
101
- // anyOf might exist for When / Alternative case
105
+ // anyOf is used for When / Alternative case because open-api 3.0 does not support type with array value
102
106
  fieldSchema.anyOf = fieldSchema.anyOf || []
103
107
 
104
108
  _.forEach(fieldSchema.type, (t) => {
@@ -115,7 +119,14 @@ class JoiOpenApiSchemaParser extends JoiJsonSchemaParser {
115
119
  }
116
120
  })
117
121
 
122
+ _.forEach(fieldSchema.anyOf, (condition) => {
123
+ if (fieldSchema.nullable) {
124
+ condition.nullable = true
125
+ }
126
+ })
127
+
118
128
  delete fieldSchema.type
129
+ delete fieldSchema.nullable
119
130
  }
120
131
  }
121
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joi-to-json",
3
- "version": "5.0.4",
3
+ "version": "5.0.5",
4
4
  "description": "joi to JSON / OpenAPI Schema Converter",
5
5
  "main": "index.js",
6
6
  "repository": {