Default Resolvers Not Resolving Relative to Given Document
See original GitHub issueDescribe the bug The default resolvers don’t function as documented.
By default, http(s) and file protocols are resolved, relatively to the document Spectral lints against. [Emphasis mine]
However, when linting with a new Spectral()
object, the file $ref
s are resolved relative to where the script runs, not the file being linted.
To Reproduce
C:/api/openapi.yaml
:
openapi: 3.0.3
info:
title: Test API
version: 1.0.0
paths:
/test:
get:
responses:
'200':
$ref: components.yaml#/Ok
C:/api/components.yaml
:
Ok:
description: Success
C:/dev/script.ts
:
import fs from 'fs';
import YAML from 'js-yaml';
import { isOpenApiv3, Spectral } from '@stoplight/spectral';
import { DiagnosticSeverity } from '@stoplight/types';
const openApi = fs.readFileSync('C:/api/openapi.yaml', 'utf-8');
const spectral = new Spectral();
spectral.registerFormat('oas3', isOpenApiv3);
spectral.run(YAML.safeLoad(openApi) as string)
.then(results => {
results.filter(result => result.severity === DiagnosticSeverity.Error)
.forEach(result => console.log(result.message))
});
$ ts-node C:\dev\script.ts
ENOENT: no such file or directory, open 'C:\dev\components.yaml'
Expected behavior
Given the OpenAPI document and script above, there should be no errors and therefore no output. Spectral
’s default resolvers should be looking for C:/api/components.yaml
, not C:/dev/components.yaml
.
Environment:
- TypeScript: v3.9.6
- Spectral: v5.5.0
- Node: v12.15.0
- Windows: 10 Enterprise
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Resolvers - Apollo GraphQL Docs
This object is called the resolver map. The resolver map has top-level fields that correspond to your schema's types (such as Query above)....
Read more >Parcel 2: Specific resolvers per file type · Issue #3492 - GitHub
The problem is script and link elements in the browser resolve bare specifiers (without './ or / prefixes) as relative paths, not as...
Read more >Resolver - Parcel
Resolvers run in a pipeline until one of them returns a result. See Dependency resolution for details on how the default resolver works....
Read more >Using eslint with typescript - Unable to resolve path to module
In my eslintrc.js config file, the "import/resolver" object needed to sit within the "rules" node, not the " ...
Read more >The dns.resolver.Resolver and dns.resolver.Answer Classes
If the query name is a relative name, the resolver will construct ... An int , the default DNS port to send to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dillonredding That would be great location.
Indeed. This would bring some attention from the reader 😉
That’s not a bad idea! Maybe between the “Linting an Object” and “Registering Formats” sections?
Just want to clarify, by “warning”, you mean like the blockquote here (with the
theme: warning
comment)? I could definitely see that being helpful in “Linting a YAML String” and “Linting an Object” sections and just point to the new section.