Skip to content

Commit

Permalink
fix: pass documentUri
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed May 28, 2020
1 parent 2278e94 commit 0d71a61
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/spectral.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { safeStringify } from '@stoplight/json';
import { Resolver } from '@stoplight/json-ref-resolver';
import { DiagnosticSeverity, Dictionary } from '@stoplight/types';
import { DiagnosticSeverity, Dictionary, Optional } from '@stoplight/types';
import { YamlParserResult } from '@stoplight/yaml';
import { memoize, merge } from 'lodash';

Expand Down Expand Up @@ -62,22 +62,26 @@ export class Spectral {
Object.assign(STATIC_ASSETS, assets);
}

protected parseDocument(target: IParsedResult | IDocument | object | string): IDocument {
protected parseDocument(
target: IParsedResult | IDocument | object | string,
documentUri: Optional<string>,
): IDocument {
return target instanceof Document
? target
: isParsedResult(target)
? new ParsedDocument(target)
: new Document<unknown, YamlParserResult<unknown>>(
typeof target === 'string' ? target : safeStringify(target, undefined, 2),
Parsers.Yaml,
documentUri,
);
}

public async runWithResolved(
target: IParsedResult | IDocument | object | string,
opts: IRunOpts = {},
): Promise<ISpectralFullResult> {
const document = this.parseDocument(target);
const document = this.parseDocument(target, opts.resolve?.documentUri);

if (document.source === null && opts.resolve?.documentUri !== void 0) {
(document as Omit<Document, 'source'> & { source: string }).source = opts.resolve?.documentUri;
Expand Down

0 comments on commit 0d71a61

Please sign in to comment.