Skip to content

Commit

Permalink
fix: normalize documentUri (#1185)
Browse files Browse the repository at this point in the history
* fix: pass documentUri

* fix: alternative way
  • Loading branch information
P0lip committed May 28, 2020
1 parent 0255f98 commit 7136b90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/document.ts
Expand Up @@ -17,10 +17,13 @@ export interface IDocument<D = unknown> {
data: D;
}

const normalizeSource = (source: Optional<string>): string | null => {
export function normalizeSource(source: undefined): null;
export function normalizeSource(source: string): string;
export function normalizeSource(source: Optional<string>): string | null;
export function normalizeSource(source: Optional<string>): string | null {
if (source === void 0) return null;
return source && !startsWithProtocol(source) ? normalize(source) : source;
};
return source.length > 0 && !startsWithProtocol(source) ? normalize(source) : source;
}

export class Document<D = unknown, R extends IParserResult = IParserResult<D>> implements IDocument<D> {
protected readonly parserResult: R;
Expand Down
4 changes: 2 additions & 2 deletions src/spectral.ts
Expand Up @@ -5,7 +5,7 @@ import { YamlParserResult } from '@stoplight/yaml';
import { memoize, merge } from 'lodash';

import { STATIC_ASSETS } from './assets';
import { Document, IDocument, IParsedResult, isParsedResult, ParsedDocument } from './document';
import { Document, IDocument, IParsedResult, isParsedResult, ParsedDocument, normalizeSource } from './document';
import { DocumentInventory } from './documentInventory';
import { CoreFunctions, functions as coreFunctions } from './functions';
import * as Parsers from './parsers';
Expand Down Expand Up @@ -80,7 +80,7 @@ export class Spectral {
const document = this.parseDocument(target);

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

const inventory = new DocumentInventory(document, this._resolver);
Expand Down

0 comments on commit 7136b90

Please sign in to comment.