Skip to content

Commit ed4ea05

Browse files
committed
Modernize dependencies, fix CI, upgrade dependencies, introduce new linter and formatter
BREAKING CHANGE: Pretty large refactor of dev experience. Removes ono dependency to fix certain CJS builds
1 parent 66d2818 commit ed4ea05

File tree

113 files changed

+6038
-6266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+6038
-6266
lines changed

.eslintrc.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/CI-CD.yaml

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- macos-latest
2323
- windows-latest
2424
node:
25-
- 20
25+
- 22
2626

2727
steps:
2828
- name: Checkout source
@@ -32,19 +32,19 @@ jobs:
3232
uses: actions/setup-node@v4
3333
with:
3434
node-version: ${{ matrix.node }}
35-
cache: "npm"
35+
cache: "yarn"
3636

3737
- name: Install dependencies
38-
run: npm ci
38+
run: yarn install --immutable
3939

4040
- name: Run linter
41-
run: npm run lint
41+
run: yarn lint
4242

4343
- name: Run TypeScript tests
44-
run: npm run test:typescript
44+
run: yarn test:typescript
4545

4646
- name: Run Node tests
47-
run: npm run coverage:node
47+
run: yarn coverage:node
4848

4949
- name: Send code coverage results to Coveralls
5050
uses: coverallsapp/github-action@v1.1.0
@@ -74,33 +74,14 @@ jobs:
7474
- node_tests
7575

7676
steps:
77-
- name: Checkout source
78-
uses: actions/checkout@v4
79-
80-
- name: Install Node
81-
uses: actions/setup-node@v4
77+
- uses: actions/checkout@v4
78+
- uses: actions/setup-node@v4
8279
with:
83-
node-version: 22
84-
cache: "npm"
85-
86-
- name: Install dependencies
87-
run: npm ci
88-
89-
- name: Publish to NPM
90-
run: npm publish --provenance --access public
91-
env:
92-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
93-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
94-
95-
- name: Prepare the non-scoped packaged
96-
run: |
97-
cp LICENSE *.md dist
98-
VERSION=$(node -e "console.log(require('./package.json').version)")
99-
sed -i "s/X.X.X/${VERSION}/g" dist/package.json
80+
node-version: latest
81+
cache: "yarn"
82+
- run: yarn install --immutable
10083

101-
- name: Publish the non-scoped package to NPM
102-
run: npm publish --provenance --access public
103-
working-directory: dist
84+
- run: npx semantic-release --branches main
10485
env:
105-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10687
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.yarn
2+
test/**/*.html

.vscode/launch.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,17 @@
77
"request": "launch",
88
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
99
"stopOnEntry": false,
10-
"args": [
11-
"--quick-test",
12-
"--timeout=600000"
13-
],
10+
"args": ["--quick-test", "--timeout=600000"],
1411
"cwd": "${workspaceRoot}",
1512
"preLaunchTask": null,
1613
"runtimeExecutable": null,
17-
"runtimeArgs": [
18-
"--nolazy"
19-
],
14+
"runtimeArgs": ["--nolazy"],
2015
"env": {
2116
"NODE_ENV": "development"
2217
},
2318
"console": "internalConsole",
2419
"sourceMaps": false,
25-
"skipFiles": [
26-
"<node_internals>/**/*.js"
27-
]
20+
"skipFiles": ["<node_internals>/**/*.js"]
2821
}
2922
]
3023
}

CHANGELOG.md

Lines changed: 36 additions & 73 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Swagger 2.0 and OpenAPI 3.0 parser/validator
2-
============================
1+
# Swagger 2.0 and OpenAPI 3.0 parser/validator
32

43
[![Build Status](https://github.com/APIDevTools/swagger-parser/workflows/CI-CD/badge.svg?branch=master)](https://github.com/APIDevTools/swagger-parser/actions)
54
[![Coverage Status](https://coveralls.io/repos/github/APIDevTools/swagger-parser/badge.svg?branch=master)](https://coveralls.io/github/APIDevTools/swagger-parser)
@@ -12,9 +11,8 @@ Swagger 2.0 and OpenAPI 3.0 parser/validator
1211

1312
[![OS and Browser Compatibility](https://apidevtools.com/img/badges/ci-badges-with-ie.svg)](https://github.com/APIDevTools/swagger-parser/actions)
1413

14+
## Features
1515

16-
Features
17-
--------------------------
1816
- Parses Swagger specs in **JSON** or **YAML** format
1917
- Validates against the [Swagger 2.0 schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json) or [OpenAPI 3.0 Schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.json)
2018
- [Resolves](https://apidevtools.com/swagger-parser/docs/swagger-parser.html#resolveapi-options-callback) all `$ref` pointers, including external files and URLs
@@ -25,24 +23,18 @@ Features
2523
- Supports [circular references](https://apidevtools.com/swagger-parser/docs/#circular-refs), nested references, back-references, and cross-references
2624
- Maintains object reference equality &mdash; `$ref` pointers to the same value always resolve to the same object instance
2725

26+
## Related Projects
2827

29-
30-
Related Projects
31-
--------------------------
3228
- [Swagger CLI](https://github.com/APIDevTools/swagger-cli)
3329
- [Swagger Express Middleware](https://github.com/APIDevTools/swagger-express-middleware)
3430

35-
36-
37-
Example
38-
--------------------------
31+
## Example
3932

4033
```javascript
4134
SwaggerParser.validate(myAPI, (err, api) => {
4235
if (err) {
4336
console.error(err);
44-
}
45-
else {
37+
} else {
4638
console.log("API name: %s, Version: %s", api.info.title, api.info.version);
4739
}
4840
});
@@ -54,28 +46,23 @@ Or use `async`/`await` or [Promise](http://javascriptplayground.com/blog/2015/02
5446
try {
5547
let api = await SwaggerParser.validate(myAPI);
5648
console.log("API name: %s, Version: %s", api.info.title, api.info.version);
57-
}
58-
catch(err) {
49+
} catch (err) {
5950
console.error(err);
6051
}
6152
```
6253

6354
For more detailed examples, please see the [API Documentation](https://apidevtools.com/swagger-parser/docs/)
6455

56+
## Installation
6557

66-
67-
Installation
68-
--------------------------
6958
Install using [npm](https://docs.npmjs.com/about-npm/):
7059

7160
```bash
7261
npm install @apidevtools/swagger-parser
7362
```
7463

64+
## Usage
7565

76-
77-
Usage
78-
--------------------------
7966
When using Swagger Parser in Node.js apps, you'll probably want to use **CommonJS** syntax:
8067

8168
```javascript
@@ -85,57 +72,49 @@ const SwaggerParser = require("@apidevtools/swagger-parser");
8572
When using a transpiler such as [Babel](https://babeljs.io/) or [TypeScript](https://www.typescriptlang.org/), or a bundler such as [Webpack](https://webpack.js.org/) or [Rollup](https://rollupjs.org/), you can use **ECMAScript modules** syntax instead:
8673

8774
```javascript
88-
import * as SwaggerParser from '@apidevtools/swagger-parser';
75+
import * as SwaggerParser from "@apidevtools/swagger-parser";
8976
```
9077

78+
## Browser support
9179

92-
93-
Browser support
94-
--------------------------
95-
Swagger 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).
80+
Swagger 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).
9681

9782
To use Swagger Parser in a browser, you'll need to use a bundling tool such as [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/), [Parcel](https://parceljs.org/), or [Browserify](http://browserify.org/). Some bundlers may require a bit of configuration, such as setting `browser: true` in [rollup-plugin-resolve](https://github.com/rollup/rollup-plugin-node-resolve).
9883

84+
## API Documentation
9985

100-
101-
API Documentation
102-
--------------------------
10386
Full API documentation is available [right here](https://apidevtools.com/swagger-parser/docs/)
10487

88+
## Security
10589

106-
Security
107-
--------------------------
10890
The library, by default, attempts to resolve any files referenced using `$ref`, without considering file extensions or the location of the files. This can result in Local File Inclusion (LFI), thus, potentially sensitive information disclosure. Developers must be cautious when working with documents from untrusted sources. See [here](SECURITY.md) for more details and information on how to mitigate LFI.
10991

92+
## Contributing
11093

111-
Contributing
112-
--------------------------
113-
I welcome any contributions, enhancements, and bug-fixes. [Open an issue](https://github.com/APIDevTools/swagger-parser/issues) on GitHub and [submit a pull request](https://github.com/APIDevTools/swagger-parser/pulls).
94+
I welcome any contributions, enhancements, and bug-fixes. [Open an issue](https://github.com/APIDevTools/swagger-parser/issues) on GitHub and [submit a pull request](https://github.com/APIDevTools/swagger-parser/pulls).
11495

11596
To test the project locally on your computer:
11697

117-
1. __Clone this repo__<br>
118-
`git clone https://github.com/APIDevTools/swagger-parser.git`
98+
1. **Clone this repo**<br>
99+
`git clone https://github.com/APIDevTools/swagger-parser.git`
119100

120-
2. __Install dependencies__<br>
121-
`npm install`
101+
2. **Install dependencies**<br>
102+
`npm install`
122103

123-
3. __Run the tests__<br>
124-
`npm test`
104+
3. **Run the tests**<br>
105+
`npm test`
125106

126-
4. __Check the code coverage__<br>
127-
`npm run coverage`
107+
4. **Check the code coverage**<br>
108+
`npm run coverage`
109+
110+
## License
128111

129-
License
130-
--------------------------
131112
Swagger Parser is 100% free and open-source, under the [MIT license](LICENSE). Use it however you want.
132113

133114
This package is [Treeware](http://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://shop.protect.earth) to thank us for our work.
134115

116+
## Big Thanks To
135117

136-
137-
Big Thanks To
138-
--------------------------
139118
Thanks to these awesome companies for their support of Open Source developers ❤
140119

141120
[![GitHub](https://apidevtools.com/img/badges/github.svg)](https://github.com/open-source)

SECURITY.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
The library, by default, attempts to resolve any files pointed to by `$ref`, which can be a problem in specific scenarios, for example:
88

9-
* A backend service uses the library, AND
10-
* The service processes OpenAPI documents from untrusted sources, AND
11-
* The service performs actual requests based on the processed OpenAPI document
9+
- A backend service uses the library, AND
10+
- The service processes OpenAPI documents from untrusted sources, AND
11+
- The service performs actual requests based on the processed OpenAPI document
1212

1313
For example, the below OpenAPI document refers to `/etc/passwd` via the `leak` property of the Pet object.
1414

@@ -30,7 +30,7 @@ paths:
3030
content:
3131
application/json:
3232
schema:
33-
$ref: '#/components/schemas/Pet'
33+
$ref: "#/components/schemas/Pet"
3434
required: true
3535
components:
3636
schemas:
@@ -46,8 +46,8 @@ components:
4646
example: 10
4747
leak:
4848
type: string
49-
default:
50-
$ref: '/etc/passwd'
49+
default:
50+
$ref: "/etc/passwd"
5151
name:
5252
type: string
5353
example: doggie
@@ -110,16 +110,16 @@ Configuring the file resolver this way only partially mitigates LFI. See the nex
110110

111111
With the previously mentioned mitigation in place, an attacker could still craft a malicious OpenAPI document to make the library read arbitrary JSON or YAML files on the filesystem and potentially gain access to sensitive data (e.g. credentials). This is possible if:
112112

113-
* The actor knows (or successfully guesses) the location of a JSON or YAML file on the file system
114-
* The service using the library has privileges to read the file
115-
* The service using the library sends requests to the server specified in the OpenAPI document
113+
- The actor knows (or successfully guesses) the location of a JSON or YAML file on the file system
114+
- The service using the library has privileges to read the file
115+
- The service using the library sends requests to the server specified in the OpenAPI document
116116

117117
You can prevent exploitation by hardening the environment in which the service is running:
118118

119-
* The service should run under its own dedicated user account
120-
* File system permissions should be configured so that the service cannot read any YAML or JSON files not owned by the service user
119+
- The service should run under its own dedicated user account
120+
- File system permissions should be configured so that the service cannot read any YAML or JSON files not owned by the service user
121121

122122
If you have any YAML or JSON files the service must have access to that may contain sensitive information, such as configuration file(s), you must take additional measures to prevent exploitation. A non-exhaustive list:
123123

124-
* You can implement your service so that it reads the configuration into memory at start time, then uses [setuid](https://nodejs.org/api/process.html#processsetuidid) and [setgid](https://nodejs.org/api/process.html#processsetgidid) to set the process' UID and GID to the ID of a user and ID of a group that has no access to the file on the filesystem
125-
* Do not store sensitive information, such as credentials, in the service configuration files
124+
- You can implement your service so that it reads the configuration into memory at start time, then uses [setuid](https://nodejs.org/api/process.html#processsetuidid) and [setgid](https://nodejs.org/api/process.html#processsetgidid) to set the process' UID and GID to the ID of a user and ID of a group that has no access to the file on the filesystem
125+
- Do not store sensitive information, such as credentials, in the service configuration files

_includes/stylesheets.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
<!-- {{ page.url }} -->
2-
<link rel="stylesheet" href="/css/style.css?v=3" media="screen" type="text/css">
3-
<link rel="stylesheet" href="/css/print.css" media="print" type="text/css">
2+
<link
3+
rel="stylesheet"
4+
href="/css/style.css?v=3"
5+
media="screen"
6+
type="text/css"
7+
/>
8+
<link rel="stylesheet" href="/css/print.css" media="print" type="text/css" />

0 commit comments

Comments
 (0)