@openapi-contrib/json-schema-to-openapi-schema
Advanced tools
Comparing version 1.1.0 to 1.2.0
31
index.js
@@ -125,24 +125,13 @@ 'use strict'; | ||
if (Array.isArray(schema.type)) { | ||
if (schema.type.length > 2 || !schema.type.includes('null')) { | ||
throw new Error('Type of ' + schema.type.join(',') + ' is too confusing for OpenAPI to understand. Found in ' + JSON.stringify(schema)); | ||
if (schema.type.includes('null')) { | ||
schema.nullable = true; | ||
} | ||
switch (schema.type.length) { | ||
case 0: | ||
delete schema.type; | ||
break; | ||
case 1: | ||
if (schema.type === 'null') { | ||
schema.nullable = true; | ||
} | ||
else { | ||
schema.type = schema.type[0]; | ||
} | ||
break; | ||
default: | ||
schema.type = schema.type.find(type => type !== 'null'); | ||
schema.nullable = true; | ||
const typesWithoutNull = schema.type.filter(type => type !== 'null'); | ||
if (typesWithoutNull.length === 0) { | ||
delete schema.type | ||
} else if (typesWithoutNull.length === 1) { | ||
schema.type = typesWithoutNull[0]; | ||
} else { | ||
delete schema.type; | ||
schema.anyOf = typesWithoutNull.map(type => ({ type })); | ||
} | ||
@@ -149,0 +138,0 @@ } |
{ | ||
"name": "@openapi-contrib/json-schema-to-openapi-schema", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Converts a JSON Schema to OpenAPI Schema Object", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92296
40
3710