Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

My First Playground

node v14.20.1
version: master
endpointsharetweet
This is a playground to test JavaScript. It runs a completely standard copy of Node.js on a virtual server created just for you. Every one of npm’s 300,000+ packages are pre-installed, so try it out:
require("ajv") const options: Ajv.Options = { allErrors: true }; function go() { const ajv = new Ajv({ nullable: true, allErrors: true }); const schema = { "type": "object", "properties": { "root": { "$ref": "#/components/schemas/ObjectA" } }, "components": { "schemas": { "ObjectA": { "type": "object", "properties": { "property1": { "allOf": [{ "$ref": "#/components/schemas/ObjectB" }], "nullable": true } } }, "ObjectB": { "type": "object", "properties": { "foo": { "type": "boolean" } } } } } } const schemaInline = { "type": "object", "properties": { "root": { "$ref": "#/components/schemas/UpdateAudienceLoadBoardRequestOptions" } }, "additionalPropertes": false, "components": { "schemas": { "UpdateAudienceLoadBoardRequestOptions": { "type": "object", "properties": { "transactionDetails": { "type": "object", "properties": { "test": { "type": "boolean" } }, "required": ["test"], "additionalProperties": false, "nullable": true } } }, "UpdateTransactionDetails": { "type": "object", "properties": { "test": { "type": "boolean" } }, "required": ["test"], "additionalProperties": false } } } } let validateMessage = ajv.compile(schema); const nulled = { "root": { "property1": null } } as any; const good = { "root": { "property1": { "test": true } } } as any; if (validateMessage(nulled)) { console.log('good2'); } else { console.log(JSON.stringify(validateMessage.errors)); // output is: [{"keyword":"type","dataPath":".root.property1","schemaPath":"#/components/schemas/ObjectB/type","params":{"type":"object"},"message":"should be object"}] } } go();
Loading…

no comments

    sign in to comment