angular2-json-schema-form icon indicating copy to clipboard operation
angular2-json-schema-form copied to clipboard

Getting error in data only mode

Open bhuvanit opened this issue 6 years ago • 2 comments

Issue type

I'm submitting a (check one): [X] Bug report [ ] Feature request [ ] Regression (something that used to work, but stopped working in a newer version) [ ] Support request [ ] Documentation issue or request

Prerequisites

Before posting, make sure you do the following (check all): [X] Confirm you are using the latest versions of all necessary packages (or if not, explain why not) [X] Search GitHub for a similar issue or PR [X] If submitting a Support request, also search Stack Overflow for similar issues Note: Please cross-post GitHub support requests to Stack Overflow, and include a link in your GitHub issue to your Stack Overflow question. We do currently respond to support requests on GitHub, but we eventually expect to stop, and will then refer all support questions exclusively to Stack Overflow.

Current behavior

As per the documentation, https://github.com/dschnelldavis/angular2-json-schema-form, I tried following the data only mode approach Data-only mode Angular JSON Schema Form can also create a form entirely from a JSON object—with no schema—like so:

<json-schema-form loadExternalAssets="true" [(ngModel)]="exampleJsonObject"> exampleJsonObject = { "first_name": "Jane", "last_name": "Doe", "age": 25, "is_company": false, "address": { "street_1": "123 Main St.", "street_2": null, "city": "Las Vegas", "state": "NV", "zip_code": "89123" }, "phone_numbers": [ { "number": "702-123-4567", "type": "cell" }, { "number": "702-987-6543", "type": "work" } ], "notes": "" };

But, I am getting an error when the browser loads the page : "AppComponent.html:1 ERROR Error: no schema with key or ref "http://json-schema.org/draft-06/schema#""

Expected behavior

The page should have rendered the form based on the data model.

IMPORTANT: How can we reproduce your problem?

The sample code is placed in the demo : https://stackblitz.com/edit/angular-p4lm8n

Environment

OS name & version: Windows 7 Browser name & version: Chrome Angular version: 5 Angular JSON Schema Form version(s): 2 Other relevant software or packages:

Any other relevant information

bhuvanit avatar Mar 08 '18 23:03 bhuvanit

I just glanced at the error and it is due to the following:

  • The latest version of AJV only supports Json Schema draft version 7, unless you require version 6.

So Here are a few possible fixes:

  • Lock the AJV version to support 6 (this can be done probably in your local workspace) or in this one.
  • This project needs to run the following command ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json')); after ajv is initiated
  • Upgrade the default schema draft to 7 for the latest version of ajv

tmburnell avatar Mar 09 '18 13:03 tmburnell

Hi, Could you please tell me exactly how would I know if the ajv is initiated? And should I integrate the ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json')); the command in some typescript/javascript file, if yes, could you please tell me the name where I can execute this command?

Thanks,

vijayanandkhedkar avatar Apr 22 '20 02:04 vijayanandkhedkar