@@ -17,6 +17,7 @@ const basic = require("../schemas/basic.json");
1717const invalidFieldOne = require ( "../schemas/invalidFields/invalidField.json" ) ;
1818// null property type
1919const nullProperty = require ( "../schemas/nullProperties/nullProperty.json" ) ;
20+ const nullAndTypeProperty = require ( "../schemas/nullProperties/nullAndType.json" ) ;
2021// array types
2122const arrayType = require ( "../schemas/arrayTypes/arrayType.json" ) ;
2223const arrayTypeWithNull = require ( "../schemas/arrayTypes/arrayTypeIncludingNull.json" ) ;
@@ -178,24 +179,24 @@ describe("Convertor", () => {
178179 let valid = await validator . validateInner ( cloned , { } ) ;
179180 expect ( valid ) . to . be . true ;
180181 } ) ;
181- } ) ;
182182
183- describe ( "arrays of types" , ( ) => {
184- it ( "should convert properties that have an array of types to a oneOf" , async function ( ) {
185- const newConvertor = new Convertor ( arrayType ) ;
183+ it ( `should set types as nullable when null is provided along with a type` , async function ( ) {
184+ const newConvertor = new Convertor ( nullAndTypeProperty ) ;
186185 const result = newConvertor . convert ( "basic" ) ;
186+
187+ expect ( result . schemas . basic . properties . typedProperty ) . to . have . property (
188+ "type"
189+ ) ;
190+ expect ( result . schemas . basic . properties . typedProperty ) . to . have . property (
191+ "type" ,
192+ "string"
193+ ) ;
194+ expect ( result . schemas . basic . properties . typedProperty ) . to . have . property (
195+ "nullable"
196+ ) ;
187197 expect (
188- result . schemas . basic . properties . arrayTypeProperty
189- ) . to . not . have . property ( "type" ) ;
190- expect (
191- result . schemas . basic . properties . arrayTypeProperty
192- ) . to . have . property ( "oneOf" ) ;
193- expect (
194- result . schemas . basic . properties . arrayTypeProperty . oneOf
195- ) . to . be . an ( "array" ) ;
196- expect (
197- result . schemas . basic . properties . arrayTypeProperty . oneOf . length
198- ) . to . be . equal ( 2 ) ;
198+ result . schemas . basic . properties . typedProperty . nullable
199+ ) . to . be . equal ( true ) ;
199200
200201 const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) ) ;
201202 Object . assign ( cloned , { components : result } ) ;
@@ -205,9 +206,11 @@ describe("Convertor", () => {
205206 let valid = await validator . validateInner ( cloned , { } ) ;
206207 expect ( valid ) . to . be . true ;
207208 } ) ;
209+ } ) ;
208210
209- it ( "should convert properties that have an array of types to a oneOf with null fields" , async function ( ) {
210- const newConvertor = new Convertor ( arrayTypeWithNull ) ;
211+ describe ( "arrays of types" , ( ) => {
212+ it ( "should convert properties that have an array of types to a oneOf" , async function ( ) {
213+ const newConvertor = new Convertor ( arrayType ) ;
211214 const result = newConvertor . convert ( "basic" ) ;
212215 expect (
213216 result . schemas . basic . properties . arrayTypeProperty
@@ -220,13 +223,7 @@ describe("Convertor", () => {
220223 ) . to . be . an ( "array" ) ;
221224 expect (
222225 result . schemas . basic . properties . arrayTypeProperty . oneOf . length
223- ) . to . be . equal ( 1 ) ;
224- expect (
225- result . schemas . basic . properties . arrayTypeProperty . oneOf [ 0 ] . type
226- ) . to . be . equal ( "string" ) ;
227- expect (
228- result . schemas . basic . properties . arrayTypeProperty . oneOf [ 0 ] . nullable
229- ) . to . be . equal ( true ) ;
226+ ) . to . be . equal ( 2 ) ;
230227
231228 const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) ) ;
232229 Object . assign ( cloned , { components : result } ) ;
0 commit comments