Skip to content

Commit

Permalink
fix: bump test and fix schema with const tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Coobaha committed Aug 21, 2023
1 parent 47fcfeb commit 77d5a8b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 7 additions & 1 deletion generator/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -123,6 +128,7 @@ export default async (params: { files: string[] }) => {
required: true,
ref: true,
aliasRef: false,
skipLibCheck: true,
topRef: true,
ignoreErrors: true,
strictNullChecks: true,
Expand Down Expand Up @@ -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];
}

Expand Down
10 changes: 3 additions & 7 deletions tap-snapshots/test/integration.test.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -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",
},
},
Expand Down
6 changes: 2 additions & 4 deletions test/test_schema.gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@
"properties": {
"type": {
"type": "string",
"enum": [
"TEST"
]
"const": "TEST"
}
}
},
Expand Down Expand Up @@ -325,5 +323,5 @@
}
}
},
"$hash": "c138d591328ddd9cc1b794e5e35447467e7c1f8d4129b8fc727c11d7e9b0ef02__v1.1.2"
"$hash": "c138d591328ddd9cc1b794e5e35447467e7c1f8d4129b8fc727c11d7e9b0ef02__v1.1.31692627847130"
}

0 comments on commit 77d5a8b

Please sign in to comment.