Skip to content

Commit

Permalink
chore(prettier): reformat files
Browse files Browse the repository at this point in the history
  • Loading branch information
jonluca committed Aug 1, 2024
1 parent edcb80a commit 9a5e4a0
Show file tree
Hide file tree
Showing 44 changed files with 264 additions and 321 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI-CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ jobs:
fail-fast: true
matrix:
os:
- ubuntu-latest # Chrome, Firefox
- windows-latest # Internet Explorer
- ubuntu-latest # Chrome, Firefox
- windows-latest # Internet Explorer

steps:
- name: Checkout source
Expand Down
13 changes: 3 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"runtimeArgs": ["--nolazy"],
"env": {
"NODE_ENV": "development"
},
Expand All @@ -26,16 +24,11 @@
"request": "launch",
"program": "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js",
"stopOnEntry": false,
"args": [
"run",
"test:typescript"
],
"args": ["run", "test:typescript"],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"runtimeArgs": ["--nolazy"],
"env": {
"NODE_ENV": "development"
},
Expand Down
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"kind": "build",
"isDefault": true
},
"problemMatcher": "$tsc",
"problemMatcher": "$tsc"
},
{
"type": "npm",
"script": "test:node",
"group": {
"kind": "test",
"isDefault": true
},
},
}
}
]
}
60 changes: 26 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
[![License](https://img.shields.io/npm/l/@apidevtools/json-schema-ref-parser.svg)](LICENSE)
[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](https://plant.treeware.earth/APIDevTools/json-schema-ref-parser)

Installation
--------------------------
## Installation

Install using [npm](https://docs.npmjs.com/about-npm/):

```bash
Expand All @@ -19,8 +19,8 @@ yarn add @apidevtools/json-schema-ref-parser
bun add @apidevtools/json-schema-ref-parser
```

The Problem:
--------------------------
## The Problem:

You've got a JSON Schema with `$ref` pointers to other files and/or URLs. Maybe you know all the referenced files ahead
of time. Maybe you don't. Maybe some are local files, and others are remote URLs. Maybe they are a mix of JSON and YAML
format. Maybe some of the files contain cross-references to each other.
Expand Down Expand Up @@ -48,8 +48,8 @@ format. Maybe some of the files contain cross-references to each other.
}
```

The Solution:
--------------------------
## The Solution:

JSON Schema $Ref Parser is a full [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03)
and [JSON Pointer](https://tools.ietf.org/html/rfc6901) implementation that crawls even the most
complex [JSON Schemas](http://json-schema.org/latest/json-schema-core.html) and gives you simple, straightforward
Expand All @@ -68,8 +68,7 @@ JavaScript objects.
instance
- Compatible with Node LTS and beyond, and all major web browsers on Windows, Mac, and Linux

Example
--------------------------
## Example

```javascript
import $RefParser from "@apidevtools/json-schema-ref-parser";
Expand All @@ -89,10 +88,7 @@ try {

For more detailed examples, please see the [API Documentation](https://apitools.dev/json-schema-ref-parser/docs/)


Polyfills
--------------------------

## Polyfills

If you are using Node.js < 18, you'll need a polyfill for `fetch`,
like [node-fetch](https://github.com/node-fetch/node-fetch):
Expand All @@ -103,8 +99,8 @@ import fetch from "node-fetch";
globalThis.fetch = fetch;
```

Browser support
--------------------------
## Browser support

JSON Schema $Ref Parser supports recent versions of every major web browser. Older browsers may
require [Babel](https://babeljs.io/) and/or [polyfills](https://babeljs.io/docs/en/next/babel-polyfill).

Expand All @@ -121,54 +117,50 @@ Edit your `webpack.config.js` :

```js
config.resolve.fallback = {
"path": require.resolve("path-browserify"),
'fs': require.resolve('browserify-fs')
}
path: require.resolve("path-browserify"),
fs: require.resolve("browserify-fs"),
};

config.plugins.push(
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
)

Buffer: ["buffer", "Buffer"],
}),
);
```

API Documentation
--------------------------
## API Documentation

Full API documentation is available [right here](https://apitools.dev/json-schema-ref-parser/docs/)

## Contributing

Contributing
--------------------------
I welcome any contributions, enhancements, and
bug-fixes. [Open an issue](https://github.com/APIDevTools/json-schema-ref-parser/issues) on GitHub
bug-fixes. [Open an issue](https://github.com/APIDevTools/json-schema-ref-parser/issues) on GitHub
and [submit a pull request](https://github.com/APIDevTools/json-schema-ref-parser/pulls).

#### Building/Testing

To build/test the project locally on your computer:

1. __Clone this repo__<br>
1. **Clone this repo**<br>
`git clone https://github.com/APIDevTools/json-schema-ref-parser.git`

2. __Install dependencies__<br>
2. **Install dependencies**<br>
`yarn install`

3. __Run the tests__<br>
3. **Run the tests**<br>
`yarn test`

License
--------------------------
## License

JSON Schema $Ref Parser is 100% free and open-source, under the [MIT license](LICENSE). Use it however you want.

This package is [Treeware](http://treeware.earth). If you use it in production, then we ask that you [**buy the world a
tree**](https://plant.treeware.earth/APIDevTools/json-schema-ref-parser) to thank us for our work. By contributing to
the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

## Big Thanks To


Big Thanks To
--------------------------
Thanks to these awesome companies for their support of Open Source developers ❤

[![Stoplight](https://svgshare.com/i/TK5.svg)](https://stoplight.io/?utm_source=github&utm_medium=readme&utm_campaign=json_schema_ref_parser)
Expand Down
53 changes: 25 additions & 28 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
JSON Schema $Ref Parser API
==========================
# JSON Schema $Ref Parser API

## Things to Know

Things to Know
---------------------
- [Class methods vs. Instance methods](#class-methods-vs-instance-methods)
- [Callbacks vs. Promises](#callbacks-vs-promises)
- [Circular references](#circular-refs)


Classes & Methods
---------------------
## Classes & Methods

#### [The `$RefParser` class](ref-parser.md)

- [`schema` property](ref-parser.md#schema)
- [`$refs` property](ref-parser.md#refs)
- [`dereference()` method](ref-parser.md#dereferenceschema-options-callback)
Expand All @@ -20,6 +18,7 @@ Classes & Methods
- [`resolve()` method](ref-parser.md#resolveschema-options-callback)

#### [The `$Refs` class](refs.md)

- [`circular` property](refs.md#circular)
- [`paths()` method](refs.md#pathstypes)
- [`values()` method](refs.md#valuestypes)
Expand All @@ -29,9 +28,9 @@ Classes & Methods

#### [The `Options` object](options.md)


### Class methods vs. Instance methods
All of JSON Schema $Ref Parser's methods are available as static (class) methods, and as instance methods. The static methods simply create a new [`$RefParser`](ref-parser.md) instance and then call the corresponding instance method. Thus, the following line...

All of JSON Schema $Ref Parser's methods are available as static (class) methods, and as instance methods. The static methods simply create a new [`$RefParser`](ref-parser.md) instance and then call the corresponding instance method. Thus, the following line...

```javascript
$RefParser.bundle("my-schema.json");
Expand All @@ -46,47 +45,45 @@ parser.bundle("my-schema.json");

The difference is that in the second example you now have a reference to `parser`, which means you can access the results ([`parser.schema`](ref-parser.md#schema) and [`parser.$refs`](ref-parser.md#refs)) anytime you want, rather than just in the callback function.


### Callbacks vs. Promises
Many people prefer [Promise syntax](http://javascriptplayground.com/blog/2015/02/promises/) or `async`/`await` instead of callbacks. JSON Schema $Ref Parser allows you to use whichever one you prefer.

If you pass a callback function to any method, then the method will call the callback using the Node.js error-first convention. If you do _not_ pass a callback function, then the method will return a Promise.
Many people prefer [Promise syntax](http://javascriptplayground.com/blog/2015/02/promises/) or `async`/`await` instead of callbacks. JSON Schema $Ref Parser allows you to use whichever one you prefer.

If you pass a callback function to any method, then the method will call the callback using the Node.js error-first convention. If you do _not_ pass a callback function, then the method will return a Promise.

The following two examples are equivalent:

```javascript
// Callback syntax
$RefParser.dereference(mySchema, (err, api) => {
if (err) {
// Error
}
else {
// Success
}
if (err) {
// Error
} else {
// Success
}
});
```

```javascript
try {
// async/await syntax
let api = await $RefParser.dereference(mySchema);
// async/await syntax
let api = await $RefParser.dereference(mySchema);

// Success
}
catch (err) {
// Error
// Success
} catch (err) {
// Error
}
```


### Circular $Refs
JSON Schema files can contain [circular $ref pointers](https://gist.github.com/JamesMessinger/d18278935fc73e3a0ee1), and JSON Schema $Ref Parser fully supports them. Circular references can be resolved and dereferenced just like any other reference. However, if you intend to serialize the dereferenced schema as JSON, then you should be aware that [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) does not support circular references by default, so you will need to [use a custom replacer function](https://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json).

JSON Schema files can contain [circular $ref pointers](https://gist.github.com/JamesMessinger/d18278935fc73e3a0ee1), and JSON Schema $Ref Parser fully supports them. Circular references can be resolved and dereferenced just like any other reference. However, if you intend to serialize the dereferenced schema as JSON, then you should be aware that [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) does not support circular references by default, so you will need to [use a custom replacer function](https://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json).

You can disable circular references by setting the [`dereference.circular`](options.md) option to `false`. Then, if a circular reference is found, a `ReferenceError` will be thrown.

Or you can choose to just ignore circular references altogether by setting the [`dereference.circular`](options.md) option to `"ignore"`. In this case, all non-circular references will still be dereferenced as normal, but any circular references will remain in the schema.
Or you can choose to just ignore circular references altogether by setting the [`dereference.circular`](options.md) option to `"ignore"`. In this case, all non-circular references will still be dereferenced as normal, but any circular references will remain in the schema.

Another option is to use the [`bundle`](ref-parser.md#bundleschema-options-callback) method rather than the [`dereference`](ref-parser.md#dereferenceschema-options-callback) method. Bundling does _not_ result in circular references, because it simply converts _external_ `$ref` pointers to _internal_ ones.
Another option is to use the [`bundle`](ref-parser.md#bundleschema-options-callback) method rather than the [`dereference`](ref-parser.md#dereferenceschema-options-callback) method. Bundling does _not_ result in circular references, because it simply converts _external_ `$ref` pointers to _internal_ ones.

```javascript
"person": {
Expand Down
Loading

0 comments on commit 9a5e4a0

Please sign in to comment.