Skip to content
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

Issue with required in schema #125

Open
medihack opened this issue Oct 14, 2021 · 4 comments
Open

Issue with required in schema #125

medihack opened this issue Oct 14, 2021 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed language server Upstream language server issue

Comments

@medihack
Copy link
Contributor

medihack commented Oct 14, 2021

With the below schema and an empty Monaco editor, I initially get the correct error message Missing property "title". If I then type in a title the error message correctly disappears, but if I delete the title again the error message is not showing up anymore.

Could an upgrade to yaml-language-server v1.0 fix this (I saw that you replaced nodeca/js-yaml with eemeli/yaml over there)?

import { JSONSchema7 } from "json-schema"

export const schema: JSONSchema7 = {
  type: "object",
  properties: {
    title: { type: "string" },
  },
  required: ["title"],
}
@medihack
Copy link
Contributor Author

medihack commented Oct 15, 2021

I just want to add that this is also easily reproducible in the Monaco YAML example:

  • Go to https://monaco-yaml.js.org/
  • Delete the whole text
  • Switch to openapi.json
  • Missing properties are shown in the problems view
  • Type in a character (other problems are shown then) and delete the character again
  • The problems view is empty now

@remcohaszing
Copy link
Owner

I think yaml-language-server simply doesn’t do validation if the document is empty. I think this is indended behaviour. This decision isn’t made by monaco-yaml.

If the type is incorrect, it shows Incorrect type, Expected "2021-09-28", which seems to refer to the last URL segment of the schema $id: https://spec.openapis.org/oas/3.1/schema/2021-09-28. This looks like a bug in yaml-language-server. I can also reproduce this in VS Code by editing a file named openapi.yaml and adding the following content:

foo

@medihack could you create the upstream bug?

@remcohaszing remcohaszing added bug Something isn't working language server Upstream language server issue labels Oct 17, 2021
@remcohaszing
Copy link
Owner

Could an upgrade to yaml-language-server v1.0 fix this (I saw that you replaced nodeca/js-yaml with eemeli/yaml over there)?

This isn’t fixed by the upgrade to yaml-language-server 1.0. (See #126)

js-yaml was only used to parse JSON schemas defined as YAML. I did this purely to get rid of an unnecessary dependency, because in 1.0 yaml-languageserver-parser has also been replaced with yaml.

@medihack
Copy link
Contributor Author

I think yaml-language-server simply doesn’t do validation if the document is empty. I think this is indended behaviour. This decision isn’t made by monaco-yaml.

@remcohaszing I wonder if this is really the case, because when I empty the document on the demo site and switch to another schema (e.g. .build.yml) the error messages are shown correctly for the empty document. So it seems the language server does evaluate an empty document.

If the type is incorrect, it shows Incorrect type, Expected "2021-09-28", which seems to refer to the last URL segment of the schema $id: https://spec.openapis.org/oas/3.1/schema/2021-09-28. This looks like a bug in yaml-language-server.

Not sure if this is always the case, because for example with the .build.yml schema I get the message Incorrect type. Expected "Sourcehut Build Manifest". which is not part of the URL.

@remcohaszing remcohaszing added the help wanted Extra attention is needed label Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed language server Upstream language server issue
Projects
None yet
Development

No branches or pull requests

2 participants