DeepBlueCLtd / json-schema-editor

JSON Editor focussed on developing/editing JSON Schema documents
https://deepbluecltd.github.io/json-schema-editor/
GNU General Public License v3.0
9 stars 2 forks source link

Don't lose Preview Editor value after a schema update #22

Closed Franciman closed 5 years ago

Franciman commented 5 years ago

When one only adds or removes a field from the schema, it would be wasteful to totally lose the Preview Editor, instead it would be preferable to keep the old values, when possible.

Franciman commented 5 years ago

@pmk65 do you have any tip for this?

pmk65 commented 5 years ago

@Franciman Im not quite sure what you mean by loosing Preview Editor.

Franciman commented 5 years ago

@pmk65 for example, suppose you have the Person schema, you put some data in the Preview Editor(e.g. Name: 'Jon', Age: 25, etc..) then you realize you don't need The name field anymore, so you update the schema. Now when you update the Preview Editor, all the data you previously inserted are lost

pmk65 commented 5 years ago

Ok. Now I get it. 😄

1) Turn on "No additional object properties" for the Preview Editor. (This will prevent creation of field when you set a value for a non-existing field) 2) Before updating Preview Editor, save the content. ( previewEditor.getValue() ) 3) Update the Preview Editor from the Schema Editor and use the values saved in step 2 as starting value (startval).

Franciman commented 5 years ago

What if a field changed type? E.g. from string to int. I get a validation error. I tried solving that issue by running

var errors = editor.validate(oldValue);

And then for each error reported I remove the field in the oldValue that gives that error (chasing it thanks to error.path) Do you know of a better approach?

pmk65 commented 5 years ago

It will just validate the value as invalid (I think the int/number types automatically converts any non digit value to zero)

Your approach seems a good way to do it.

Franciman commented 5 years ago

thank you for the support!

IanMayo commented 5 years ago

Yes, thanks again @pmk65 for your support.

Hey, did you see that the schema editor is now being used in the wild? https://github.com/DeepBlueCLtd/json-schema-editor/issues/24

It's in a TiddlyWiki clone, and I've loved TiddlyWiki for over 10 years. Very exciting :-)

pmk65 commented 5 years ago

Hey, did you see that the schema editor is now being used in the wild?

24

Yeah. I saw that. Very nice 😃