joi-to-json 2.3.1 → 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.
@@ -31,6 +31,10 @@ class JoiJsonSchemaParser {
31
31
  this._setMetaProperties(schema, joiSpec)
32
32
  this._setLinkFieldProperties(schema, joiSpec)
33
33
 
34
+ if (!_.isEmpty(joiSpec.shared)) {
35
+ this.parse(joiSpec.shared[0], definitions, level)
36
+ }
37
+
34
38
  const schemaId = _.get(joiSpec, 'flags.id')
35
39
  if (schemaId) {
36
40
  definitions[schemaId] = schema
@@ -111,9 +115,16 @@ class JoiJsonSchemaParser {
111
115
  return _.get(fieldDefn, 'flags.default')
112
116
  }
113
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
+
114
125
  _getEnum(fieldDefn) {
115
126
  const enumList = fieldDefn[this.enumFieldName]
116
- if (fieldDefn.flags && fieldDefn.flags.only && !_.isEmpty(enumList)) {
127
+ if (fieldDefn.flags && fieldDefn.flags.only && enumList.length > 1) {
117
128
  return _.uniq(enumList)
118
129
  }
119
130
  }
@@ -137,6 +148,7 @@ class JoiJsonSchemaParser {
137
148
  this._setIfNotEmpty(fieldSchema, 'examples', this._getFieldExample(fieldDefn))
138
149
  this._setIfNotEmpty(fieldSchema, 'description', this._getFieldDescription(fieldDefn))
139
150
  this._setIfNotEmpty(fieldSchema, 'default', this._getDefaultValue(fieldDefn))
151
+ this._setIfNotEmpty(fieldSchema, 'const', this._getConst(fieldDefn))
140
152
  this._setIfNotEmpty(fieldSchema, 'enum', this._getEnum(fieldDefn))
141
153
  }
142
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.1",
3
+ "version": "2.3.4",
4
4
  "description": "joi to JSON / OpenAPI Schema Converter",
5
5
  "main": "index.js",
6
6
  "repository": {