joi-to-json 2.3.3 → 2.3.4

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.
@@ -115,9 +115,16 @@ class JoiJsonSchemaParser {
115
115
  return _.get(fieldDefn, 'flags.default')
116
116
  }
117
117
 
118
+ _getConst(fieldDefn) {
119
+ const enumList = fieldDefn[this.enumFieldName]
120
+ if (fieldDefn.flags && fieldDefn.flags.only && enumList.length === 1) {
121
+ return enumList[0]
122
+ }
123
+ }
124
+
118
125
  _getEnum(fieldDefn) {
119
126
  const enumList = fieldDefn[this.enumFieldName]
120
- if (fieldDefn.flags && fieldDefn.flags.only && !_.isEmpty(enumList)) {
127
+ if (fieldDefn.flags && fieldDefn.flags.only && enumList.length > 1) {
121
128
  return _.uniq(enumList)
122
129
  }
123
130
  }
@@ -141,6 +148,7 @@ class JoiJsonSchemaParser {
141
148
  this._setIfNotEmpty(fieldSchema, 'examples', this._getFieldExample(fieldDefn))
142
149
  this._setIfNotEmpty(fieldSchema, 'description', this._getFieldDescription(fieldDefn))
143
150
  this._setIfNotEmpty(fieldSchema, 'default', this._getDefaultValue(fieldDefn))
151
+ this._setIfNotEmpty(fieldSchema, 'const', this._getConst(fieldDefn))
144
152
  this._setIfNotEmpty(fieldSchema, 'enum', this._getEnum(fieldDefn))
145
153
  }
146
154
 
@@ -53,6 +53,10 @@ class JoiOpenApiSchemaParser extends JoiJsonSchemaParser {
53
53
  schema.schemas = definitions
54
54
  }
55
55
 
56
+ if (fullSchema.const) {
57
+ schema.enum = [fullSchema.const]
58
+ }
59
+
56
60
  return schema
57
61
  }
58
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joi-to-json",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "description": "joi to JSON / OpenAPI Schema Converter",
5
5
  "main": "index.js",
6
6
  "repository": {