Skip to content

generated code is wrong with that schema #268

@kapouer

Description

@kapouer

EDIT: a simpler schema

{
 "type": "object",
 "properties": {
  "email": { "type": "string", "transform": ["trim"] }
 }
}

gives
SyntaxError: Unexpected token ':'.

const schema43 = scope.schema[23];const func0 = scope.func[0];const func86 = scope.func[2];return function validate29(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(data && typeof data == "object" && !Array.isArray(data)){for(const key0 of Object.keys(data)){if(!(key0 === "email")){delete data[key0];}}if(data.email !== undefined && func0.call(data, "email")){let data0 = data.email;if(typeof data0 !== "string"){let dataType0 = typeof data0;let coerced0 = undefined;if(dataType0 == 'object' && Array.isArray(data0) && data0.length == 1){data0 = data0[0];dataType0 = typeof data0;if(typeof data0 === "string"){coerced0 = data0;}}if(!(coerced0 !== undefined)){if(dataType0 == "number" || dataType0 == "boolean"){coerced0 = "" + data0;}else if(data0 === null){coerced0 = "";}else {const err0 = {instancePath:instancePath+"/email",schemaPath:"#/properties/email/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err0];}else {vErrors.push(err0);}errors++;}}if(coerced0 !== undefined){data0 = coerced0;if(data !== undefined){data["email"] = coerced0;}}}if(typeof {"str":"data0"} == "string" && {"str":"data"} !== undefined){data0 = {"str":"func86","prefix":"func","value":{"code":{"_items":["require(\"ajv-keywords/dist/definitions/transform\").transform",".trim",""]}},"scopePath":{"_items":[".",{"str":"func"},"[",2,"]"]}}({"str":"data0"});{"str":"data"}[{"_items":["","\"email\"",""]}] = data0;}}}else {const err1 = {instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err1];}else {vErrors.push(err1);}errors++;}validate29.errors = vErrors;return errors === 0;}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions