yaml-language-server
                                
                                 yaml-language-server copied to clipboard
                                
                                    yaml-language-server copied to clipboard
                            
                            
                            
                        Apply schema to custom file name
I would like to apply the OpenAPI (swagger) schema to a YAML file that's not named openapi.yaml. The schema seems to only apply to files named openapi.yaml. How can I tell yaml-language-server to apply the openapi schema to a file with a custom file name?
Also, would this configuration be possible to set in a project's package.json file?
@Melkster You can use settings to map your schema to file.
I've tried adding this to my config but it doesn't seem to apply the schema:
"yaml": {
  "schemas": {
    "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json":  "custom-filename.yaml"
  }
}
hm, that strange. Could you try:
"yaml.schemas": {
    "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json":  "custom-filename.yaml"
}
Nope, still doesn't work :/
The thing is that I'm using yaml-language-server with Neovim's built-in LSP client, which is configured using Lua, not JSON, and I've tried various configurations, including
{
  ['yaml.schemas'] = {
    ['https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json'] = 'custom-filename.yaml'
  },
}
and
{
  ['yaml'] = {
    ['schemas'] = {
      ['https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json'] = 'custom-filename.yaml'
    }
  },
}
You can try to use an inlined declaration of the yaml schema, see https://github.com/redhat-developer/yaml-language-server#using-inlined-schema
so would be something like:
# yaml-language-server: $schema=https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json

In neovim, you would need some specific neovim extension to provide the parameters from the client to the server. I do not think that all settings are passed to the language server by default.
For instance in VS Code Yaml, I think that related code is here: https://github.com/redhat-developer/vscode-yaml/blob/75f3f8c5ccb04444f82003c3c1084351d95b9955/src/extension.ts#L146 https://github.com/redhat-developer/vscode-yaml/blob/75f3f8c5ccb04444f82003c3c1084351d95b9955/src/extension.ts#L150
@apupier Ok! I tried using inlined schema like you suggested but that didn't work either.
@Melkster Can you precise which version of the yaml language server you are using please? 0.10.0+ is required for the inlined schema https://github.com/redhat-developer/yaml-language-server/blob/main/CHANGELOG.md#0100
@apupier How do I find the version? I seem to be getting an error when I try to run yaml-language-server with only a --version flag
it depends from where/how you are grabbing the yaml-language-server.
if you can open it, or find it in side node_modules folder, in the package.json, you will find the version
@apupier In the package.json it says 0.22.0
@mawkler have you got this working eventually? This is a feature that works on vscode. I am closing this, for now, let us know if this still needs our attention.