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

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

Open
kubauk opened this issue Aug 21, 2024 · 2 comments

Comments

@kubauk
Copy link

kubauk commented Aug 21, 2024

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.

@LasneF
Copy link

LasneF commented Sep 26, 2024

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

@kubauk
Copy link
Author

kubauk commented Sep 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants