Skip to content

Commit 83132aa

Browse files
Физули Махмудовphilsturgeon
authored andcommitted
Add tests for lowercase bug
1 parent c24cd22 commit 83132aa

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

test/specs/resolvers/dereferenced.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ module.exports =
88
baz: "hello world"
99
}
1010
},
11+
bar: {
12+
Foo: {
13+
Baz: "hello world"
14+
}
15+
},
1116
name: {
1217
required: [
1318
"first",

test/specs/resolvers/parsed.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module.exports =
66
foo: {
77
$ref: "foo://bar.baz"
88
},
9+
bar: {
10+
$ref: "bar://Foo.Baz"
11+
},
912
pet: {
1013
$ref: "definitions/pet.yaml"
1114
},

test/specs/resolvers/resolvers.spec.js

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ describe("options.resolve", () => {
3737
foo: {
3838
canRead: /^foo\:\/\//i,
3939
read: { bar: { baz: "hello world" }}
40+
},
41+
bar: {
42+
canRead: /^bar\:\/\//i,
43+
read: { Foo: { Baz: "hello world" }}
4044
}
4145
}
4246
});
47+
4348
expect(schema).to.deep.equal(dereferencedSchema);
4449
});
4550

@@ -53,9 +58,41 @@ describe("options.resolve", () => {
5358
read (_file) {
5459
return { bar: { baz: "hello world" }};
5560
}
61+
},
62+
bar: {
63+
canRead: /^bar\:\/\//i,
64+
read (_file) {
65+
return { Foo: { Baz: "hello world" }};
66+
}
67+
}
68+
}
69+
});
70+
expect(schema).to.deep.equal(dereferencedSchema);
71+
});
72+
73+
it("should return _file url as it's written", async () => {
74+
const schema = await $RefParser
75+
.dereference(path.abs("specs/resolvers/resolvers.yaml"), {
76+
resolve: {
77+
// A custom resolver for "foo://" URLs
78+
foo: {
79+
canRead: /^foo\:\/\//i,
80+
read (_file) {
81+
return { bar: { baz: "hello world" }};
82+
}
83+
},
84+
// A custom resolver with uppercase symbols
85+
bar: {
86+
canRead: /^bar\:\/\//i,
87+
read (_file) {
88+
expect(_file.url).to.be.equal("bar://Foo.Baz");
89+
90+
return { Foo: { Baz: "hello world" }};
91+
}
5692
}
5793
}
5894
});
95+
5996
expect(schema).to.deep.equal(dereferencedSchema);
6097
});
6198

@@ -69,6 +106,12 @@ describe("options.resolve", () => {
69106
read (_file, callback) {
70107
callback(null, { bar: { baz: "hello world" }});
71108
}
109+
},
110+
bar: {
111+
canRead: /^bar\:\/\//i,
112+
read (_file, callback) {
113+
callback(null, { Foo: { Baz: "hello world" }});
114+
}
72115
}
73116
}
74117
});
@@ -86,6 +129,12 @@ describe("options.resolve", () => {
86129
read (_file) {
87130
return Promise.resolve({ bar: { baz: "hello world" }});
88131
}
132+
},
133+
bar: {
134+
canRead: /^bar\:\/\//i,
135+
read (_file) {
136+
return Promise.resolve({ Foo: { Baz: "hello world" }});
137+
}
89138
}
90139
}
91140
});
@@ -109,6 +158,10 @@ describe("options.resolve", () => {
109158
foo: {
110159
canRead: /^foo\:\/\//i,
111160
read: { bar: { baz: "hello world" }}
161+
},
162+
bar: {
163+
canRead: /^bar\:\/\//i,
164+
read: { Foo: { Baz: "hello world" }}
112165
}
113166
}
114167
});
@@ -165,9 +218,9 @@ describe("options.resolve", () => {
165218
await parser.dereference(path.abs("specs/resolvers/resolvers.yaml"), {
166219
resolve: {
167220
file: false,
168-
http: false,
221+
http: false
169222
},
170-
continueOnError: true,
223+
continueOnError: true
171224
});
172225
helper.shouldNotGetCalled();
173226
}
@@ -179,8 +232,8 @@ describe("options.resolve", () => {
179232
name: UnmatchedResolverError.name,
180233
message: message => message.startsWith("Could not find resolver for"),
181234
path: [],
182-
source: message => message.endsWith("specs/resolvers/resolvers.yaml"),
183-
},
235+
source: message => message.endsWith("specs/resolvers/resolvers.yaml")
236+
}
184237
]);
185238
}
186239
});

test/specs/resolvers/resolvers.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ definitions:
2727
$ref: "#/definitions/name/properties/first"
2828
foo:
2929
$ref: foo://bar.baz
30+
bar:
31+
$ref: bar://Foo.Baz
3032
pet:
3133
$ref: definitions/pet.yaml

0 commit comments

Comments
 (0)