You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error messaging is one of the powerful features of the monaco editor that works alright for most json schema features. However, when using anyOf (or oneOf) to define multiple acceptable values for a property error messaging assumes that the schema uniquely maps to the property first defined in the anyOf array.
Screenshot:
In the above example, the issue is that the schema defines both rectangle and square as acceptable values for the p1.shape property but the error messaging insists that the value must be rectangle.
This is in contrast to enums for which it works perfectly as shown in the example below, but for complex schema that requires either anyOf or oneOf support, it falls short:
// JSON schema with anyOf having issues with eror messaging.varjsonCode=["{",' "p1": {',' "shape" : ""',' },','"p2" : ""',"}"].join("\n");varmodelUri=monaco.Uri.parse("a://b/foo.json");// a made up unique URI for our modelvarmodel=monaco.editor.createModel(jsonCode,"json",modelUri);// configure the JSON language support with schemas and schema associationsmonaco.languages.json.jsonDefaults.setDiagnosticsOptions({validate: true,schemaValidation: "error",schemas: [{uri: "http://myserver/foo-schema.json",// id of the first schemafileMatch: [modelUri.toString()],// associate with our modelschema: {properties: {p1: {anyOf: [{$ref: "http://myserver/rectangle.json"},{$ref: "http://myserver/square.json"}],},p2: {type: "string",enum: ["square","rectangle"]},},},},{uri: "http://myserver/rectangle.json",// id of the second schemaschema: {type: "object",properties: {"shape" : {type: "string",const: "rectangle"}},},},{uri: "http://myserver/square.json",// id of the second schemaschema: {type: "object",properties: {shape: {type: "string",const: "square"},},},},],});monaco.editor.create(document.getElementById("container"),{model: model});
One can solve this problem by defining a custom errorMessage property in each of the schema, but that creates another issue documented in #205.
The text was updated successfully, but these errors were encountered:
Error messaging is one of the powerful features of the monaco editor that works alright for most json schema features. However, when using
anyOf
(oroneOf
) to define multiple acceptable values for a property error messaging assumes that the schema uniquely maps to the property first defined in theanyOf
array.Screenshot:
In the above example, the issue is that the schema defines both
rectangle
andsquare
as acceptable values for thep1.shape
property but the error messaging insists that the value must berectangle
.This is in contrast to enums for which it works perfectly as shown in the example below, but for complex schema that requires either
anyOf
oroneOf
support, it falls short:Appendix
Code for Monaco playground:
One can solve this problem by defining a custom
errorMessage
property in each of the schema, but that creates another issue documented in #205.The text was updated successfully, but these errors were encountered: