Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/__tests__/resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ describe('resolver', () => {
expect(resolved.result.hello).toBe('world');
});

test('should resolve json pointers pointing to falsy values', async () => {
const source = {
hello: {
$ref: '#/word',
},
word: '',
};

const resolver = new Resolver();
const resolved = await resolver.resolve(source);
expect(resolved.result.hello).toBe('');
});

test('should only resolve valid $refs', async () => {
const source = {
hello: {
Expand Down Expand Up @@ -526,6 +539,34 @@ describe('resolver', () => {
expect(resolved.result).toEqual(source);
});

test('should resolve jsonPointer pointing to remote falsy values', async () => {
const source = {
root: {
$ref: 'custom://whatever#/entry',
},
};

const reader: Types.IResolver = {
async resolve(): Promise<any> {
return {
entry: 0,
};
},
};

const resolver = new Resolver({
resolvers: {
custom: reader,
},
});

const resolved = await resolver.resolve(source);

expect(resolved.result).toEqual({
root: 0,
});
});

test('should support not resolving authorities', async () => {
const data = {
hello: 'world',
Expand Down
6 changes: 3 additions & 3 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class ResolveRunner implements Types.IResolveRunner {
resolved.result = get(resolved.result, targetPath);
}

if (!resolved.result) {
if (resolved.result === void 0) {
resolved.errors.push({
code: 'POINTER_MISSING',
message: `'${jsonPointer}' does not exist @ '${this.baseUri.toString()}'`,
Expand Down Expand Up @@ -157,7 +157,7 @@ export class ResolveRunner implements Types.IResolveRunner {
resolved.errors = resolved.errors.concat(r.resolved.errors);
}

if (!r.resolved.result) continue;
if (r.resolved.result === void 0) continue;

this._source = produce(this._source, (draft: any) => {
if (r.resolved) {
Expand Down Expand Up @@ -207,7 +207,7 @@ export class ResolveRunner implements Types.IResolveRunner {

resolved.refMap[pathToPointer(dependantPath)] = pathToPointer(pointerPath);

if (val) {
if (val !== void 0) {
set(draft, dependantPath, val);
} else {
resolved.errors.push({
Expand Down