diff --git a/src/oas/__tests__/__snapshots__/operation.test.ts.snap b/src/oas/__tests__/__snapshots__/operation.test.ts.snap index 24458fde..97dfad52 100644 --- a/src/oas/__tests__/__snapshots__/operation.test.ts.snap +++ b/src/oas/__tests__/__snapshots__/operation.test.ts.snap @@ -787,6 +787,28 @@ Array [ ], "type": "string", }, + "nullableEnumExplicit": Object { + "enum": Array [ + null, + "foo", + "bar", + ], + "type": Array [ + "string", + "null", + ], + }, + "nullableEnumImplicit": Object { + "enum": Array [ + "foo", + "bar", + null, + ], + "type": Array [ + "string", + "null", + ], + }, "photoUrls": Object { "items": Object { "type": "string", @@ -849,6 +871,28 @@ Array [ ], "type": "string", }, + "nullableEnumExplicit": Object { + "enum": Array [ + null, + "foo", + "bar", + ], + "type": Array [ + "string", + "null", + ], + }, + "nullableEnumImplicit": Object { + "enum": Array [ + "foo", + "bar", + null, + ], + "type": Array [ + "string", + "null", + ], + }, "photoUrls": Object { "items": Object { "type": "string", @@ -1143,6 +1187,28 @@ Array [ ], "type": "string", }, + "nullableEnumExplicit": Object { + "enum": Array [ + null, + "foo", + "bar", + ], + "type": Array [ + "string", + "null", + ], + }, + "nullableEnumImplicit": Object { + "enum": Array [ + "foo", + "bar", + null, + ], + "type": Array [ + "string", + "null", + ], + }, "photoUrls": Object { "items": Object { "type": "string", @@ -1205,6 +1271,28 @@ Array [ ], "type": "string", }, + "nullableEnumExplicit": Object { + "enum": Array [ + null, + "foo", + "bar", + ], + "type": Array [ + "string", + "null", + ], + }, + "nullableEnumImplicit": Object { + "enum": Array [ + "foo", + "bar", + null, + ], + "type": Array [ + "string", + "null", + ], + }, "photoUrls": Object { "items": Object { "type": "string", diff --git a/src/oas/__tests__/fixtures/oas3-kitchen-sink.json b/src/oas/__tests__/fixtures/oas3-kitchen-sink.json index 26a09ca7..c9d96366 100644 --- a/src/oas/__tests__/fixtures/oas3-kitchen-sink.json +++ b/src/oas/__tests__/fixtures/oas3-kitchen-sink.json @@ -312,6 +312,16 @@ "type": "string", "description": "pet status in the store", "enum": ["available", "pending", "sold"] + }, + "nullableEnumImplicit": { + "type": "string", + "nullable": true, + "enum": ["foo", "bar"] + }, + "nullableEnumExplicit": { + "type": "string", + "nullable": true, + "enum": [null, "foo", "bar"] } }, "required": ["name", "photoUrls"] diff --git a/src/oas/transformers/schema/keywords/nullable.ts b/src/oas/transformers/schema/keywords/nullable.ts index 72de6eea..74c4766d 100644 --- a/src/oas/transformers/schema/keywords/nullable.ts +++ b/src/oas/transformers/schema/keywords/nullable.ts @@ -26,7 +26,7 @@ const createNullableConverter = (keyword: 'x-nullable' | 'nullable'): Converter if (schema[keyword] === true) { schema.type = [schema.type, 'null']; - if (Array.isArray(schema.enum)) { + if (Array.isArray(schema.enum) && !schema.enum.includes(null)) { schema.enum = [...schema.enum, null]; } } else {