vacuum icon indicating copy to clipboard operation
vacuum copied to clipboard

cannot resolve reference `#/components/schemas/SchemaName`, it's missing: $.components.schemas['SchemaName']

Open kubauk opened this issue 1 year ago • 2 comments

When using the language server in neovim, I am getting an error being reported that is not reported when running the lint command using vacuum in the terminal.

I am using neovim v0.10.1, and vacuum v0.12.1 installed using Mason. I also have vacuum v0.12.1 installed using brew in my environment.

It occurs when a component schema references another component schema. As far as I can tell this is fine if the reference is in the paths section and only happens when you try to references schemas from schemas.

You can use the below spec to reproduce the issue.

openapi: 3.0.0
info:
  title: Example
  version: 1.0.0
  description: Bug example
  contact:
    name: Bug name
    url: bug.example.com
    email: [email protected]
servers:
  - url: http://localhost
    description: Local development environment
components:
  schemas:
    ID:
      description: A unique ID
      type: string
      pattern: ^[0-9a-f]{32}$
      example: d0bf5a6a909111f0aabf02d14af18cff
    ReferenceToID:
      description: An object that references the ID
      type: object
      properties:
        id:
          $ref: '#/components/schemas/ID'
        otherProp:
          type: string
          example: Some string
      example:
        id: 0123456789abcdef0123456789abcdef
        otherProp: Some string

In neovim, for the spec, it reports the following errors and warnings:

openapi-example.yml|2 col 2 error| schema invalid: missing properties: 'paths' openapi-example.yml|21 col 7 warning| #/components/schemas/ReferenceToID is potentially unused or has been orphaned openapi-example.yml|25 col 11-15 error| cannot resolve reference #/components/schemas/ID, it's missing: $.components.schemas['ID'] [25:11]

While using vaccum in the command line using the command:

vacuum lint -dq openapi-example.yml

It produces the following list of errors:



██╗   ██╗ █████╗  ██████╗██╗   ██╗██╗   ██╗███╗   ███╗
██║   ██║██╔══██╗██╔════╝██║   ██║██║   ██║████╗ ████║
██║   ██║███████║██║     ██║   ██║██║   ██║██╔████╔██║
╚██╗ ██╔╝██╔══██║██║     ██║   ██║██║   ██║██║╚██╔╝██║
 ╚████╔╝ ██║  ██║╚██████╗╚██████╔╝╚██████╔╝██║ ╚═╝ ██║
  ╚═══╝  ╚═╝  ╚═╝ ╚═════╝ ╚═════╝  ╚═════╝ ╚═╝     ╚═╝


version: 0.12.1 | compiled: Fri, 16 Aug 2024 14:08:38 UTC
🔗 https://quobix.com/vacuum | https://github.com/daveshanley/vacuum


INFO: Linting file 'openapi-example.yml' against 44 rules: https://quobix.com/vacuum/rulesets/recommended



/Users/kuba/Google Drive/My Drive/src/payouts/openapi-example.yml
-----------------------------------------------------------------
Location                 | Severity | Message                                                                         | Rule                  | Category | Path
openapi-example.yml:0:0  | error    | schema invalid: missing properties: 'paths'                                     | oas3-schema           | Schemas  |
openapi-example.yml:21:7 | warning  | `#/components/schemas/ReferenceToID` is potentially unused or has been orphaned | oas3-unused-component | Schemas  | $.components.schemas['ReferenceToID']

Category | Errors | Warnings | Info
Schemas  | 1      | 1        | 0

Linting file 'openapi-example.yml' failed with 1 errors, 1 warnings and 0 informsError: failed with 1 errors

As you can see the error is missing, and this gives an impression in the editor that the spec has a problem when it does not.

kubauk avatar Aug 21 '24 16:08 kubauk

do you still get the pb ?

🤔not sure what is wrong there , at least the command line in vacuum looks right ? isnt'it

it is true that the ReferenceToID has been orphaned , and that looks the unique error

btw updgrading to 3.1.0 will drop the error

make sure your neovim is using the right version of vacuum and adjust as well may be the base when running in neovim

LasneF avatar Sep 26 '24 16:09 LasneF

What do you mean by pb?

I think I wasn't too clear on the actual issue.

Yes, the command line has no issue.

And yes, ReferenceToID is orphaned so this is expected in both the command line and neovim.

The only issue is that with the command line there is no error/warning for using a $ref to a schema from another schema while in the LSP provided for neovim, it is flagged as an error. And I believe this to be false negative as I believe it is perfectly valid to reference a schema object from another schema object.

kubauk avatar Sep 30 '24 15:09 kubauk

Hi,

I looked at this today using v0.14.3

I saw this in the CLI

Screenshot 2024-11-21 at 10 52 10 AM

Which is correct.

The I loaded up VSCode and enabled the vacuum plugin

I saw this :

Screenshot 2024-11-21 at 10 59 01 AM

Same thing.

I can't help beyond this, I can't reproduce it using the language server (which is what you were seeing) or the CLI. They are in sync and doing the same thing.

Sorry I can't help more, but I don't use neovim, even so - when using the LSP, I still can't re-create it.

daveshanley avatar Nov 21 '24 16:11 daveshanley