-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type errors inform wrong type when parent schema has keyword "title" #845
Comments
I did some preliminary code digging and it looks like //get more specific name than just object
const schemaType = schema.type === 'object' ? getSchemaTypeName(schema) : schema.type;
if (schema.title) {
return schema.title;
} It's fine for parent schema, but why would we want to propagate that to all it's properties which are |
Ok, so this issue should be fixed but I think I understand the original intent. Spitting out a warning that tells users the type should be Maybe an error message like |
Ya It may be useful. I will raise another PR on top of this |
@rgrunber this makes even more sense, having both seems like a win win. I would even argue it might be a good approach for both scenarios (having title set in the current node too), it's always good to know there's an object expected instead of a string, if the users are only presented with the title they will always have to resort to checking it with the schema. |
The fix will be available on the YAML 1.12.0 |
Describe the bug
It seems that using the
title
keyword propagates the element name to all it's properties which also have atype
ofobject
.I verified the behaviour against another JSON Schema implementation: https://www.jsonschemavalidator.net/.
Given the following schema:
It produced the following error:
Which makes absolute sense, since the type of the property
foo
isobject
.However that's not the case with yaml-language-server, which instead treats all
type
errors forobject
properties of a schema with settitle
keyword as If they had the same type as the parent schema, i.e.THE OBJECT
.It only happens when the property is of type
object
, If we now changebar
to an invalid type, let's sayobject
it will produce the right error, telling us it should be a string:Expected Behavior
Displayed error should be referring to the property
type
, not the parent schematype
.Current Behavior
Displayed error informs about parent schema
type
, instead of the propertytype
mismatch.Steps to Reproduce
Copy the schema provided in the description and play around with it as described.
Environment
The text was updated successfully, but these errors were encountered: