Skip to content

Commit 7a54120

Browse files
authored
Merge pull request #1 from hey-api/feat/download-resolve
refactor: simplify the code to serve Hey API requirements
2 parents 70626d3 + c667923 commit 7a54120

32 files changed

+1562
-2534
lines changed

.github/FUNDING.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
github: philsturgeon
1+
github:
2+
- mrlubos
3+
- hey-api

.github/workflows/CI-CD.yaml

+34-29
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ jobs:
4444
- name: Run linter
4545
run: yarn lint
4646

47-
- name: Run Node tests
48-
run: yarn test:node
47+
# disabled after refactoring
48+
# - name: Run Node tests
49+
# run: yarn test:node
4950

50-
- name: Send code coverage results to Coveralls
51-
uses: coverallsapp/github-action@v2
52-
with:
53-
github-token: ${{ secrets.GITHUB_TOKEN }}
54-
parallel: true
51+
# disabled after refactoring
52+
# - name: Send code coverage results to Coveralls
53+
# uses: coverallsapp/github-action@v2
54+
# with:
55+
# github-token: ${{ secrets.GITHUB_TOKEN }}
56+
# parallel: true
5557

5658
browser_tests:
5759
name: Browser Tests
@@ -76,28 +78,31 @@ jobs:
7678
- name: Install dependencies
7779
run: yarn install --frozen-lockfile
7880

79-
- name: Run tests
80-
run: yarn test:browser
81-
82-
- name: Send code coverage results to Coveralls
83-
uses: coverallsapp/github-action@v2
84-
with:
85-
github-token: ${{ secrets.GITHUB_TOKEN }}
86-
parallel: true
87-
88-
coverage:
89-
name: Code Coverage
90-
runs-on: ubuntu-latest
91-
timeout-minutes: 5
92-
needs:
93-
- node_tests
94-
- browser_tests
95-
steps:
96-
- name: Let Coveralls know that all tests have finished
97-
uses: coverallsapp/github-action@v2
98-
with:
99-
github-token: ${{ secrets.GITHUB_TOKEN }}
100-
parallel-finished: true
81+
# disabled after refactoring
82+
# - name: Run tests
83+
# run: yarn test:browser
84+
85+
# disabled after refactoring
86+
# - name: Send code coverage results to Coveralls
87+
# uses: coverallsapp/github-action@v2
88+
# with:
89+
# github-token: ${{ secrets.GITHUB_TOKEN }}
90+
# parallel: true
91+
92+
# disabled after refactoring
93+
# coverage:
94+
# name: Code Coverage
95+
# runs-on: ubuntu-latest
96+
# timeout-minutes: 5
97+
# needs:
98+
# - node_tests
99+
# - browser_tests
100+
# steps:
101+
# - name: Let Coveralls know that all tests have finished
102+
# uses: coverallsapp/github-action@v2
103+
# with:
104+
# github-token: ${{ secrets.GITHUB_TOKEN }}
105+
# parallel-finished: true
101106

102107
release:
103108
name: Release

.yarn/releases/yarn-4.2.2.cjs

-894
This file was deleted.

.yarn/releases/yarn-4.5.3.cjs

+934
Large diffs are not rendered by default.

.yarnrc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
nodeLinker: node-modules
22

3-
yarnPath: .yarn/releases/yarn-4.2.2.cjs
3+
yarnPath: .yarn/releases/yarn-4.5.3.cjs

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
> This is a modified fork to serve Hey API needs
2+
13
# JSON Schema $Ref Parser
24

35
#### Parse, Resolve, and Dereference JSON Schema $ref pointers

lib/bundle.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import $Ref from "./ref.js";
2+
import type { ParserOptions } from "./options.js";
23
import Pointer from "./pointer.js";
34
import * as url from "./util/url.js";
45
import type $Refs from "./refs.js";
5-
import type $RefParser from "./index";
6-
import type { ParserOptions } from "./index";
7-
import type { JSONSchema } from "./index";
6+
import type { $RefParser } from "./index";
7+
import type { JSONSchema } from "./types/index.js";
88

