From 77d5a8b57522dc4f2feea38d15aca8529cb3a213 Mon Sep 17 00:00:00 2001 From: Alexander Ryzhikov Date: Mon, 21 Aug 2023 17:26:01 +0300 Subject: [PATCH] fix: bump test and fix schema with const tag --- generator/gen.ts | 8 +++++++- tap-snapshots/test/integration.test.ts.test.cjs | 10 +++------- test/test_schema.gen.json | 6 ++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/generator/gen.ts b/generator/gen.ts index f190f05..83fb7e5 100755 --- a/generator/gen.ts +++ b/generator/gen.ts @@ -109,6 +109,11 @@ async function normalizeSchema(originalSchema: JSONSchema7, rootId: string, newR return mergeAllOf(mergedSchema); } + +function isSchemaTag(tag: JSONSchema7) { + return (tag.enum?.length === 1 && tag.enum?.[0] === 'BETTER-FASTIFY-SCHEMA') || tag.const === 'BETTER-FASTIFY-SCHEMA'; +} + export default async (params: { files: string[] }) => { const compilerOptions: TsConfigJson['compilerOptions'] = { resolveJsonModule: false, @@ -123,6 +128,7 @@ export default async (params: { files: string[] }) => { required: true, ref: true, aliasRef: false, + skipLibCheck: true, topRef: true, ignoreErrors: true, strictNullChecks: true, @@ -173,7 +179,7 @@ export default async (params: { files: string[] }) => { const tag = def.properties['__SCHEMA_TAG__']; if (!tag || typeof tag === 'boolean') continue; - if (tag.enum?.length === 1 && tag.enum?.[0] === 'BETTER-FASTIFY-SCHEMA') { + if (isSchemaTag(tag)) { delete $defs[defName]; } diff --git a/tap-snapshots/test/integration.test.ts.test.cjs b/tap-snapshots/test/integration.test.ts.test.cjs index f670eb0..e2f0667 100644 --- a/tap-snapshots/test/integration.test.ts.test.cjs +++ b/tap-snapshots/test/integration.test.ts.test.cjs @@ -1135,7 +1135,7 @@ Object { "Headers": Array [ "HTTP/1.1 200 OK", "content-type: application/json; charset=utf-8", - "content-length: 3211", + "content-length: 3210", "Date: dateString", "Connection: keep-alive", ], @@ -1210,9 +1210,7 @@ Object { "$ref": "#/definitions/def-0/properties/Omit__Obj,%22type%22__", "properties": Object { "type": Object { - "enum": Array [ - "TEST", - ], + "const": "TEST", "type": "string", }, }, @@ -1546,9 +1544,7 @@ Object { "$ref": "#/definitions/def-0/properties/Omit__Obj,%22type%22__", "properties": Object { "type": Object { - "enum": Array [ - "TEST", - ], + "const": "TEST", "type": "string", }, }, diff --git a/test/test_schema.gen.json b/test/test_schema.gen.json index 04e3879..04f4ccf 100644 --- a/test/test_schema.gen.json +++ b/test/test_schema.gen.json @@ -58,9 +58,7 @@ "properties": { "type": { "type": "string", - "enum": [ - "TEST" - ] + "const": "TEST" } } }, @@ -325,5 +323,5 @@ } } }, - "$hash": "c138d591328ddd9cc1b794e5e35447467e7c1f8d4129b8fc727c11d7e9b0ef02__v1.1.2" + "$hash": "c138d591328ddd9cc1b794e5e35447467e7c1f8d4129b8fc727c11d7e9b0ef02__v1.1.31692627847130" } \ No newline at end of file