@@ -17,6 +17,7 @@ const basic = require("../schemas/basic.json");
17
17
const invalidFieldOne = require ( "../schemas/invalidFields/invalidField.json" ) ;
18
18
// null property type
19
19
const nullProperty = require ( "../schemas/nullProperties/nullProperty.json" ) ;
20
+ const nullAndTypeProperty = require ( "../schemas/nullProperties/nullAndType.json" ) ;
20
21
// array types
21
22
const arrayType = require ( "../schemas/arrayTypes/arrayType.json" ) ;
22
23
const arrayTypeWithNull = require ( "../schemas/arrayTypes/arrayTypeIncludingNull.json" ) ;
@@ -178,24 +179,24 @@ describe("Convertor", () => {
178
179
let valid = await validator . validateInner ( cloned , { } ) ;
179
180
expect ( valid ) . to . be . true ;
180
181
} ) ;
181
- } ) ;
182
182
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 ) ;
186
185
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
+ ) ;
187
197
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 ) ;
199
200
200
201
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) ) ;
201
202
Object . assign ( cloned , { components : result } ) ;
@@ -205,9 +206,11 @@ describe("Convertor", () => {
205
206
let valid = await validator . validateInner ( cloned , { } ) ;
206
207
expect ( valid ) . to . be . true ;
207
208
} ) ;
209
+ } ) ;
208
210
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 ) ;
211
214
const result = newConvertor . convert ( "basic" ) ;
212
215
expect (
213
216
result . schemas . basic . properties . arrayTypeProperty
@@ -220,13 +223,7 @@ describe("Convertor", () => {
220
223
) . to . be . an ( "array" ) ;
221
224
expect (
222
225
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 ) ;
230
227
231
228
const cloned = JSON . parse ( JSON . stringify ( basicOpenAPI ) ) ;
232
229
Object . assign ( cloned , { components : result } ) ;
0 commit comments