99
export interface InventoryEntry {
1010
$ref: any;
@@ -28,15 +28,15 @@ export interface InventoryEntry {
2828
* @param parser
2929
* @param options
3030
*/
31-
function bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
32-
parser: $RefParser<S, O>,
33-
options: O,
31+
function bundle(
32+
parser: $RefParser,
33+
options: ParserOptions,
3434
) {
3535
// console.log('Bundling $ref pointers in %s', parser.$refs._root$Ref.path);
3636

3737
// Build an inventory of all $ref pointers in the JSON Schema
3838
const inventory: InventoryEntry[] = [];
39-
crawl<S, O>(parser, "schema", parser.$refs._root$Ref.path + "#", "#", 0, inventory, parser.$refs, options);
39+
crawl<JSONSchema>(parser, "schema", parser.$refs._root$Ref.path + "#", "#", 0, inventory, parser.$refs, options);
4040

4141
// Remap all $ref pointers
4242
remap(inventory);
@@ -54,15 +54,15 @@ function bundle<S extends object = JSONSchema, O extends ParserOptions<S> = Pars
5454
* @param $refs
5555
* @param options
5656
*/
57-
function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
58-
parent: object | $RefParser<S, O>,
57+
function crawl<S extends object = JSONSchema>(
58+
parent: object | $RefParser,
5959
key: string | null,
6060
path: string,
6161
pathFromRoot: string,
6262
indirections: number,
6363
inventory: InventoryEntry[],
64-
$refs: $Refs<S, O>,
65-
options: O,
64+
$refs: $Refs<S>,
65+
options: ParserOptions,
6666
) {
6767
const obj = key === null ? parent : parent[key as keyof typeof parent];
6868

@@ -115,15 +115,15 @@ function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = Parse
115115
* @param $refs
116116
* @param options
117117
*/
118-
function inventory$Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
118+
function inventory$Ref<S extends object = JSONSchema>(
119119
$refParent: any,
120120
$refKey: string | null,
121121
path: string,
122122
pathFromRoot: string,
123123
indirections: number,
124124
inventory: InventoryEntry[],
125-
$refs: $Refs<S, O>,
126-
options: O,
125+
$refs: $Refs<S>,
126+
options: ParserOptions,
127127
) {
128128
const $ref = $refKey === null ? $refParent : $refParent[$refKey];
129129
const $refPath = url.resolve(path, $ref.$ref);

lib/dereference.ts

+14-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as url from "./util/url.js";
55
import type $Refs from "./refs.js";
66
import type { DereferenceOptions, ParserOptions } from "./options.js";
77
import type { JSONSchema } from "./types";
8-
import type $RefParser from "./index";
8+
import type { $RefParser } from "./index";
99
import { TimeoutError } from "./util/errors";
1010

1111
export default dereference;
@@ -17,13 +17,13 @@ export default dereference;
1717
* @param parser
1818
* @param options
1919
*/
20-
function dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
21-
parser: $RefParser<S, O>,
22-
options: O,
20+
function dereference(
21+
parser: $RefParser,
22+
options: ParserOptions,
2323
) {
2424
const start = Date.now();
2525
// console.log('Dereferencing $ref pointers in %s', parser.$refs._root$Ref.path);
26-
const dereferenced = crawl<S, O>(
26+
const dereferenced = crawl<JSONSchema>(
2727
parser.schema,
2828
parser.$refs._root$Ref.path!,
2929
"#",
@@ -52,15 +52,15 @@ function dereference<S extends object = JSONSchema, O extends ParserOptions<S> =
5252
* @param startTime - The time when the dereferencing started
5353
* @returns
5454
*/
55-
function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
55+
function crawl<S extends object = JSONSchema>(
5656
obj: any,
5757
path: string,
5858
pathFromRoot: string,
5959
parents: Set<any>,
6060
processedObjects: Set<any>,
6161
dereferencedCache: any,
62-
$refs: $Refs<S, O>,
63-
options: O,
62+
$refs: $Refs<S>,
63+
options: ParserOptions,
6464
startTime: number,
6565
) {
6666
let dereferenced;
@@ -82,7 +82,7 @@ function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = Parse
8282
parents.add(obj);
8383
processedObjects.add(obj);
8484

85-
if ($Ref.isAllowed$Ref(obj, options)) {
85+
if ($Ref.isAllowed$Ref(obj)) {
8686
dereferenced = dereference$Ref(
8787
obj,
8888
path,
@@ -108,7 +108,7 @@ function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = Parse
108108
const value = obj[key];
109109
let circular = false;
110110

111-
if ($Ref.isAllowed$Ref(value, options)) {
111+
if ($Ref.isAllowed$Ref(value)) {
112112
dereferenced = dereference$Ref(
113113
value,
114114
keyPath,
@@ -174,20 +174,18 @@ function crawl<S extends object = JSONSchema, O extends ParserOptions<S> = Parse
174174
* @param options
175175
* @returns
176176
*/
177-
function dereference$Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
177+
function dereference$Ref<S extends object = JSONSchema>(
178178
$ref: any,
179179
path: string,
180180
pathFromRoot: string,
181181
parents: Set<any>,
182182
processedObjects: any,
183183
dereferencedCache: any,
184-
$refs: $Refs<S, O>,
185-
options: O,
184+
$refs: $Refs<S>,
185+
options: ParserOptions,
186186
startTime: number,
187187
) {
188-
const isExternalRef = $Ref.isExternal$Ref($ref);
189-
const shouldResolveOnCwd = isExternalRef && options?.dereference?.externalReferenceResolution === "root";
190-
const $refPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, $ref.$ref);
188+
const $refPath = url.resolve(path, $ref.$ref);
191189

192190
const cache = dereferencedCache.get($refPath);
193191
if (cache && !cache.circular) {

0 commit comments

Comments
 (0)