Initial Commit
This commit is contained in:
commit
ea1a56a169
1507 changed files with 258442 additions and 0 deletions
6
.env
Normal file
6
.env
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
PORT=3000
|
||||||
|
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_USER=root
|
||||||
|
DB_PASSWORD=root
|
||||||
|
DB_NAME=cours_management
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
.env
|
||||||
|
/node_modules
|
||||||
33
app.js
Normal file
33
app.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
require('dotenv').config();
|
||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
const swaggerUi = require('swagger-ui-express');
|
||||||
|
const swaggerSpec = require('./swagger');
|
||||||
|
const db = require('./config/db');
|
||||||
|
|
||||||
|
// Middlewares
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
// Swagger
|
||||||
|
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
|
||||||
|
|
||||||
|
// Routes
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* tags:
|
||||||
|
* - name: Users
|
||||||
|
* description: User management
|
||||||
|
* /users:
|
||||||
|
* get:
|
||||||
|
* summary: Get all users
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: List of users
|
||||||
|
*/
|
||||||
|
app.use('/users', require('./routes/users'));
|
||||||
|
app.use('/cours', require('./routes/cours'));
|
||||||
|
app.use('/groups', require('./routes/groups'));
|
||||||
|
|
||||||
|
// Lancer serveur
|
||||||
|
const PORT = process.env.PORT || 3000;
|
||||||
|
app.listen(PORT, () => console.log(`API running on http://localhost:${PORT}`));
|
||||||
11
config/db.js
Normal file
11
config/db.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
const mysql = require('mysql2/promise');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const pool = mysql.createPool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
user: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
database: process.env.DB_NAME
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = pool;
|
||||||
29
controllers/coursController.js
Normal file
29
controllers/coursController.js
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
const db = require('../config/db');
|
||||||
|
|
||||||
|
exports.getAllCours = async (req, res) => {
|
||||||
|
const [rows] = await db.query('SELECT * FROM cours');
|
||||||
|
res.json(rows);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getCoursById = async (req, res) => {
|
||||||
|
const [rows] = await db.query('SELECT * FROM cours WHERE id = ?', [req.params.id]);
|
||||||
|
if (rows.length === 0) return res.status(404).json({ error: 'Cours not found' });
|
||||||
|
res.json(rows[0]);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.createCours = async (req, res) => {
|
||||||
|
const { name, description } = req.body;
|
||||||
|
await db.query('INSERT INTO cours (name, description) VALUES (?, ?)', [name, description]);
|
||||||
|
res.status(201).json({ message: 'Cours created' });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.updateCours = async (req, res) => {
|
||||||
|
const { name, description } = req.body;
|
||||||
|
await db.query('UPDATE cours SET name = ?, description = ? WHERE id = ?', [name, description, req.params.id]);
|
||||||
|
res.json({ message: 'Cours updated' });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.deleteCours = async (req, res) => {
|
||||||
|
await db.query('DELETE FROM cours WHERE id = ?', [req.params.id]);
|
||||||
|
res.status(204).send();
|
||||||
|
};
|
||||||
69
controllers/groupController.js
Normal file
69
controllers/groupController.js
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
const db = require('../config/db');
|
||||||
|
|
||||||
|
exports.getAllGroups = async (req, res) => {
|
||||||
|
const [rows] = await db.query('SELECT * FROM groups');
|
||||||
|
res.json(rows);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getGroupById = async (req, res) => {
|
||||||
|
const [rows] = await db.query('SELECT * FROM groups WHERE id = ?', [req.params.id]);
|
||||||
|
if (rows.length === 0) return res.status(404).json({ error: 'Group not found' });
|
||||||
|
res.json(rows[0]);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.createGroup = async (req, res) => {
|
||||||
|
const { name } = req.body;
|
||||||
|
await db.query('INSERT INTO groups (name) VALUES (?)', [name]);
|
||||||
|
res.status(201).json({ message: 'Group created' });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.updateGroup = async (req, res) => {
|
||||||
|
const { name } = req.body;
|
||||||
|
await db.query('UPDATE groups SET name = ? WHERE id = ?', [name, req.params.id]);
|
||||||
|
res.json({ message: 'Group updated' });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.deleteGroup = async (req, res) => {
|
||||||
|
await db.query('DELETE FROM groups WHERE id = ?', [req.params.id]);
|
||||||
|
res.status(204).send();
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getGroupUsers = async (req, res) => {
|
||||||
|
const [rows] = await db.query(`
|
||||||
|
SELECT u.* FROM users u
|
||||||
|
JOIN group_users gu ON gu.user_id = u.id
|
||||||
|
WHERE gu.group_id = ?
|
||||||
|
`, [req.params.id]);
|
||||||
|
res.json(rows);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getGroupCours = async (req, res) => {
|
||||||
|
const [rows] = await db.query(`
|
||||||
|
SELECT c.* FROM courses c
|
||||||
|
JOIN group_cours gc ON gc.cours_id = c.id
|
||||||
|
WHERE gc.group_id = ?
|
||||||
|
`, [req.params.id]);
|
||||||
|
res.json(rows);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.addUserToGroup = async (req, res) => {
|
||||||
|
const { userId } = req.body;
|
||||||
|
await db.query('INSERT IGNORE INTO group_users (group_id, user_id) VALUES (?, ?)', [req.params.id, userId]);
|
||||||
|
res.status(200).json({ message: 'User added to group' });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.addCoursToGroup = async (req, res) => {
|
||||||
|
const { coursId } = req.body;
|
||||||
|
await db.query('INSERT IGNORE INTO group_cours (group_id, cours_id) VALUES (?, ?)', [req.params.id, coursId]);
|
||||||
|
res.status(200).json({ message: 'Cours added to group' });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.removeUserFromGroup = async (req, res) => {
|
||||||
|
await db.query('DELETE FROM group_users WHERE group_id = ? AND user_id = ?', [req.params.id, req.params.userId]);
|
||||||
|
res.status(204).send();
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.removeCoursFromGroup = async (req, res) => {
|
||||||
|
await db.query('DELETE FROM group_courses WHERE group_id = ? AND course_id = ?', [req.params.id, req.params.courseId]);
|
||||||
|
res.status(204).send();
|
||||||
|
};
|
||||||
50
controllers/userController.js
Normal file
50
controllers/userController.js
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
const db = require('../config/db');
|
||||||
|
|
||||||
|
exports.getAllUsers = async (req, res) => {
|
||||||
|
const [rows] = await db.query('SELECT * FROM users');
|
||||||
|
res.json(rows);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getUserById = async (req, res) => {
|
||||||
|
const [rows] = await db.query('SELECT * FROM users WHERE id = ?', [req.params.id]);
|
||||||
|
if (rows.length === 0) return res.status(404).json({ error: 'User not found' });
|
||||||
|
res.json(rows[0]);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.createUser = async (req, res) => {
|
||||||
|
const { first_name, last_name, email, password_hash, role } = req.body;
|
||||||
|
await db.query('INSERT INTO users (first_name, last_name, email, password_hash, role) VALUES (?, ?, ?, ?, ?)',
|
||||||
|
[first_name, last_name, email, password_hash, role]);
|
||||||
|
res.status(201).json({ message: 'User created' });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.updateUser = async (req, res) => {
|
||||||
|
const { first_name, last_name, email, password_hash, role } = req.body;
|
||||||
|
await db.query('UPDATE users SET first_name = ?, last_name = ?, email = ?, password_hash = ?, role = ? WHERE id = ?',
|
||||||
|
[first_name, last_name, email, password_hash, role, req.params.id]);
|
||||||
|
res.json({ message: 'User updated' });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.deleteUser = async (req, res) => {
|
||||||
|
await db.query('DELETE FROM users WHERE id = ?', [req.params.id]);
|
||||||
|
res.status(204).send();
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getUserGroups = async (req, res) => {
|
||||||
|
const [rows] = await db.query(`
|
||||||
|
SELECT g.* FROM groups g
|
||||||
|
JOIN group_users gu ON gu.group_id = g.id
|
||||||
|
WHERE gu.user_id = ?
|
||||||
|
`, [req.params.id]);
|
||||||
|
res.json(rows);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getUserCours = async (req, res) => {
|
||||||
|
const [rows] = await db.query(`
|
||||||
|
SELECT DISTINCT c.* FROM courses c
|
||||||
|
JOIN group_cours gc ON gc.course_id = c.id
|
||||||
|
JOIN group_users gu ON gu.group_id = gc.group_id
|
||||||
|
WHERE gu.user_id = ?
|
||||||
|
`, [req.params.id]);
|
||||||
|
res.json(rows);
|
||||||
|
};
|
||||||
16
node_modules/.bin/js-yaml
generated
vendored
Normal file
16
node_modules/.bin/js-yaml
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../js-yaml/bin/js-yaml.js" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../js-yaml/bin/js-yaml.js" "$@"
|
||||||
|
fi
|
||||||
17
node_modules/.bin/js-yaml.cmd
generated
vendored
Normal file
17
node_modules/.bin/js-yaml.cmd
generated
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
@ECHO off
|
||||||
|
GOTO start
|
||||||
|
:find_dp0
|
||||||
|
SET dp0=%~dp0
|
||||||
|
EXIT /b
|
||||||
|
:start
|
||||||
|
SETLOCAL
|
||||||
|
CALL :find_dp0
|
||||||
|
|
||||||
|
IF EXIST "%dp0%\node.exe" (
|
||||||
|
SET "_prog=%dp0%\node.exe"
|
||||||
|
) ELSE (
|
||||||
|
SET "_prog=node"
|
||||||
|
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||||
|
)
|
||||||
|
|
||||||
|
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\js-yaml\bin\js-yaml.js" %*
|
||||||
28
node_modules/.bin/js-yaml.ps1
generated
vendored
Normal file
28
node_modules/.bin/js-yaml.ps1
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/usr/bin/env pwsh
|
||||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||||
|
|
||||||
|
$exe=""
|
||||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||||
|
# Fix case when both the Windows and Linux builds of Node
|
||||||
|
# are installed in the same directory
|
||||||
|
$exe=".exe"
|
||||||
|
}
|
||||||
|
$ret=0
|
||||||
|
if (Test-Path "$basedir/node$exe") {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "$basedir/node$exe" "$basedir/../js-yaml/bin/js-yaml.js" $args
|
||||||
|
} else {
|
||||||
|
& "$basedir/node$exe" "$basedir/../js-yaml/bin/js-yaml.js" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
} else {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "node$exe" "$basedir/../js-yaml/bin/js-yaml.js" $args
|
||||||
|
} else {
|
||||||
|
& "node$exe" "$basedir/../js-yaml/bin/js-yaml.js" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
}
|
||||||
|
exit $ret
|
||||||
16
node_modules/.bin/swagger-jsdoc
generated
vendored
Normal file
16
node_modules/.bin/swagger-jsdoc
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../swagger-jsdoc/bin/swagger-jsdoc.js" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../swagger-jsdoc/bin/swagger-jsdoc.js" "$@"
|
||||||
|
fi
|
||||||
17
node_modules/.bin/swagger-jsdoc.cmd
generated
vendored
Normal file
17
node_modules/.bin/swagger-jsdoc.cmd
generated
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
@ECHO off
|
||||||
|
GOTO start
|
||||||
|
:find_dp0
|
||||||
|
SET dp0=%~dp0
|
||||||
|
EXIT /b
|
||||||
|
:start
|
||||||
|
SETLOCAL
|
||||||
|
CALL :find_dp0
|
||||||
|
|
||||||
|
IF EXIST "%dp0%\node.exe" (
|
||||||
|
SET "_prog=%dp0%\node.exe"
|
||||||
|
) ELSE (
|
||||||
|
SET "_prog=node"
|
||||||
|
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||||
|
)
|
||||||
|
|
||||||
|
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\swagger-jsdoc\bin\swagger-jsdoc.js" %*
|
||||||
28
node_modules/.bin/swagger-jsdoc.ps1
generated
vendored
Normal file
28
node_modules/.bin/swagger-jsdoc.ps1
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/usr/bin/env pwsh
|
||||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||||
|
|
||||||
|
$exe=""
|
||||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||||
|
# Fix case when both the Windows and Linux builds of Node
|
||||||
|
# are installed in the same directory
|
||||||
|
$exe=".exe"
|
||||||
|
}
|
||||||
|
$ret=0
|
||||||
|
if (Test-Path "$basedir/node$exe") {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "$basedir/node$exe" "$basedir/../swagger-jsdoc/bin/swagger-jsdoc.js" $args
|
||||||
|
} else {
|
||||||
|
& "$basedir/node$exe" "$basedir/../swagger-jsdoc/bin/swagger-jsdoc.js" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
} else {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "node$exe" "$basedir/../swagger-jsdoc/bin/swagger-jsdoc.js" $args
|
||||||
|
} else {
|
||||||
|
& "node$exe" "$basedir/../swagger-jsdoc/bin/swagger-jsdoc.js" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
}
|
||||||
|
exit $ret
|
||||||
16
node_modules/.bin/z-schema
generated
vendored
Normal file
16
node_modules/.bin/z-schema
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../z-schema/bin/z-schema" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../z-schema/bin/z-schema" "$@"
|
||||||
|
fi
|
||||||
17
node_modules/.bin/z-schema.cmd
generated
vendored
Normal file
17
node_modules/.bin/z-schema.cmd
generated
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
@ECHO off
|
||||||
|
GOTO start
|
||||||
|
:find_dp0
|
||||||
|
SET dp0=%~dp0
|
||||||
|
EXIT /b
|
||||||
|
:start
|
||||||
|
SETLOCAL
|
||||||
|
CALL :find_dp0
|
||||||
|
|
||||||
|
IF EXIST "%dp0%\node.exe" (
|
||||||
|
SET "_prog=%dp0%\node.exe"
|
||||||
|
) ELSE (
|
||||||
|
SET "_prog=node"
|
||||||
|
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||||
|
)
|
||||||
|
|
||||||
|
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\z-schema\bin\z-schema" %*
|
||||||
28
node_modules/.bin/z-schema.ps1
generated
vendored
Normal file
28
node_modules/.bin/z-schema.ps1
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/usr/bin/env pwsh
|
||||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||||
|
|
||||||
|
$exe=""
|
||||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||||
|
# Fix case when both the Windows and Linux builds of Node
|
||||||
|
# are installed in the same directory
|
||||||
|
$exe=".exe"
|
||||||
|
}
|
||||||
|
$ret=0
|
||||||
|
if (Test-Path "$basedir/node$exe") {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "$basedir/node$exe" "$basedir/../z-schema/bin/z-schema" $args
|
||||||
|
} else {
|
||||||
|
& "$basedir/node$exe" "$basedir/../z-schema/bin/z-schema" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
} else {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "node$exe" "$basedir/../z-schema/bin/z-schema" $args
|
||||||
|
} else {
|
||||||
|
& "node$exe" "$basedir/../z-schema/bin/z-schema" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
}
|
||||||
|
exit $ret
|
||||||
1267
node_modules/.package-lock.json
generated
vendored
Normal file
1267
node_modules/.package-lock.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
21
node_modules/@apidevtools/json-schema-ref-parser/LICENSE
generated
vendored
Normal file
21
node_modules/@apidevtools/json-schema-ref-parser/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 James Messinger
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
162
node_modules/@apidevtools/json-schema-ref-parser/README.md
generated
vendored
Normal file
162
node_modules/@apidevtools/json-schema-ref-parser/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,162 @@
|
||||||
|
JSON Schema $Ref Parser
|
||||||
|
============================
|
||||||
|
#### Parse, Resolve, and Dereference JSON Schema $ref pointers
|
||||||
|
|
||||||
|
[](https://github.com/APIDevTools/json-schema-ref-parser/actions)
|
||||||
|
[](https://coveralls.io/github/APIDevTools/json-schema-ref-parser)
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/@apidevtools/json-schema-ref-parser)
|
||||||
|
[](https://david-dm.org/APIDevTools/json-schema-ref-parser)
|
||||||
|
[](LICENSE)
|
||||||
|
[](https://plant.treeware.earth/APIDevTools/json-schema-ref-parser)
|
||||||
|
|
||||||
|
|
||||||
|
[](https://github.com/APIDevTools/json-schema-ref-parser/actions)
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
"definitions": {
|
||||||
|
"person": {
|
||||||
|
// references an external file
|
||||||
|
"$ref": "schemas/people/Bruce-Wayne.json"
|
||||||
|
},
|
||||||
|
"place": {
|
||||||
|
// references a sub-schema in an external file
|
||||||
|
"$ref": "schemas/places.yaml#/definitions/Gotham-City"
|
||||||
|
},
|
||||||
|
"thing": {
|
||||||
|
// references a URL
|
||||||
|
"$ref": "http://wayne-enterprises.com/things/batmobile"
|
||||||
|
},
|
||||||
|
"color": {
|
||||||
|
// references a value in an external file via an internal reference
|
||||||
|
"$ref": "#/definitions/thing/properties/colors/black-as-the-night"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
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 JavaScript objects.
|
||||||
|
|
||||||
|
- Use **JSON** or **YAML** schemas — or even a mix of both!
|
||||||
|
- Supports `$ref` pointers to external files and URLs, as well as [custom sources](https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html) such as databases
|
||||||
|
- Can [bundle](https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#bundlepath-options-callback) multiple files into a single schema that only has _internal_ `$ref` pointers
|
||||||
|
- Can [dereference](https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#dereferencepath-options-callback) your schema, producing a plain-old JavaScript object that's easy to work with
|
||||||
|
- Supports [circular references](https://apitools.dev/json-schema-ref-parser/docs/#circular-refs), nested references, back-references, and cross-references between files
|
||||||
|
- Maintains object reference equality — `$ref` pointers to the same value always resolve to the same object instance
|
||||||
|
- Tested in Node v10, v12, & v14, and all major web browsers on Windows, Mac, and Linux
|
||||||
|
|
||||||
|
|
||||||
|
Example
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
$RefParser.dereference(mySchema, (err, schema) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// `schema` is just a normal JavaScript object that contains your entire JSON Schema,
|
||||||
|
// including referenced files, combined into a single object
|
||||||
|
console.log(schema.definitions.person.properties.firstName);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Or use `async`/`await` syntax instead. The following example is the same as above:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
try {
|
||||||
|
let schema = await $RefParser.dereference(mySchema);
|
||||||
|
console.log(schema.definitions.person.properties.firstName);
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For more detailed examples, please see the [API Documentation](https://apitools.dev/json-schema-ref-parser/docs/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
--------------------------
|
||||||
|
Install using [npm](https://docs.npmjs.com/about-npm/):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install @apidevtools/json-schema-ref-parser
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
--------------------------
|
||||||
|
When using JSON Schema $Ref Parser in Node.js apps, you'll probably want to use **CommonJS** syntax:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const $RefParser = require("@apidevtools/json-schema-ref-parser");
|
||||||
|
```
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import $RefParser from "@apidevtools/json-schema-ref-parser";
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
To use JSON Schema $Ref 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).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
API Documentation
|
||||||
|
--------------------------
|
||||||
|
Full API documentation is available [right here](https://apitools.dev/json-schema-ref-parser/docs/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
--------------------------
|
||||||
|
I welcome any contributions, enhancements, and 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>
|
||||||
|
`git clone https://github.com/APIDevTools/json-schema-ref-parser.git`
|
||||||
|
|
||||||
|
2. __Install dependencies__<br>
|
||||||
|
`npm install`
|
||||||
|
|
||||||
|
3. __Run the tests__<br>
|
||||||
|
`npm test`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
--------------------------
|
||||||
|
Thanks to these awesome companies for their support of Open Source developers ❤
|
||||||
|
|
||||||
|
[](https://stoplight.io/?utm_source=github&utm_medium=readme&utm_campaign=json_schema_ref_parser)
|
||||||
|
[](https://saucelabs.com)
|
||||||
|
[](https://coveralls.io)
|
||||||
261
node_modules/@apidevtools/json-schema-ref-parser/lib/bundle.js
generated
vendored
Normal file
261
node_modules/@apidevtools/json-schema-ref-parser/lib/bundle.js
generated
vendored
Normal file
|
|
@ -0,0 +1,261 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const $Ref = require("./ref");
|
||||||
|
const Pointer = require("./pointer");
|
||||||
|
const url = require("./util/url");
|
||||||
|
|
||||||
|
module.exports = bundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bundles all external JSON references into the main JSON schema, thus resulting in a schema that
|
||||||
|
* only has *internal* references, not any *external* references.
|
||||||
|
* This method mutates the JSON schema object, adding new references and re-mapping existing ones.
|
||||||
|
*
|
||||||
|
* @param {$RefParser} parser
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*/
|
||||||
|
function bundle (parser, options) {
|
||||||
|
// console.log('Bundling $ref pointers in %s', parser.$refs._root$Ref.path);
|
||||||
|
|
||||||
|
// Build an inventory of all $ref pointers in the JSON Schema
|
||||||
|
let inventory = [];
|
||||||
|
crawl(parser, "schema", parser.$refs._root$Ref.path + "#", "#", 0, inventory, parser.$refs, options);
|
||||||
|
|
||||||
|
// Remap all $ref pointers
|
||||||
|
remap(inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively crawls the given value, and inventories all JSON references.
|
||||||
|
*
|
||||||
|
* @param {object} parent - The object containing the value to crawl. If the value is not an object or array, it will be ignored.
|
||||||
|
* @param {string} key - The property key of `parent` to be crawled
|
||||||
|
* @param {string} path - The full path of the property being crawled, possibly with a JSON Pointer in the hash
|
||||||
|
* @param {string} pathFromRoot - The path of the property being crawled, from the schema root
|
||||||
|
* @param {object[]} inventory - An array of already-inventoried $ref pointers
|
||||||
|
* @param {$Refs} $refs
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*/
|
||||||
|
function crawl (parent, key, path, pathFromRoot, indirections, inventory, $refs, options) {
|
||||||
|
let obj = key === null ? parent : parent[key];
|
||||||
|
|
||||||
|
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
|
||||||
|
if ($Ref.isAllowed$Ref(obj)) {
|
||||||
|
inventory$Ref(parent, key, path, pathFromRoot, indirections, inventory, $refs, options);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Crawl the object in a specific order that's optimized for bundling.
|
||||||
|
// This is important because it determines how `pathFromRoot` gets built,
|
||||||
|
// which later determines which keys get dereferenced and which ones get remapped
|
||||||
|
let keys = Object.keys(obj)
|
||||||
|
.sort((a, b) => {
|
||||||
|
// Most people will expect references to be bundled into the the "definitions" property,
|
||||||
|
// so we always crawl that property first, if it exists.
|
||||||
|
if (a === "definitions") {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (b === "definitions") {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Otherwise, crawl the keys based on their length.
|
||||||
|
// This produces the shortest possible bundled references
|
||||||
|
return a.length - b.length;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-shadow
|
||||||
|
for (let key of keys) {
|
||||||
|
let keyPath = Pointer.join(path, key);
|
||||||
|
let keyPathFromRoot = Pointer.join(pathFromRoot, key);
|
||||||
|
let value = obj[key];
|
||||||
|
|
||||||
|
if ($Ref.isAllowed$Ref(value)) {
|
||||||
|
inventory$Ref(obj, key, path, keyPathFromRoot, indirections, inventory, $refs, options);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
crawl(obj, key, keyPath, keyPathFromRoot, indirections, inventory, $refs, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inventories the given JSON Reference (i.e. records detailed information about it so we can
|
||||||
|
* optimize all $refs in the schema), and then crawls the resolved value.
|
||||||
|
*
|
||||||
|
* @param {object} $refParent - The object that contains a JSON Reference as one of its keys
|
||||||
|
* @param {string} $refKey - The key in `$refParent` that is a JSON Reference
|
||||||
|
* @param {string} path - The full path of the JSON Reference at `$refKey`, possibly with a JSON Pointer in the hash
|
||||||
|
* @param {string} pathFromRoot - The path of the JSON Reference at `$refKey`, from the schema root
|
||||||
|
* @param {object[]} inventory - An array of already-inventoried $ref pointers
|
||||||
|
* @param {$Refs} $refs
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*/
|
||||||
|
function inventory$Ref ($refParent, $refKey, path, pathFromRoot, indirections, inventory, $refs, options) {
|
||||||
|
let $ref = $refKey === null ? $refParent : $refParent[$refKey];
|
||||||
|
let $refPath = url.resolve(path, $ref.$ref);
|
||||||
|
let pointer = $refs._resolve($refPath, pathFromRoot, options);
|
||||||
|
if (pointer === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let depth = Pointer.parse(pathFromRoot).length;
|
||||||
|
let file = url.stripHash(pointer.path);
|
||||||
|
let hash = url.getHash(pointer.path);
|
||||||
|
let external = file !== $refs._root$Ref.path;
|
||||||
|
let extended = $Ref.isExtended$Ref($ref);
|
||||||
|
indirections += pointer.indirections;
|
||||||
|
|
||||||
|
let existingEntry = findInInventory(inventory, $refParent, $refKey);
|
||||||
|
if (existingEntry) {
|
||||||
|
// This $Ref has already been inventoried, so we don't need to process it again
|
||||||
|
if (depth < existingEntry.depth || indirections < existingEntry.indirections) {
|
||||||
|
removeFromInventory(inventory, existingEntry);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory.push({
|
||||||
|
$ref, // The JSON Reference (e.g. {$ref: string})
|
||||||
|
parent: $refParent, // The object that contains this $ref pointer
|
||||||
|
key: $refKey, // The key in `parent` that is the $ref pointer
|
||||||
|
pathFromRoot, // The path to the $ref pointer, from the JSON Schema root
|
||||||
|
depth, // How far from the JSON Schema root is this $ref pointer?
|
||||||
|
file, // The file that the $ref pointer resolves to
|
||||||
|
hash, // The hash within `file` that the $ref pointer resolves to
|
||||||
|
value: pointer.value, // The resolved value of the $ref pointer
|
||||||
|
circular: pointer.circular, // Is this $ref pointer DIRECTLY circular? (i.e. it references itself)
|
||||||
|
extended, // Does this $ref extend its resolved value? (i.e. it has extra properties, in addition to "$ref")
|
||||||
|
external, // Does this $ref pointer point to a file other than the main JSON Schema file?
|
||||||
|
indirections, // The number of indirect references that were traversed to resolve the value
|
||||||
|
});
|
||||||
|
|
||||||
|
// Recursively crawl the resolved value
|
||||||
|
if (!existingEntry) {
|
||||||
|
crawl(pointer.value, null, pointer.path, pathFromRoot, indirections + 1, inventory, $refs, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-maps every $ref pointer, so that they're all relative to the root of the JSON Schema.
|
||||||
|
* Each referenced value is dereferenced EXACTLY ONCE. All subsequent references to the same
|
||||||
|
* value are re-mapped to point to the first reference.
|
||||||
|
*
|
||||||
|
* @example:
|
||||||
|
* {
|
||||||
|
* first: { $ref: somefile.json#/some/part },
|
||||||
|
* second: { $ref: somefile.json#/another/part },
|
||||||
|
* third: { $ref: somefile.json },
|
||||||
|
* fourth: { $ref: somefile.json#/some/part/sub/part }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* In this example, there are four references to the same file, but since the third reference points
|
||||||
|
* to the ENTIRE file, that's the only one we need to dereference. The other three can just be
|
||||||
|
* remapped to point inside the third one.
|
||||||
|
*
|
||||||
|
* On the other hand, if the third reference DIDN'T exist, then the first and second would both need
|
||||||
|
* to be dereferenced, since they point to different parts of the file. The fourth reference does NOT
|
||||||
|
* need to be dereferenced, because it can be remapped to point inside the first one.
|
||||||
|
*
|
||||||
|
* @param {object[]} inventory
|
||||||
|
*/
|
||||||
|
function remap (inventory) {
|
||||||
|
// Group & sort all the $ref pointers, so they're in the order that we need to dereference/remap them
|
||||||
|
inventory.sort((a, b) => {
|
||||||
|
if (a.file !== b.file) {
|
||||||
|
// Group all the $refs that point to the same file
|
||||||
|
return a.file < b.file ? -1 : +1;
|
||||||
|
}
|
||||||
|
else if (a.hash !== b.hash) {
|
||||||
|
// Group all the $refs that point to the same part of the file
|
||||||
|
return a.hash < b.hash ? -1 : +1;
|
||||||
|
}
|
||||||
|
else if (a.circular !== b.circular) {
|
||||||
|
// If the $ref points to itself, then sort it higher than other $refs that point to this $ref
|
||||||
|
return a.circular ? -1 : +1;
|
||||||
|
}
|
||||||
|
else if (a.extended !== b.extended) {
|
||||||
|
// If the $ref extends the resolved value, then sort it lower than other $refs that don't extend the value
|
||||||
|
return a.extended ? +1 : -1;
|
||||||
|
}
|
||||||
|
else if (a.indirections !== b.indirections) {
|
||||||
|
// Sort direct references higher than indirect references
|
||||||
|
return a.indirections - b.indirections;
|
||||||
|
}
|
||||||
|
else if (a.depth !== b.depth) {
|
||||||
|
// Sort $refs by how close they are to the JSON Schema root
|
||||||
|
return a.depth - b.depth;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Determine how far each $ref is from the "definitions" property.
|
||||||
|
// Most people will expect references to be bundled into the the "definitions" property if possible.
|
||||||
|
let aDefinitionsIndex = a.pathFromRoot.lastIndexOf("/definitions");
|
||||||
|
let bDefinitionsIndex = b.pathFromRoot.lastIndexOf("/definitions");
|
||||||
|
|
||||||
|
if (aDefinitionsIndex !== bDefinitionsIndex) {
|
||||||
|
// Give higher priority to the $ref that's closer to the "definitions" property
|
||||||
|
return bDefinitionsIndex - aDefinitionsIndex;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// All else is equal, so use the shorter path, which will produce the shortest possible reference
|
||||||
|
return a.pathFromRoot.length - b.pathFromRoot.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let file, hash, pathFromRoot;
|
||||||
|
for (let entry of inventory) {
|
||||||
|
// console.log('Re-mapping $ref pointer "%s" at %s', entry.$ref.$ref, entry.pathFromRoot);
|
||||||
|
|
||||||
|
if (!entry.external) {
|
||||||
|
// This $ref already resolves to the main JSON Schema file
|
||||||
|
entry.$ref.$ref = entry.hash;
|
||||||
|
}
|
||||||
|
else if (entry.file === file && entry.hash === hash) {
|
||||||
|
// This $ref points to the same value as the prevous $ref, so remap it to the same path
|
||||||
|
entry.$ref.$ref = pathFromRoot;
|
||||||
|
}
|
||||||
|
else if (entry.file === file && entry.hash.indexOf(hash + "/") === 0) {
|
||||||
|
// This $ref points to a sub-value of the prevous $ref, so remap it beneath that path
|
||||||
|
entry.$ref.$ref = Pointer.join(pathFromRoot, Pointer.parse(entry.hash.replace(hash, "#")));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// We've moved to a new file or new hash
|
||||||
|
file = entry.file;
|
||||||
|
hash = entry.hash;
|
||||||
|
pathFromRoot = entry.pathFromRoot;
|
||||||
|
|
||||||
|
// This is the first $ref to point to this value, so dereference the value.
|
||||||
|
// Any other $refs that point to the same value will point to this $ref instead
|
||||||
|
entry.$ref = entry.parent[entry.key] = $Ref.dereference(entry.$ref, entry.value);
|
||||||
|
|
||||||
|
if (entry.circular) {
|
||||||
|
// This $ref points to itself
|
||||||
|
entry.$ref.$ref = entry.pathFromRoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(' new value: %s', (entry.$ref && entry.$ref.$ref) ? entry.$ref.$ref : '[object Object]');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
function findInInventory (inventory, $refParent, $refKey) {
|
||||||
|
for (let i = 0; i < inventory.length; i++) {
|
||||||
|
let existingEntry = inventory[i];
|
||||||
|
if (existingEntry.parent === $refParent && existingEntry.key === $refKey) {
|
||||||
|
return existingEntry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeFromInventory (inventory, entry) {
|
||||||
|
let index = inventory.indexOf(entry);
|
||||||
|
inventory.splice(index, 1);
|
||||||
|
}
|
||||||
205
node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js
generated
vendored
Normal file
205
node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js
generated
vendored
Normal file
|
|
@ -0,0 +1,205 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const $Ref = require("./ref");
|
||||||
|
const Pointer = require("./pointer");
|
||||||
|
const { ono } = require("@jsdevtools/ono");
|
||||||
|
const url = require("./util/url");
|
||||||
|
|
||||||
|
module.exports = dereference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crawls the JSON schema, finds all JSON references, and dereferences them.
|
||||||
|
* This method mutates the JSON schema object, replacing JSON references with their resolved value.
|
||||||
|
*
|
||||||
|
* @param {$RefParser} parser
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*/
|
||||||
|
function dereference (parser, options) {
|
||||||
|
// console.log('Dereferencing $ref pointers in %s', parser.$refs._root$Ref.path);
|
||||||
|
let dereferenced = crawl(parser.schema, parser.$refs._root$Ref.path, "#", new Set(), new Set(), new Map(), parser.$refs, options);
|
||||||
|
parser.$refs.circular = dereferenced.circular;
|
||||||
|
parser.schema = dereferenced.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively crawls the given value, and dereferences any JSON references.
|
||||||
|
*
|
||||||
|
* @param {*} obj - The value to crawl. If it's not an object or array, it will be ignored.
|
||||||
|
* @param {string} path - The full path of `obj`, possibly with a JSON Pointer in the hash
|
||||||
|
* @param {string} pathFromRoot - The path of `obj` from the schema root
|
||||||
|
* @param {Set<object>} parents - An array of the parent objects that have already been dereferenced
|
||||||
|
* @param {Set<object>} processedObjects - An array of all the objects that have already been processed
|
||||||
|
* @param {Map<string,object>} dereferencedCache - An map of all the dereferenced objects
|
||||||
|
* @param {$Refs} $refs
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @returns {{value: object, circular: boolean}}
|
||||||
|
*/
|
||||||
|
function crawl (obj, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options) {
|
||||||
|
let dereferenced;
|
||||||
|
let result = {
|
||||||
|
value: obj,
|
||||||
|
circular: false
|
||||||
|
};
|
||||||
|
|
||||||
|
let isExcludedPath = options.dereference.excludedPathMatcher;
|
||||||
|
|
||||||
|
if (options.dereference.circular === "ignore" || !processedObjects.has(obj)) {
|
||||||
|
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !isExcludedPath(pathFromRoot)) {
|
||||||
|
parents.add(obj);
|
||||||
|
processedObjects.add(obj);
|
||||||
|
|
||||||
|
if ($Ref.isAllowed$Ref(obj, options)) {
|
||||||
|
dereferenced = dereference$Ref(obj, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options);
|
||||||
|
result.circular = dereferenced.circular;
|
||||||
|
result.value = dereferenced.value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (const key of Object.keys(obj)) {
|
||||||
|
let keyPath = Pointer.join(path, key);
|
||||||
|
let keyPathFromRoot = Pointer.join(pathFromRoot, key);
|
||||||
|
|
||||||
|
if (isExcludedPath(keyPathFromRoot)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let value = obj[key];
|
||||||
|
let circular = false;
|
||||||
|
|
||||||
|
if ($Ref.isAllowed$Ref(value, options)) {
|
||||||
|
dereferenced = dereference$Ref(value, keyPath, keyPathFromRoot, parents, processedObjects, dereferencedCache, $refs, options);
|
||||||
|
circular = dereferenced.circular;
|
||||||
|
// Avoid pointless mutations; breaks frozen objects to no profit
|
||||||
|
if (obj[key] !== dereferenced.value) {
|
||||||
|
obj[key] = dereferenced.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!parents.has(value)) {
|
||||||
|
dereferenced = crawl(value, keyPath, keyPathFromRoot, parents, processedObjects, dereferencedCache, $refs, options);
|
||||||
|
circular = dereferenced.circular;
|
||||||
|
// Avoid pointless mutations; breaks frozen objects to no profit
|
||||||
|
if (obj[key] !== dereferenced.value) {
|
||||||
|
obj[key] = dereferenced.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
circular = foundCircularReference(keyPath, $refs, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the "isCircular" flag if this or any other property is circular
|
||||||
|
result.circular = result.circular || circular;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parents.delete(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dereferences the given JSON Reference, and then crawls the resulting value.
|
||||||
|
*
|
||||||
|
* @param {{$ref: string}} $ref - The JSON Reference to resolve
|
||||||
|
* @param {string} path - The full path of `$ref`, possibly with a JSON Pointer in the hash
|
||||||
|
* @param {string} pathFromRoot - The path of `$ref` from the schema root
|
||||||
|
* @param {Set<object>} parents - An array of the parent objects that have already been dereferenced
|
||||||
|
* @param {Set<object>} processedObjects - An array of all the objects that have already been dereferenced
|
||||||
|
* @param {Map<string,object>} dereferencedCache - An map of all the dereferenced objects
|
||||||
|
* @param {$Refs} $refs
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @returns {{value: object, circular: boolean}}
|
||||||
|
*/
|
||||||
|
function dereference$Ref ($ref, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options) {
|
||||||
|
// console.log('Dereferencing $ref pointer "%s" at %s', $ref.$ref, path);
|
||||||
|
|
||||||
|
let $refPath = url.resolve(path, $ref.$ref);
|
||||||
|
|
||||||
|
const cache = dereferencedCache.get($refPath);
|
||||||
|
if (cache) {
|
||||||
|
const refKeys = Object.keys($ref);
|
||||||
|
if (refKeys.length > 1) {
|
||||||
|
const extraKeys = {};
|
||||||
|
for (let key of refKeys) {
|
||||||
|
if (key !== "$ref" && !(key in cache.value)) {
|
||||||
|
extraKeys[key] = $ref[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
circular: cache.circular,
|
||||||
|
value: Object.assign({}, cache.value, extraKeys),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let pointer = $refs._resolve($refPath, path, options);
|
||||||
|
|
||||||
|
if (pointer === null) {
|
||||||
|
return {
|
||||||
|
circular: false,
|
||||||
|
value: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for circular references
|
||||||
|
let directCircular = pointer.circular;
|
||||||
|
let circular = directCircular || parents.has(pointer.value);
|
||||||
|
circular && foundCircularReference(path, $refs, options);
|
||||||
|
|
||||||
|
// Dereference the JSON reference
|
||||||
|
let dereferencedValue = $Ref.dereference($ref, pointer.value);
|
||||||
|
|
||||||
|
// Crawl the dereferenced value (unless it's circular)
|
||||||
|
if (!circular) {
|
||||||
|
// Determine if the dereferenced value is circular
|
||||||
|
let dereferenced = crawl(dereferencedValue, pointer.path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options);
|
||||||
|
circular = dereferenced.circular;
|
||||||
|
dereferencedValue = dereferenced.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (circular && !directCircular && options.dereference.circular === "ignore") {
|
||||||
|
// The user has chosen to "ignore" circular references, so don't change the value
|
||||||
|
dereferencedValue = $ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (directCircular) {
|
||||||
|
// The pointer is a DIRECT circular reference (i.e. it references itself).
|
||||||
|
// So replace the $ref path with the absolute path from the JSON Schema root
|
||||||
|
dereferencedValue.$ref = pathFromRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const dereferencedObject = {
|
||||||
|
circular,
|
||||||
|
value: dereferencedValue
|
||||||
|
};
|
||||||
|
|
||||||
|
// only cache if no extra properties than $ref
|
||||||
|
if (Object.keys($ref).length === 1) {
|
||||||
|
dereferencedCache.set($refPath, dereferencedObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dereferencedObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a circular reference is found.
|
||||||
|
* It sets the {@link $Refs#circular} flag, and throws an error if options.dereference.circular is false.
|
||||||
|
*
|
||||||
|
* @param {string} keyPath - The JSON Reference path of the circular reference
|
||||||
|
* @param {$Refs} $refs
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @returns {boolean} - always returns true, to indicate that a circular reference was found
|
||||||
|
*/
|
||||||
|
function foundCircularReference (keyPath, $refs, options) {
|
||||||
|
$refs.circular = true;
|
||||||
|
if (!options.dereference.circular) {
|
||||||
|
throw ono.reference(`Circular $ref pointer found at ${keyPath}`);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
487
node_modules/@apidevtools/json-schema-ref-parser/lib/index.d.ts
generated
vendored
Normal file
487
node_modules/@apidevtools/json-schema-ref-parser/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,487 @@
|
||||||
|
import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type, JSONSchema7, JSONSchema7Type } from "json-schema";
|
||||||
|
|
||||||
|
export = $RefParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the default export of JSON Schema $Ref Parser. You can creates instances of this class using new $RefParser(), or you can just call its static methods.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html
|
||||||
|
*/
|
||||||
|
declare class $RefParser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `schema` property is the parsed/bundled/dereferenced JSON Schema object. This is the same value that is passed to the callback function (or Promise) when calling the parse, bundle, or dereference methods.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#schema
|
||||||
|
*/
|
||||||
|
public schema: $RefParser.JSONSchema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The $refs property is a `$Refs` object, which lets you access all of the externally-referenced files in the schema, as well as easily get and set specific values in the schema using JSON pointers.
|
||||||
|
*
|
||||||
|
* This is the same value that is passed to the callback function (or Promise) when calling the `resolve` method.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#refs
|
||||||
|
*/
|
||||||
|
public $refs: $RefParser.$Refs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
|
||||||
|
*
|
||||||
|
* The dereference method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of circular references, so be careful if you intend to serialize the schema using `JSON.stringify()`. Consider using the bundle method instead, which does not create circular references.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#dereferenceschema-options-callback
|
||||||
|
*
|
||||||
|
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the dereferenced schema object
|
||||||
|
*/
|
||||||
|
public dereference(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public dereference(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
||||||
|
public dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
public dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
|
||||||
|
*
|
||||||
|
* The dereference method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of circular references, so be careful if you intend to serialize the schema using `JSON.stringify()`. Consider using the bundle method instead, which does not create circular references.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#dereferenceschema-options-callback
|
||||||
|
*
|
||||||
|
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the dereferenced schema object
|
||||||
|
*/
|
||||||
|
public static dereference(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public static dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public static dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public static dereference(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
||||||
|
public static dereference(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
public static dereference(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bundles all referenced files/URLs into a single schema that only has internal `$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
|
||||||
|
*
|
||||||
|
* This also eliminates the risk of circular references, so the schema can be safely serialized using `JSON.stringify()`.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#bundleschema-options-callback
|
||||||
|
*
|
||||||
|
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the bundled schema object
|
||||||
|
*/
|
||||||
|
public bundle(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public bundle(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
||||||
|
public bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
public bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bundles all referenced files/URLs into a single schema that only has internal `$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
|
||||||
|
*
|
||||||
|
* This also eliminates the risk of circular references, so the schema can be safely serialized using `JSON.stringify()`.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#bundleschema-options-callback
|
||||||
|
*
|
||||||
|
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the bundled schema object
|
||||||
|
*/
|
||||||
|
public static bundle(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public static bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public static bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public static bundle(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
||||||
|
public static bundle(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
public static bundle(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
||||||
|
*
|
||||||
|
* Parses the given JSON Schema file (in JSON or YAML format), and returns it as a JavaScript object. This method `does not` resolve `$ref` pointers or dereference anything. It simply parses one file and returns it.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#parseschema-options-callback
|
||||||
|
*
|
||||||
|
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. The path can be absolute or relative. In Node, the path is relative to `process.cwd()`. In the browser, it's relative to the URL of the page.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the parsed schema object, or an error
|
||||||
|
*/
|
||||||
|
public parse(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public parse(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
||||||
|
public parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
public parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
||||||
|
*
|
||||||
|
* Parses the given JSON Schema file (in JSON or YAML format), and returns it as a JavaScript object. This method `does not` resolve `$ref` pointers or dereference anything. It simply parses one file and returns it.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#parseschema-options-callback
|
||||||
|
*
|
||||||
|
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. The path can be absolute or relative. In Node, the path is relative to `process.cwd()`. In the browser, it's relative to the URL of the page.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the parsed schema object, or an error
|
||||||
|
*/
|
||||||
|
public static parse(schema: string | $RefParser.JSONSchema, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public static parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public static parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.SchemaCallback): void;
|
||||||
|
public static parse(schema: string | $RefParser.JSONSchema): Promise<$RefParser.JSONSchema>;
|
||||||
|
public static parse(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
public static parse(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.JSONSchema>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
||||||
|
*
|
||||||
|
* Resolves all JSON references (`$ref` pointers) in the given JSON Schema file. If it references any other files/URLs, then they will be downloaded and resolved as well. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#resolveschema-options-callback
|
||||||
|
*
|
||||||
|
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
||||||
|
*/
|
||||||
|
public resolve(schema: string | $RefParser.JSONSchema, callback: $RefParser.$RefsCallback): void;
|
||||||
|
public resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
||||||
|
public resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
||||||
|
public resolve(schema: string | $RefParser.JSONSchema): Promise<$RefParser.$Refs>;
|
||||||
|
public resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
||||||
|
public resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
||||||
|
*
|
||||||
|
* Resolves all JSON references (`$ref` pointers) in the given JSON Schema file. If it references any other files/URLs, then they will be downloaded and resolved as well. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html#resolveschema-options-callback
|
||||||
|
*
|
||||||
|
* @param schema A JSON Schema object, or the file path or URL of a JSON Schema file. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
||||||
|
*/
|
||||||
|
public static resolve(schema: string | $RefParser.JSONSchema, callback: $RefParser.$RefsCallback): void;
|
||||||
|
public static resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
||||||
|
public static resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options, callback: $RefParser.$RefsCallback): void;
|
||||||
|
public static resolve(schema: string | $RefParser.JSONSchema): Promise<$RefParser.$Refs>;
|
||||||
|
public static resolve(schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
||||||
|
public static resolve(baseUrl: string, schema: string | $RefParser.JSONSchema, options: $RefParser.Options): Promise<$RefParser.$Refs>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-redeclare
|
||||||
|
declare namespace $RefParser {
|
||||||
|
|
||||||
|
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
|
||||||
|
export type SchemaCallback = (err: Error | null, schema?: JSONSchema) => any;
|
||||||
|
export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/options.html
|
||||||
|
*/
|
||||||
|
export interface Options {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `parse` options determine how different types of files will be parsed.
|
||||||
|
*
|
||||||
|
* JSON Schema `$Ref` Parser comes with built-in JSON, YAML, plain-text, and binary parsers, any of which you can configure or disable. You can also add your own custom parsers if you want.
|
||||||
|
*/
|
||||||
|
parse?: {
|
||||||
|
json?: ParserOptions | boolean;
|
||||||
|
yaml?: ParserOptions | boolean;
|
||||||
|
text?: (ParserOptions & { encoding?: string }) | boolean;
|
||||||
|
[key: string]: ParserOptions | boolean | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `resolve` options control how JSON Schema $Ref Parser will resolve file paths and URLs, and how those files will be read/downloaded.
|
||||||
|
*
|
||||||
|
* JSON Schema `$Ref` Parser comes with built-in support for HTTP and HTTPS, as well as support for local files (when running in Node.js). You can configure or disable either of these built-in resolvers. You can also add your own custom resolvers if you want.
|
||||||
|
*/
|
||||||
|
resolve?: {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether external $ref pointers will be resolved. If this option is disabled, then external `$ref` pointers will simply be ignored.
|
||||||
|
*/
|
||||||
|
external?: boolean;
|
||||||
|
file?: Partial<ResolverOptions> | boolean;
|
||||||
|
http?: HTTPResolverOptions | boolean;
|
||||||
|
} & {
|
||||||
|
[key: string]: Partial<ResolverOptions> | HTTPResolverOptions | boolean | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, JSON Schema $Ref Parser throws the first error it encounters. Setting `continueOnError` to `true`
|
||||||
|
* causes it to keep processing as much as possible and then throw a single error that contains all errors
|
||||||
|
* that were encountered.
|
||||||
|
*/
|
||||||
|
continueOnError?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `dereference` options control how JSON Schema `$Ref` Parser will dereference `$ref` pointers within the JSON schema.
|
||||||
|
*/
|
||||||
|
dereference?: {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether circular `$ref` pointers are handled.
|
||||||
|
*
|
||||||
|
* If set to `false`, then a `ReferenceError` will be thrown if the schema contains any circular references.
|
||||||
|
*
|
||||||
|
* If set to `"ignore"`, then circular references will simply be ignored. No error will be thrown, but the `$Refs.circular` property will still be set to `true`.
|
||||||
|
*/
|
||||||
|
circular?: boolean | "ignore";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function, called for each path, which can return true to stop this path and all
|
||||||
|
* subpaths from being dereferenced further. This is useful in schemas where some
|
||||||
|
* subpaths contain literal $ref keys that should not be dereferenced.
|
||||||
|
*/
|
||||||
|
excludedPathMatcher?(path: string): boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HTTPResolverOptions extends Partial<ResolverOptions> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can specify any HTTP headers that should be sent when downloading files. For example, some servers may require you to set the `Accept` or `Referrer` header.
|
||||||
|
*/
|
||||||
|
headers?: object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount of time (in milliseconds) to wait for a response from the server when downloading files. The default is 5 seconds.
|
||||||
|
*/
|
||||||
|
timeout?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum number of HTTP redirects to follow per file. The default is 5. To disable automatic following of redirects, set this to zero.
|
||||||
|
*/
|
||||||
|
redirects?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this to `true` if you're downloading files from a CORS-enabled server that requires authentication
|
||||||
|
*/
|
||||||
|
withCredentials?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON Schema `$Ref` Parser comes with built-in resolvers for HTTP and HTTPS URLs, as well as local filesystem paths (when running in Node.js). You can add your own custom resolvers to support additional protocols, or even replace any of the built-in resolvers with your own custom implementation.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html
|
||||||
|
*/
|
||||||
|
export interface ResolverOptions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All resolvers have an order property, even the built-in resolvers. If you don't specify an order property, then your resolver will run last. Specifying `order: 1`, like we did in this example, will make your resolver run first. Or you can squeeze your resolver in-between some of the built-in resolvers. For example, `order: 101` would make it run after the file resolver, but before the HTTP resolver. You can see the order of all the built-in resolvers by looking at their source code.
|
||||||
|
*
|
||||||
|
* The order property and canRead property are related to each other. For each file that JSON Schema $Ref Parser needs to resolve, it first determines which resolvers can read that file by checking their canRead property. If only one resolver matches a file, then only that one resolver is called, regardless of its order. If multiple resolvers match a file, then those resolvers are tried in order until one of them successfully reads the file. Once a resolver successfully reads the file, the rest of the resolvers are skipped.
|
||||||
|
*/
|
||||||
|
order?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `canRead` property tells JSON Schema `$Ref` Parser what kind of files your resolver can read. In this example, we've simply specified a regular expression that matches "mogodb://" URLs, but we could have used a simple boolean, or even a function with custom logic to determine which files to resolve. Here are examples of each approach:
|
||||||
|
*/
|
||||||
|
canRead: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is where the real work of a resolver happens. The `read` method accepts the same file info object as the `canRead` function, but rather than returning a boolean value, the `read` method should return the contents of the file. The file contents should be returned in as raw a form as possible, such as a string or a byte array. Any further parsing or processing should be done by parsers.
|
||||||
|
*
|
||||||
|
* Unlike the `canRead` function, the `read` method can also be asynchronous. This might be important if your resolver needs to read data from a database or some other external source. You can return your asynchronous value using either an ES6 Promise or a Node.js-style error-first callback. Of course, if your resolver has the ability to return its data synchronously, then that's fine too. Here are examples of all three approaches:
|
||||||
|
*/
|
||||||
|
read(
|
||||||
|
file: FileInfo,
|
||||||
|
callback?: (error: Error | null, data: string | null) => any
|
||||||
|
): string | Buffer | JSONSchema | Promise<string | Buffer | JSONSchema>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ParserOptions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parsers run in a specific order, relative to other parsers. For example, a parser with `order: 5` will run before a parser with `order: 10`. If a parser is unable to successfully parse a file, then the next parser is tried, until one succeeds or they all fail.
|
||||||
|
*
|
||||||
|
* You can change the order in which parsers run, which is useful if you know that most of your referenced files will be a certain type, or if you add your own custom parser that you want to run first.
|
||||||
|
*/
|
||||||
|
order?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All of the built-in parsers allow empty files by default. The JSON and YAML parsers will parse empty files as `undefined`. The text parser will parse empty files as an empty string. The binary parser will parse empty files as an empty byte array.
|
||||||
|
*
|
||||||
|
* You can set `allowEmpty: false` on any parser, which will cause an error to be thrown if a file empty.
|
||||||
|
*/
|
||||||
|
allowEmpty?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines which parsers will be used for which files.
|
||||||
|
*
|
||||||
|
* A regular expression can be used to match files by their full path. A string (or array of strings) can be used to match files by their file extension. Or a function can be used to perform more complex matching logic. See the custom parser docs for details.
|
||||||
|
*/
|
||||||
|
canParse?: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is where the real work of a parser happens. The `parse` method accepts the same file info object as the `canParse` function, but rather than returning a boolean value, the `parse` method should return a JavaScript representation of the file contents. For our CSV parser, that is a two-dimensional array of lines and values. For your parser, it might be an object, a string, a custom class, or anything else.
|
||||||
|
*
|
||||||
|
* Unlike the `canParse` function, the `parse` method can also be asynchronous. This might be important if your parser needs to retrieve data from a database or if it relies on an external HTTP service to return the parsed value. You can return your asynchronous value via a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or a Node.js-style error-first callback. Here are examples of both approaches:
|
||||||
|
*/
|
||||||
|
parse(
|
||||||
|
file: FileInfo,
|
||||||
|
callback?: (error: Error | null, data: string | null) => any
|
||||||
|
): unknown | Promise<unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON Schema `$Ref` Parser supports plug-ins, such as resolvers and parsers. These plug-ins can have methods such as `canRead()`, `read()`, `canParse()`, and `parse()`. All of these methods accept the same object as their parameter: an object containing information about the file being read or parsed.
|
||||||
|
*
|
||||||
|
* The file info object currently only consists of a few properties, but it may grow in the future if plug-ins end up needing more information.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/plugins/file-info-object.html
|
||||||
|
*/
|
||||||
|
export interface FileInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The full URL of the file. This could be any type of URL, including "http://", "https://", "file://", "ftp://", "mongodb://", or even a local filesystem path (when running in Node.js).
|
||||||
|
*/
|
||||||
|
url: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The lowercase file extension, such as ".json", ".yaml", ".txt", etc.
|
||||||
|
*/
|
||||||
|
extension: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The raw file contents, in whatever form they were returned by the resolver that read the file.
|
||||||
|
*/
|
||||||
|
data: string | Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you call the resolve method, the value that gets passed to the callback function (or Promise) is a $Refs object. This same object is accessible via the parser.$refs property of $RefParser objects.
|
||||||
|
*
|
||||||
|
* This object is a map of JSON References and their resolved values. It also has several convenient helper methods that make it easy for you to navigate and manipulate the JSON References.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html
|
||||||
|
*/
|
||||||
|
export class $Refs {
|
||||||
|
/**
|
||||||
|
* This property is true if the schema contains any circular references. You may want to check this property before serializing the dereferenced schema as JSON, since JSON.stringify() does not support circular references by default.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#circular
|
||||||
|
*/
|
||||||
|
public circular: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the paths/URLs of all the files in your schema (including the main schema file).
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#pathstypes
|
||||||
|
*
|
||||||
|
* @param types (optional) Optionally only return certain types of paths ("file", "http", etc.)
|
||||||
|
*/
|
||||||
|
public paths(...types: string[]): string[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a map of paths/URLs and their correspond values.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#valuestypes
|
||||||
|
*
|
||||||
|
* @param types (optional) Optionally only return values from certain locations ("file", "http", etc.)
|
||||||
|
*/
|
||||||
|
public values(...types: string[]): { [url: string]: $RefParser.JSONSchema }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns `true` if the given path exists in the schema; otherwise, returns `false`
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#existsref
|
||||||
|
*
|
||||||
|
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
||||||
|
*/
|
||||||
|
public exists($ref: string): boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value at the given path in the schema. Throws an error if the path does not exist.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/refs.html#getref
|
||||||
|
*
|
||||||
|
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
||||||
|
*/
|
||||||
|
public get($ref: string): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value at the given path in the schema. If the property, or any of its parents, don't exist, they will be created.
|
||||||
|
*
|
||||||
|
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
||||||
|
* @param value The value to assign. Can be anything (object, string, number, etc.)
|
||||||
|
*/
|
||||||
|
public set($ref: string, value: JSONSchema4Type | JSONSchema6Type | JSONSchema7Type): void
|
||||||
|
}
|
||||||
|
|
||||||
|
export type JSONParserErrorType = "EUNKNOWN" | "EPARSER" | "EUNMATCHEDPARSER" | "ERESOLVER" | "EUNMATCHEDRESOLVER" | "EMISSINGPOINTER" | "EINVALIDPOINTER";
|
||||||
|
|
||||||
|
export class JSONParserError extends Error {
|
||||||
|
public constructor(message: string, source: string);
|
||||||
|
|
||||||
|
public readonly name: string;
|
||||||
|
public readonly message: string;
|
||||||
|
public readonly source: string;
|
||||||
|
public readonly path: Array<string | number>;
|
||||||
|
public readonly errors: string;
|
||||||
|
public readonly code: JSONParserErrorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class JSONParserErrorGroup extends Error {
|
||||||
|
/**
|
||||||
|
* List of all errors
|
||||||
|
*
|
||||||
|
* See https://github.com/APIDevTools/json-schema-ref-parser/blob/master/docs/ref-parser.md#errors
|
||||||
|
*/
|
||||||
|
public readonly errors: Array<$RefParser.JSONParserError | $RefParser.InvalidPointerError | $RefParser.ResolverError | $RefParser.ParserError | $RefParser.MissingPointerError | $RefParser.UnmatchedParserError | $RefParser.UnmatchedResolverError>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The fields property is a `$RefParser` instance
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/ref-parser.html
|
||||||
|
*/
|
||||||
|
public readonly files: $RefParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User friendly message containing the total amount of errors, as well as the absolute path to the source document
|
||||||
|
*/
|
||||||
|
public readonly message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ParserError extends JSONParserError {
|
||||||
|
public constructor(message: string, source: string);
|
||||||
|
|
||||||
|
public readonly name = "ParserError";
|
||||||
|
public readonly code = "EPARSER";
|
||||||
|
}
|
||||||
|
export class UnmatchedParserError extends JSONParserError {
|
||||||
|
public constructor(source: string);
|
||||||
|
|
||||||
|
public readonly name = "UnmatchedParserError";
|
||||||
|
public readonly code = "EUNMATCHEDPARSER";
|
||||||
|
}
|
||||||
|
export class ResolverError extends JSONParserError {
|
||||||
|
public constructor(ex: Error | NodeJS.ErrnoException, source: string);
|
||||||
|
|
||||||
|
public readonly name = "ResolverError";
|
||||||
|
public readonly code = "ERESOLVER";
|
||||||
|
public readonly ioErrorCode?: string;
|
||||||
|
}
|
||||||
|
export class UnmatchedResolverError extends JSONParserError {
|
||||||
|
public constructor(source: string);
|
||||||
|
|
||||||
|
public readonly name = "UnmatchedResolverError";
|
||||||
|
public readonly code = "EUNMATCHEDRESOLVER";
|
||||||
|
}
|
||||||
|
export class MissingPointerError extends JSONParserError {
|
||||||
|
public constructor(token: string | number, source: string);
|
||||||
|
|
||||||
|
public readonly name = "MissingPointerError";
|
||||||
|
public readonly code = "EMISSINGPOINTER";
|
||||||
|
}
|
||||||
|
export class InvalidPointerError extends JSONParserError {
|
||||||
|
public constructor(pointer: string, source: string);
|
||||||
|
|
||||||
|
public readonly name = "InvalidPointerError";
|
||||||
|
public readonly code = "EINVALIDPOINTER";
|
||||||
|
}
|
||||||
|
}
|
||||||
283
node_modules/@apidevtools/json-schema-ref-parser/lib/index.js
generated
vendored
Normal file
283
node_modules/@apidevtools/json-schema-ref-parser/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,283 @@
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const $Refs = require("./refs");
|
||||||
|
const _parse = require("./parse");
|
||||||
|
const normalizeArgs = require("./normalize-args");
|
||||||
|
const resolveExternal = require("./resolve-external");
|
||||||
|
const _bundle = require("./bundle");
|
||||||
|
const _dereference = require("./dereference");
|
||||||
|
const url = require("./util/url");
|
||||||
|
const { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, JSONParserErrorGroup } = require("./util/errors");
|
||||||
|
const maybe = require("call-me-maybe");
|
||||||
|
const { ono } = require("@jsdevtools/ono");
|
||||||
|
|
||||||
|
module.exports = $RefParser;
|
||||||
|
module.exports.default = $RefParser;
|
||||||
|
module.exports.JSONParserError = JSONParserError;
|
||||||
|
module.exports.InvalidPointerError = InvalidPointerError;
|
||||||
|
module.exports.MissingPointerError = MissingPointerError;
|
||||||
|
module.exports.ResolverError = ResolverError;
|
||||||
|
module.exports.ParserError = ParserError;
|
||||||
|
module.exports.UnmatchedParserError = UnmatchedParserError;
|
||||||
|
module.exports.UnmatchedResolverError = UnmatchedResolverError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
|
||||||
|
* and provides methods for traversing, manipulating, and dereferencing those references.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function $RefParser () {
|
||||||
|
/**
|
||||||
|
* The parsed (and possibly dereferenced) JSON schema object
|
||||||
|
*
|
||||||
|
* @type {object}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
this.schema = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The resolved JSON references
|
||||||
|
*
|
||||||
|
* @type {$Refs}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
this.$refs = new $Refs();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given JSON schema.
|
||||||
|
* This method does not resolve any JSON references.
|
||||||
|
* It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed
|
||||||
|
* @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.
|
||||||
|
* @returns {Promise} - The returned promise resolves with the parsed JSON schema object.
|
||||||
|
*/
|
||||||
|
$RefParser.parse = function parse (path, schema, options, callback) {
|
||||||
|
let Class = this; // eslint-disable-line consistent-this
|
||||||
|
let instance = new Class();
|
||||||
|
return instance.parse.apply(instance, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given JSON schema.
|
||||||
|
* This method does not resolve any JSON references.
|
||||||
|
* It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed
|
||||||
|
* @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.
|
||||||
|
* @returns {Promise} - The returned promise resolves with the parsed JSON schema object.
|
||||||
|
*/
|
||||||
|
$RefParser.prototype.parse = async function parse (path, schema, options, callback) {
|
||||||
|
let args = normalizeArgs(arguments);
|
||||||
|
let promise;
|
||||||
|
|
||||||
|
if (!args.path && !args.schema) {
|
||||||
|
let err = ono(`Expected a file path, URL, or object. Got ${args.path || args.schema}`);
|
||||||
|
return maybe(args.callback, Promise.reject(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset everything
|
||||||
|
this.schema = null;
|
||||||
|
this.$refs = new $Refs();
|
||||||
|
|
||||||
|
// If the path is a filesystem path, then convert it to a URL.
|
||||||
|
// NOTE: According to the JSON Reference spec, these should already be URLs,
|
||||||
|
// but, in practice, many people use local filesystem paths instead.
|
||||||
|
// So we're being generous here and doing the conversion automatically.
|
||||||
|
// This is not intended to be a 100% bulletproof solution.
|
||||||
|
// If it doesn't work for your use-case, then use a URL instead.
|
||||||
|
let pathType = "http";
|
||||||
|
if (url.isFileSystemPath(args.path)) {
|
||||||
|
args.path = url.fromFileSystemPath(args.path);
|
||||||
|
pathType = "file";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve the absolute path of the schema
|
||||||
|
args.path = url.resolve(url.cwd(), args.path);
|
||||||
|
|
||||||
|
if (args.schema && typeof args.schema === "object") {
|
||||||
|
// A schema object was passed-in.
|
||||||
|
// So immediately add a new $Ref with the schema object as its value
|
||||||
|
let $ref = this.$refs._add(args.path);
|
||||||
|
$ref.value = args.schema;
|
||||||
|
$ref.pathType = pathType;
|
||||||
|
promise = Promise.resolve(args.schema);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Parse the schema file/url
|
||||||
|
promise = _parse(args.path, this.$refs, args.options);
|
||||||
|
}
|
||||||
|
|
||||||
|
let me = this;
|
||||||
|
try {
|
||||||
|
let result = await promise;
|
||||||
|
|
||||||
|
if (result !== null && typeof result === "object" && !Buffer.isBuffer(result)) {
|
||||||
|
me.schema = result;
|
||||||
|
return maybe(args.callback, Promise.resolve(me.schema));
|
||||||
|
}
|
||||||
|
else if (args.options.continueOnError) {
|
||||||
|
me.schema = null; // it's already set to null at line 79, but let's set it again for the sake of readability
|
||||||
|
return maybe(args.callback, Promise.resolve(me.schema));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw ono.syntax(`"${me.$refs._root$Ref.path || result}" is not a valid JSON Schema`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (!args.options.continueOnError || !isHandledError(err)) {
|
||||||
|
return maybe(args.callback, Promise.reject(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.$refs._$refs[url.stripHash(args.path)]) {
|
||||||
|
this.$refs._$refs[url.stripHash(args.path)].addError(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return maybe(args.callback, Promise.resolve(null));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given JSON schema and resolves any JSON references, including references in
|
||||||
|
* externally-referenced files.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved
|
||||||
|
* @param {function} [callback]
|
||||||
|
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
|
||||||
|
*
|
||||||
|
* @returns {Promise}
|
||||||
|
* The returned promise resolves with a {@link $Refs} object containing the resolved JSON references
|
||||||
|
*/
|
||||||
|
$RefParser.resolve = function resolve (path, schema, options, callback) {
|
||||||
|
let Class = this; // eslint-disable-line consistent-this
|
||||||
|
let instance = new Class();
|
||||||
|
return instance.resolve.apply(instance, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given JSON schema and resolves any JSON references, including references in
|
||||||
|
* externally-referenced files.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved
|
||||||
|
* @param {function} [callback]
|
||||||
|
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
|
||||||
|
*
|
||||||
|
* @returns {Promise}
|
||||||
|
* The returned promise resolves with a {@link $Refs} object containing the resolved JSON references
|
||||||
|
*/
|
||||||
|
$RefParser.prototype.resolve = async function resolve (path, schema, options, callback) {
|
||||||
|
let me = this;
|
||||||
|
let args = normalizeArgs(arguments);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.parse(args.path, args.schema, args.options);
|
||||||
|
await resolveExternal(me, args.options);
|
||||||
|
finalize(me);
|
||||||
|
return maybe(args.callback, Promise.resolve(me.$refs));
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return maybe(args.callback, Promise.reject(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
||||||
|
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
||||||
|
* not any *external* references.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
||||||
|
* @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
||||||
|
* @returns {Promise} - The returned promise resolves with the bundled JSON schema object.
|
||||||
|
*/
|
||||||
|
$RefParser.bundle = function bundle (path, schema, options, callback) {
|
||||||
|
let Class = this; // eslint-disable-line consistent-this
|
||||||
|
let instance = new Class();
|
||||||
|
return instance.bundle.apply(instance, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given JSON schema, resolves any JSON references, and bundles all external references
|
||||||
|
* into the main JSON schema. This produces a JSON schema that only has *internal* references,
|
||||||
|
* not any *external* references.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
||||||
|
* @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object
|
||||||
|
* @returns {Promise} - The returned promise resolves with the bundled JSON schema object.
|
||||||
|
*/
|
||||||
|
$RefParser.prototype.bundle = async function bundle (path, schema, options, callback) {
|
||||||
|
let me = this;
|
||||||
|
let args = normalizeArgs(arguments);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.resolve(args.path, args.schema, args.options);
|
||||||
|
_bundle(me, args.options);
|
||||||
|
finalize(me);
|
||||||
|
return maybe(args.callback, Promise.resolve(me.schema));
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return maybe(args.callback, Promise.reject(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
||||||
|
* That is, all JSON references are replaced with their resolved values.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
||||||
|
* @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
||||||
|
* @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.
|
||||||
|
*/
|
||||||
|
$RefParser.dereference = function dereference (path, schema, options, callback) {
|
||||||
|
let Class = this; // eslint-disable-line consistent-this
|
||||||
|
let instance = new Class();
|
||||||
|
return instance.dereference.apply(instance, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
|
||||||
|
* That is, all JSON references are replaced with their resolved values.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [schema] - A JSON schema object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
|
||||||
|
* @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
|
||||||
|
* @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.
|
||||||
|
*/
|
||||||
|
$RefParser.prototype.dereference = async function dereference (path, schema, options, callback) {
|
||||||
|
let me = this;
|
||||||
|
let args = normalizeArgs(arguments);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.resolve(args.path, args.schema, args.options);
|
||||||
|
_dereference(me, args.options);
|
||||||
|
finalize(me);
|
||||||
|
return maybe(args.callback, Promise.resolve(me.schema));
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return maybe(args.callback, Promise.reject(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function finalize (parser) {
|
||||||
|
const errors = JSONParserErrorGroup.getParserErrors(parser);
|
||||||
|
if (errors.length > 0) {
|
||||||
|
throw new JSONParserErrorGroup(parser);
|
||||||
|
}
|
||||||
|
}
|
||||||
53
node_modules/@apidevtools/json-schema-ref-parser/lib/normalize-args.js
generated
vendored
Normal file
53
node_modules/@apidevtools/json-schema-ref-parser/lib/normalize-args.js
generated
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const Options = require("./options");
|
||||||
|
|
||||||
|
module.exports = normalizeArgs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes the given arguments, accounting for optional args.
|
||||||
|
*
|
||||||
|
* @param {Arguments} args
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
function normalizeArgs (args) {
|
||||||
|
let path, schema, options, callback;
|
||||||
|
args = Array.prototype.slice.call(args);
|
||||||
|
|
||||||
|
if (typeof args[args.length - 1] === "function") {
|
||||||
|
// The last parameter is a callback function
|
||||||
|
callback = args.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof args[0] === "string") {
|
||||||
|
// The first parameter is the path
|
||||||
|
path = args[0];
|
||||||
|
if (typeof args[2] === "object") {
|
||||||
|
// The second parameter is the schema, and the third parameter is the options
|
||||||
|
schema = args[1];
|
||||||
|
options = args[2];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// The second parameter is the options
|
||||||
|
schema = undefined;
|
||||||
|
options = args[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// The first parameter is the schema
|
||||||
|
path = "";
|
||||||
|
schema = args[0];
|
||||||
|
options = args[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(options instanceof Options)) {
|
||||||
|
options = new Options(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
path,
|
||||||
|
schema,
|
||||||
|
options,
|
||||||
|
callback
|
||||||
|
};
|
||||||
|
}
|
||||||
130
node_modules/@apidevtools/json-schema-ref-parser/lib/options.js
generated
vendored
Normal file
130
node_modules/@apidevtools/json-schema-ref-parser/lib/options.js
generated
vendored
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
/* eslint lines-around-comment: [2, {beforeBlockComment: false}] */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const jsonParser = require("./parsers/json");
|
||||||
|
const yamlParser = require("./parsers/yaml");
|
||||||
|
const textParser = require("./parsers/text");
|
||||||
|
const binaryParser = require("./parsers/binary");
|
||||||
|
const fileResolver = require("./resolvers/file");
|
||||||
|
const httpResolver = require("./resolvers/http");
|
||||||
|
|
||||||
|
module.exports = $RefParserOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options that determine how JSON schemas are parsed, resolved, and dereferenced.
|
||||||
|
*
|
||||||
|
* @param {object|$RefParserOptions} [options] - Overridden options
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function $RefParserOptions (options) {
|
||||||
|
merge(this, $RefParserOptions.defaults);
|
||||||
|
merge(this, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
$RefParserOptions.defaults = {
|
||||||
|
/**
|
||||||
|
* Determines how different types of files will be parsed.
|
||||||
|
*
|
||||||
|
* You can add additional parsers of your own, replace an existing one with
|
||||||
|
* your own implementation, or disable any parser by setting it to false.
|
||||||
|
*/
|
||||||
|
parse: {
|
||||||
|
json: jsonParser,
|
||||||
|
yaml: yamlParser,
|
||||||
|
text: textParser,
|
||||||
|
binary: binaryParser,
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines how JSON References will be resolved.
|
||||||
|
*
|
||||||
|
* You can add additional resolvers of your own, replace an existing one with
|
||||||
|
* your own implementation, or disable any resolver by setting it to false.
|
||||||
|
*/
|
||||||
|
resolve: {
|
||||||
|
file: fileResolver,
|
||||||
|
http: httpResolver,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether external $ref pointers will be resolved.
|
||||||
|
* If this option is disabled, then none of above resolvers will be called.
|
||||||
|
* Instead, external $ref pointers will simply be ignored.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
external: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, JSON Schema $Ref Parser throws the first error it encounters. Setting `continueOnError` to `true`
|
||||||
|
* causes it to keep processing as much as possible and then throw a single error that contains all errors
|
||||||
|
* that were encountered.
|
||||||
|
*/
|
||||||
|
continueOnError: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the types of JSON references that are allowed.
|
||||||
|
*/
|
||||||
|
dereference: {
|
||||||
|
/**
|
||||||
|
* Dereference circular (recursive) JSON references?
|
||||||
|
* If false, then a {@link ReferenceError} will be thrown if a circular reference is found.
|
||||||
|
* If "ignore", then circular references will not be dereferenced.
|
||||||
|
*
|
||||||
|
* @type {boolean|string}
|
||||||
|
*/
|
||||||
|
circular: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function, called for each path, which can return true to stop this path and all
|
||||||
|
* subpaths from being dereferenced further. This is useful in schemas where some
|
||||||
|
* subpaths contain literal $ref keys that should not be dereferenced.
|
||||||
|
*
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
|
excludedPathMatcher: () => false
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges the properties of the source object into the target object.
|
||||||
|
*
|
||||||
|
* @param {object} target - The object that we're populating
|
||||||
|
* @param {?object} source - The options that are being merged
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
function merge (target, source) {
|
||||||
|
if (isMergeable(source)) {
|
||||||
|
let keys = Object.keys(source);
|
||||||
|
for (let i = 0; i < keys.length; i++) {
|
||||||
|
let key = keys[i];
|
||||||
|
let sourceSetting = source[key];
|
||||||
|
let targetSetting = target[key];
|
||||||
|
|
||||||
|
if (isMergeable(sourceSetting)) {
|
||||||
|
// It's a nested object, so merge it recursively
|
||||||
|
target[key] = merge(targetSetting || {}, sourceSetting);
|
||||||
|
}
|
||||||
|
else if (sourceSetting !== undefined) {
|
||||||
|
// It's a scalar value, function, or array. No merging necessary. Just overwrite the target value.
|
||||||
|
target[key] = sourceSetting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given value can be merged,
|
||||||
|
* or if it is a scalar value that should just override the target value.
|
||||||
|
*
|
||||||
|
* @param {*} val
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
function isMergeable (val) {
|
||||||
|
return val &&
|
||||||
|
(typeof val === "object") &&
|
||||||
|
!Array.isArray(val) &&
|
||||||
|
!(val instanceof RegExp) &&
|
||||||
|
!(val instanceof Date);
|
||||||
|
}
|
||||||
164
node_modules/@apidevtools/json-schema-ref-parser/lib/parse.js
generated
vendored
Normal file
164
node_modules/@apidevtools/json-schema-ref-parser/lib/parse.js
generated
vendored
Normal file
|
|
@ -0,0 +1,164 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const { ono } = require("@jsdevtools/ono");
|
||||||
|
const url = require("./util/url");
|
||||||
|
const plugins = require("./util/plugins");
|
||||||
|
const { ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError } = require("./util/errors");
|
||||||
|
|
||||||
|
module.exports = parse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads and parses the specified file path or URL.
|
||||||
|
*
|
||||||
|
* @param {string} path - This path MUST already be resolved, since `read` doesn't know the resolution context
|
||||||
|
* @param {$Refs} $refs
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*
|
||||||
|
* @returns {Promise}
|
||||||
|
* The promise resolves with the parsed file contents, NOT the raw (Buffer) contents.
|
||||||
|
*/
|
||||||
|
async function parse (path, $refs, options) {
|
||||||
|
// Remove the URL fragment, if any
|
||||||
|
path = url.stripHash(path);
|
||||||
|
|
||||||
|
// Add a new $Ref for this file, even though we don't have the value yet.
|
||||||
|
// This ensures that we don't simultaneously read & parse the same file multiple times
|
||||||
|
let $ref = $refs._add(path);
|
||||||
|
|
||||||
|
// This "file object" will be passed to all resolvers and parsers.
|
||||||
|
let file = {
|
||||||
|
url: path,
|
||||||
|
extension: url.getExtension(path),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Read the file and then parse the data
|
||||||
|
try {
|
||||||
|
const resolver = await readFile(file, options, $refs);
|
||||||
|
$ref.pathType = resolver.plugin.name;
|
||||||
|
file.data = resolver.result;
|
||||||
|
|
||||||
|
const parser = await parseFile(file, options, $refs);
|
||||||
|
$ref.value = parser.result;
|
||||||
|
|
||||||
|
return parser.result;
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (isHandledError(err)) {
|
||||||
|
$ref.value = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the given file, using the configured resolver plugins
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*
|
||||||
|
* @returns {Promise}
|
||||||
|
* The promise resolves with the raw file contents and the resolver that was used.
|
||||||
|
*/
|
||||||
|
function readFile (file, options, $refs) {
|
||||||
|
return new Promise(((resolve, reject) => {
|
||||||
|
// console.log('Reading %s', file.url);
|
||||||
|
|
||||||
|
// Find the resolvers that can read this file
|
||||||
|
let resolvers = plugins.all(options.resolve);
|
||||||
|
resolvers = plugins.filter(resolvers, "canRead", file);
|
||||||
|
|
||||||
|
// Run the resolvers, in order, until one of them succeeds
|
||||||
|
plugins.sort(resolvers);
|
||||||
|
plugins.run(resolvers, "read", file, $refs)
|
||||||
|
.then(resolve, onError);
|
||||||
|
|
||||||
|
function onError (err) {
|
||||||
|
if (!err && options.continueOnError) {
|
||||||
|
// No resolver could be matched
|
||||||
|
reject(new UnmatchedResolverError(file.url));
|
||||||
|
}
|
||||||
|
else if (!err || !("error" in err)) {
|
||||||
|
// Throw a generic, friendly error.
|
||||||
|
reject(ono.syntax(`Unable to resolve $ref pointer "${file.url}"`));
|
||||||
|
}
|
||||||
|
// Throw the original error, if it's one of our own (user-friendly) errors.
|
||||||
|
else if (err.error instanceof ResolverError) {
|
||||||
|
reject(err.error);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reject(new ResolverError(err, file.url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given file's contents, using the configured parser plugins.
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*
|
||||||
|
* @returns {Promise}
|
||||||
|
* The promise resolves with the parsed file contents and the parser that was used.
|
||||||
|
*/
|
||||||
|
function parseFile (file, options, $refs) {
|
||||||
|
return new Promise(((resolve, reject) => {
|
||||||
|
// console.log('Parsing %s', file.url);
|
||||||
|
|
||||||
|
// Find the parsers that can read this file type.
|
||||||
|
// If none of the parsers are an exact match for this file, then we'll try ALL of them.
|
||||||
|
// This handles situations where the file IS a supported type, just with an unknown extension.
|
||||||
|
let allParsers = plugins.all(options.parse);
|
||||||
|
let filteredParsers = plugins.filter(allParsers, "canParse", file);
|
||||||
|
let parsers = filteredParsers.length > 0 ? filteredParsers : allParsers;
|
||||||
|
|
||||||
|
// Run the parsers, in order, until one of them succeeds
|
||||||
|
plugins.sort(parsers);
|
||||||
|
plugins.run(parsers, "parse", file, $refs)
|
||||||
|
.then(onParsed, onError);
|
||||||
|
|
||||||
|
function onParsed (parser) {
|
||||||
|
if (!parser.plugin.allowEmpty && isEmpty(parser.result)) {
|
||||||
|
reject(ono.syntax(`Error parsing "${file.url}" as ${parser.plugin.name}. \nParsed value is empty`));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve(parser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError (err) {
|
||||||
|
if (!err && options.continueOnError) {
|
||||||
|
// No resolver could be matched
|
||||||
|
reject(new UnmatchedParserError(file.url));
|
||||||
|
}
|
||||||
|
else if (!err || !("error" in err)) {
|
||||||
|
reject(ono.syntax(`Unable to parse ${file.url}`));
|
||||||
|
}
|
||||||
|
else if (err.error instanceof ParserError) {
|
||||||
|
reject(err.error);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reject(new ParserError(err.error.message, file.url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the parsed value is "empty".
|
||||||
|
*
|
||||||
|
* @param {*} value
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function isEmpty (value) {
|
||||||
|
return value === undefined ||
|
||||||
|
(typeof value === "object" && Object.keys(value).length === 0) ||
|
||||||
|
(typeof value === "string" && value.trim().length === 0) ||
|
||||||
|
(Buffer.isBuffer(value) && value.length === 0);
|
||||||
|
}
|
||||||
55
node_modules/@apidevtools/json-schema-ref-parser/lib/parsers/binary.js
generated
vendored
Normal file
55
node_modules/@apidevtools/json-schema-ref-parser/lib/parsers/binary.js
generated
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
let BINARY_REGEXP = /\.(jpeg|jpg|gif|png|bmp|ico)$/i;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* The order that this parser will run, in relation to other parsers.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
order: 400,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to allow "empty" files (zero bytes).
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
allowEmpty: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this parser can parse a given file reference.
|
||||||
|
* Parsers that return true will be tried, in order, until one successfully parses the file.
|
||||||
|
* Parsers that return false will be skipped, UNLESS all parsers returned false, in which case
|
||||||
|
* every parser will be tried.
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
canParse (file) {
|
||||||
|
// Use this parser if the file is a Buffer, and has a known binary extension
|
||||||
|
return Buffer.isBuffer(file.data) && BINARY_REGEXP.test(file.url);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given data as a Buffer (byte array).
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
|
||||||
|
* @returns {Buffer}
|
||||||
|
*/
|
||||||
|
parse (file) {
|
||||||
|
if (Buffer.isBuffer(file.data)) {
|
||||||
|
return file.data;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// This will reject if data is anything other than a string or typed array
|
||||||
|
return Buffer.from(file.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
63
node_modules/@apidevtools/json-schema-ref-parser/lib/parsers/json.js
generated
vendored
Normal file
63
node_modules/@apidevtools/json-schema-ref-parser/lib/parsers/json.js
generated
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const { ParserError } = require("../util/errors");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* The order that this parser will run, in relation to other parsers.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
order: 100,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to allow "empty" files. This includes zero-byte files, as well as empty JSON objects.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
allowEmpty: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this parser can parse a given file reference.
|
||||||
|
* Parsers that match will be tried, in order, until one successfully parses the file.
|
||||||
|
* Parsers that don't match will be skipped, UNLESS none of the parsers match, in which case
|
||||||
|
* every parser will be tried.
|
||||||
|
*
|
||||||
|
* @type {RegExp|string|string[]|function}
|
||||||
|
*/
|
||||||
|
canParse: ".json",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given file as JSON
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
async parse (file) { // eslint-disable-line require-await
|
||||||
|
let data = file.data;
|
||||||
|
if (Buffer.isBuffer(data)) {
|
||||||
|
data = data.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof data === "string") {
|
||||||
|
if (data.trim().length === 0) {
|
||||||
|
return; // This mirrors the YAML behavior
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
return JSON.parse(data);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
throw new ParserError(e.message, file.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// data is already a JavaScript value (object, array, number, null, NaN, etc.)
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
66
node_modules/@apidevtools/json-schema-ref-parser/lib/parsers/text.js
generated
vendored
Normal file
66
node_modules/@apidevtools/json-schema-ref-parser/lib/parsers/text.js
generated
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const { ParserError } = require("../util/errors");
|
||||||
|
|
||||||
|
let TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* The order that this parser will run, in relation to other parsers.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
order: 300,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to allow "empty" files (zero bytes).
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
allowEmpty: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The encoding that the text is expected to be in.
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
encoding: "utf8",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this parser can parse a given file reference.
|
||||||
|
* Parsers that return true will be tried, in order, until one successfully parses the file.
|
||||||
|
* Parsers that return false will be skipped, UNLESS all parsers returned false, in which case
|
||||||
|
* every parser will be tried.
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
canParse (file) {
|
||||||
|
// Use this parser if the file is a string or Buffer, and has a known text-based extension
|
||||||
|
return (typeof file.data === "string" || Buffer.isBuffer(file.data)) && TEXT_REGEXP.test(file.url);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given file as text
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
parse (file) {
|
||||||
|
if (typeof file.data === "string") {
|
||||||
|
return file.data;
|
||||||
|
}
|
||||||
|
else if (Buffer.isBuffer(file.data)) {
|
||||||
|
return file.data.toString(this.encoding);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new ParserError("data is not text", file.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
60
node_modules/@apidevtools/json-schema-ref-parser/lib/parsers/yaml.js
generated
vendored
Normal file
60
node_modules/@apidevtools/json-schema-ref-parser/lib/parsers/yaml.js
generated
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const { ParserError } = require("../util/errors");
|
||||||
|
const yaml = require("js-yaml");
|
||||||
|
const { JSON_SCHEMA } = require("js-yaml");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* The order that this parser will run, in relation to other parsers.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
order: 200,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to allow "empty" files. This includes zero-byte files, as well as empty JSON objects.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
allowEmpty: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this parser can parse a given file reference.
|
||||||
|
* Parsers that match will be tried, in order, until one successfully parses the file.
|
||||||
|
* Parsers that don't match will be skipped, UNLESS none of the parsers match, in which case
|
||||||
|
* every parser will be tried.
|
||||||
|
*
|
||||||
|
* @type {RegExp|string[]|function}
|
||||||
|
*/
|
||||||
|
canParse: [".yaml", ".yml", ".json"], // JSON is valid YAML
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given file as YAML
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
async parse (file) { // eslint-disable-line require-await
|
||||||
|
let data = file.data;
|
||||||
|
if (Buffer.isBuffer(data)) {
|
||||||
|
data = data.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof data === "string") {
|
||||||
|
try {
|
||||||
|
return yaml.load(data, { schema: JSON_SCHEMA });
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
throw new ParserError(e.message, file.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// data is already a JavaScript value (object, array, number, null, NaN, etc.)
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
295
node_modules/@apidevtools/json-schema-ref-parser/lib/pointer.js
generated
vendored
Normal file
295
node_modules/@apidevtools/json-schema-ref-parser/lib/pointer.js
generated
vendored
Normal file
|
|
@ -0,0 +1,295 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = Pointer;
|
||||||
|
|
||||||
|
const $Ref = require("./ref");
|
||||||
|
const url = require("./util/url");
|
||||||
|
const { JSONParserError, InvalidPointerError, MissingPointerError, isHandledError } = require("./util/errors");
|
||||||
|
const slashes = /\//g;
|
||||||
|
const tildes = /~/g;
|
||||||
|
const escapedSlash = /~1/g;
|
||||||
|
const escapedTilde = /~0/g;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a single JSON pointer and its resolved value.
|
||||||
|
*
|
||||||
|
* @param {$Ref} $ref
|
||||||
|
* @param {string} path
|
||||||
|
* @param {string} [friendlyPath] - The original user-specified path (used for error messages)
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function Pointer ($ref, path, friendlyPath) {
|
||||||
|
/**
|
||||||
|
* The {@link $Ref} object that contains this {@link Pointer} object.
|
||||||
|
* @type {$Ref}
|
||||||
|
*/
|
||||||
|
this.$ref = $ref;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The file path or URL, containing the JSON pointer in the hash.
|
||||||
|
* This path is relative to the path of the main JSON schema file.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.path = path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The original path or URL, used for error messages.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.originalPath = friendlyPath || path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value of the JSON pointer.
|
||||||
|
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
|
||||||
|
* @type {?*}
|
||||||
|
*/
|
||||||
|
this.value = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the pointer references itself.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.circular = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of indirect references that were traversed to resolve the value.
|
||||||
|
* Resolving a single pointer may require resolving multiple $Refs.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.indirections = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the value of a nested property within the given object.
|
||||||
|
*
|
||||||
|
* @param {*} obj - The object that will be crawled
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @param {string} pathFromRoot - the path of place that initiated resolving
|
||||||
|
*
|
||||||
|
* @returns {Pointer}
|
||||||
|
* Returns a JSON pointer whose {@link Pointer#value} is the resolved value.
|
||||||
|
* If resolving this value required resolving other JSON references, then
|
||||||
|
* the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
|
||||||
|
* of the resolved value.
|
||||||
|
*/
|
||||||
|
Pointer.prototype.resolve = function (obj, options, pathFromRoot) {
|
||||||
|
let tokens = Pointer.parse(this.path, this.originalPath);
|
||||||
|
|
||||||
|
// Crawl the object, one token at a time
|
||||||
|
this.value = unwrapOrThrow(obj);
|
||||||
|
|
||||||
|
for (let i = 0; i < tokens.length; i++) {
|
||||||
|
if (resolveIf$Ref(this, options)) {
|
||||||
|
// The $ref path has changed, so append the remaining tokens to the path
|
||||||
|
this.path = Pointer.join(this.path, tokens.slice(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof this.value === "object" && this.value !== null && "$ref" in this.value) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
let token = tokens[i];
|
||||||
|
if (this.value[token] === undefined || this.value[token] === null) {
|
||||||
|
this.value = null;
|
||||||
|
throw new MissingPointerError(token, decodeURI(this.originalPath));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.value = this.value[token];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve the final value
|
||||||
|
if (!this.value || this.value.$ref && url.resolve(this.path, this.value.$ref) !== pathFromRoot) {
|
||||||
|
resolveIf$Ref(this, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a nested property within the given object.
|
||||||
|
*
|
||||||
|
* @param {*} obj - The object that will be crawled
|
||||||
|
* @param {*} value - the value to assign
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*
|
||||||
|
* @returns {*}
|
||||||
|
* Returns the modified object, or an entirely new object if the entire object is overwritten.
|
||||||
|
*/
|
||||||
|
Pointer.prototype.set = function (obj, value, options) {
|
||||||
|
let tokens = Pointer.parse(this.path);
|
||||||
|
let token;
|
||||||
|
|
||||||
|
if (tokens.length === 0) {
|
||||||
|
// There are no tokens, replace the entire object with the new value
|
||||||
|
this.value = value;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crawl the object, one token at a time
|
||||||
|
this.value = unwrapOrThrow(obj);
|
||||||
|
|
||||||
|
for (let i = 0; i < tokens.length - 1; i++) {
|
||||||
|
resolveIf$Ref(this, options);
|
||||||
|
|
||||||
|
token = tokens[i];
|
||||||
|
if (this.value && this.value[token] !== undefined) {
|
||||||
|
// The token exists
|
||||||
|
this.value = this.value[token];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// The token doesn't exist, so create it
|
||||||
|
this.value = setValue(this, token, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the value of the final token
|
||||||
|
resolveIf$Ref(this, options);
|
||||||
|
token = tokens[tokens.length - 1];
|
||||||
|
setValue(this, token, value);
|
||||||
|
|
||||||
|
// Return the updated object
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a JSON pointer (or a path containing a JSON pointer in the hash)
|
||||||
|
* and returns an array of the pointer's tokens.
|
||||||
|
* (e.g. "schema.json#/definitions/person/name" => ["definitions", "person", "name"])
|
||||||
|
*
|
||||||
|
* The pointer is parsed according to RFC 6901
|
||||||
|
* {@link https://tools.ietf.org/html/rfc6901#section-3}
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @param {string} [originalPath]
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
Pointer.parse = function (path, originalPath) {
|
||||||
|
// Get the JSON pointer from the path's hash
|
||||||
|
let pointer = url.getHash(path).substr(1);
|
||||||
|
|
||||||
|
// If there's no pointer, then there are no tokens,
|
||||||
|
// so return an empty array
|
||||||
|
if (!pointer) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split into an array
|
||||||
|
pointer = pointer.split("/");
|
||||||
|
|
||||||
|
// Decode each part, according to RFC 6901
|
||||||
|
for (let i = 0; i < pointer.length; i++) {
|
||||||
|
pointer[i] = decodeURIComponent(pointer[i].replace(escapedSlash, "/").replace(escapedTilde, "~"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pointer[0] !== "") {
|
||||||
|
throw new InvalidPointerError(pointer, originalPath === undefined ? path : originalPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pointer.slice(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a JSON pointer path, by joining one or more tokens to a base path.
|
||||||
|
*
|
||||||
|
* @param {string} base - The base path (e.g. "schema.json#/definitions/person")
|
||||||
|
* @param {string|string[]} tokens - The token(s) to append (e.g. ["name", "first"])
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
Pointer.join = function (base, tokens) {
|
||||||
|
// Ensure that the base path contains a hash
|
||||||
|
if (base.indexOf("#") === -1) {
|
||||||
|
base += "#";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append each token to the base path
|
||||||
|
tokens = Array.isArray(tokens) ? tokens : [tokens];
|
||||||
|
for (let i = 0; i < tokens.length; i++) {
|
||||||
|
let token = tokens[i];
|
||||||
|
// Encode the token, according to RFC 6901
|
||||||
|
base += "/" + encodeURIComponent(token.replace(tildes, "~0").replace(slashes, "~1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return base;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the given pointer's {@link Pointer#value} is a JSON reference,
|
||||||
|
* then the reference is resolved and {@link Pointer#value} is replaced with the resolved value.
|
||||||
|
* In addition, {@link Pointer#path} and {@link Pointer#$ref} are updated to reflect the
|
||||||
|
* resolution path of the new value.
|
||||||
|
*
|
||||||
|
* @param {Pointer} pointer
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @returns {boolean} - Returns `true` if the resolution path changed
|
||||||
|
*/
|
||||||
|
function resolveIf$Ref (pointer, options) {
|
||||||
|
// Is the value a JSON reference? (and allowed?)
|
||||||
|
|
||||||
|
if ($Ref.isAllowed$Ref(pointer.value, options)) {
|
||||||
|
let $refPath = url.resolve(pointer.path, pointer.value.$ref);
|
||||||
|
|
||||||
|
if ($refPath === pointer.path) {
|
||||||
|
// The value is a reference to itself, so there's nothing to do.
|
||||||
|
pointer.circular = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let resolved = pointer.$ref.$refs._resolve($refPath, pointer.path, options);
|
||||||
|
if (resolved === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pointer.indirections += resolved.indirections + 1;
|
||||||
|
|
||||||
|
if ($Ref.isExtended$Ref(pointer.value)) {
|
||||||
|
// This JSON reference "extends" the resolved value, rather than simply pointing to it.
|
||||||
|
// So the resolved path does NOT change. Just the value does.
|
||||||
|
pointer.value = $Ref.dereference(pointer.value, resolved.value);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Resolve the reference
|
||||||
|
pointer.$ref = resolved.$ref;
|
||||||
|
pointer.path = resolved.path;
|
||||||
|
pointer.value = resolved.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the specified token value of the {@link Pointer#value}.
|
||||||
|
*
|
||||||
|
* The token is evaluated according to RFC 6901.
|
||||||
|
* {@link https://tools.ietf.org/html/rfc6901#section-4}
|
||||||
|
*
|
||||||
|
* @param {Pointer} pointer - The JSON Pointer whose value will be modified
|
||||||
|
* @param {string} token - A JSON Pointer token that indicates how to modify `obj`
|
||||||
|
* @param {*} value - The value to assign
|
||||||
|
* @returns {*} - Returns the assigned value
|
||||||
|
*/
|
||||||
|
function setValue (pointer, token, value) {
|
||||||
|
if (pointer.value && typeof pointer.value === "object") {
|
||||||
|
if (token === "-" && Array.isArray(pointer.value)) {
|
||||||
|
pointer.value.push(value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pointer.value[token] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new JSONParserError(`Error assigning $ref pointer "${pointer.path}". \nCannot set "${token}" of a non-object.`);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function unwrapOrThrow (value) {
|
||||||
|
if (isHandledError(value)) {
|
||||||
|
throw value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
294
node_modules/@apidevtools/json-schema-ref-parser/lib/ref.js
generated
vendored
Normal file
294
node_modules/@apidevtools/json-schema-ref-parser/lib/ref.js
generated
vendored
Normal file
|
|
@ -0,0 +1,294 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = $Ref;
|
||||||
|
|
||||||
|
const Pointer = require("./pointer");
|
||||||
|
const { InvalidPointerError, isHandledError, normalizeError } = require("./util/errors");
|
||||||
|
const { safePointerToPath, stripHash, getHash } = require("./util/url");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a single JSON reference and its resolved value.
|
||||||
|
*
|
||||||
|
* @class
|
||||||
|
*/
|
||||||
|
function $Ref () {
|
||||||
|
/**
|
||||||
|
* The file path or URL of the referenced file.
|
||||||
|
* This path is relative to the path of the main JSON schema file.
|
||||||
|
*
|
||||||
|
* This path does NOT contain document fragments (JSON pointers). It always references an ENTIRE file.
|
||||||
|
* Use methods such as {@link $Ref#get}, {@link $Ref#resolve}, and {@link $Ref#exists} to get
|
||||||
|
* specific JSON pointers within the file.
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.path = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The resolved value of the JSON reference.
|
||||||
|
* Can be any JSON type, not just objects. Unknown file types are represented as Buffers (byte arrays).
|
||||||
|
*
|
||||||
|
* @type {?*}
|
||||||
|
*/
|
||||||
|
this.value = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link $Refs} object that contains this {@link $Ref} object.
|
||||||
|
*
|
||||||
|
* @type {$Refs}
|
||||||
|
*/
|
||||||
|
this.$refs = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)
|
||||||
|
*
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
this.pathType = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of all errors. Undefined if no errors.
|
||||||
|
*
|
||||||
|
* @type {Array<JSONParserError | ResolverError | ParserError | MissingPointerError>}
|
||||||
|
*/
|
||||||
|
this.errors = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pushes an error to errors array.
|
||||||
|
*
|
||||||
|
* @param {Array<JSONParserError | JSONParserErrorGroup>} err - The error to be pushed
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
$Ref.prototype.addError = function (err) {
|
||||||
|
if (this.errors === undefined) {
|
||||||
|
this.errors = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingErrors = this.errors.map(({ footprint }) => footprint);
|
||||||
|
|
||||||
|
// the path has been almost certainly set at this point,
|
||||||
|
// but just in case something went wrong, normalizeError injects path if necessary
|
||||||
|
// moreover, certain errors might point at the same spot, so filter them out to reduce noise
|
||||||
|
if (Array.isArray(err.errors)) {
|
||||||
|
this.errors.push(...err.errors
|
||||||
|
.map(normalizeError)
|
||||||
|
.filter(({ footprint }) => !existingErrors.includes(footprint)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (!existingErrors.includes(err.footprint)) {
|
||||||
|
this.errors.push(normalizeError(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given JSON reference exists within this {@link $Ref#value}.
|
||||||
|
*
|
||||||
|
* @param {string} path - The full path being resolved, optionally with a JSON pointer in the hash
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
$Ref.prototype.exists = function (path, options) {
|
||||||
|
try {
|
||||||
|
this.resolve(path, options);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the given JSON reference within this {@link $Ref#value} and returns the resolved value.
|
||||||
|
*
|
||||||
|
* @param {string} path - The full path being resolved, optionally with a JSON pointer in the hash
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @returns {*} - Returns the resolved value
|
||||||
|
*/
|
||||||
|
$Ref.prototype.get = function (path, options) {
|
||||||
|
return this.resolve(path, options).value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the given JSON reference within this {@link $Ref#value}.
|
||||||
|
*
|
||||||
|
* @param {string} path - The full path being resolved, optionally with a JSON pointer in the hash
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @param {string} friendlyPath - The original user-specified path (used for error messages)
|
||||||
|
* @param {string} pathFromRoot - The path of `obj` from the schema root
|
||||||
|
* @returns {Pointer | null}
|
||||||
|
*/
|
||||||
|
$Ref.prototype.resolve = function (path, options, friendlyPath, pathFromRoot) {
|
||||||
|
let pointer = new Pointer(this, path, friendlyPath);
|
||||||
|
try {
|
||||||
|
return pointer.resolve(this.value, options, pathFromRoot);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (!options || !options.continueOnError || !isHandledError(err)) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err.path === null) {
|
||||||
|
err.path = safePointerToPath(getHash(pathFromRoot));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err instanceof InvalidPointerError) {
|
||||||
|
// this is a special case - InvalidPointerError is thrown when dereferencing external file,
|
||||||
|
// but the issue is caused by the source file that referenced the file that undergoes dereferencing
|
||||||
|
err.source = decodeURI(stripHash(pathFromRoot));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addError(err);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a nested property within this {@link $Ref#value}.
|
||||||
|
* If the property, or any of its parents don't exist, they will be created.
|
||||||
|
*
|
||||||
|
* @param {string} path - The full path of the property to set, optionally with a JSON pointer in the hash
|
||||||
|
* @param {*} value - The value to assign
|
||||||
|
*/
|
||||||
|
$Ref.prototype.set = function (path, value) {
|
||||||
|
let pointer = new Pointer(this, path);
|
||||||
|
this.value = pointer.set(this.value, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given value is a JSON reference.
|
||||||
|
*
|
||||||
|
* @param {*} value - The value to inspect
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
$Ref.is$Ref = function (value) {
|
||||||
|
return value && typeof value === "object" && typeof value.$ref === "string" && value.$ref.length > 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given value is an external JSON reference.
|
||||||
|
*
|
||||||
|
* @param {*} value - The value to inspect
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
$Ref.isExternal$Ref = function (value) {
|
||||||
|
return $Ref.is$Ref(value) && value.$ref[0] !== "#";
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given value is a JSON reference, and whether it is allowed by the options.
|
||||||
|
* For example, if it references an external file, then options.resolve.external must be true.
|
||||||
|
*
|
||||||
|
* @param {*} value - The value to inspect
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
$Ref.isAllowed$Ref = function (value, options) {
|
||||||
|
if ($Ref.is$Ref(value)) {
|
||||||
|
if (value.$ref.substr(0, 2) === "#/" || value.$ref === "#") {
|
||||||
|
// It's a JSON Pointer reference, which is always allowed
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (value.$ref[0] !== "#" && (!options || options.resolve.external)) {
|
||||||
|
// It's an external reference, which is allowed by the options
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given value is a JSON reference that "extends" its resolved value.
|
||||||
|
* That is, it has extra properties (in addition to "$ref"), so rather than simply pointing to
|
||||||
|
* an existing value, this $ref actually creates a NEW value that is a shallow copy of the resolved
|
||||||
|
* value, plus the extra properties.
|
||||||
|
*
|
||||||
|
* @example:
|
||||||
|
* {
|
||||||
|
* person: {
|
||||||
|
* properties: {
|
||||||
|
* firstName: { type: string }
|
||||||
|
* lastName: { type: string }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* employee: {
|
||||||
|
* properties: {
|
||||||
|
* $ref: #/person/properties
|
||||||
|
* salary: { type: number }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* In this example, "employee" is an extended $ref, since it extends "person" with an additional
|
||||||
|
* property (salary). The result is a NEW value that looks like this:
|
||||||
|
*
|
||||||
|
* {
|
||||||
|
* properties: {
|
||||||
|
* firstName: { type: string }
|
||||||
|
* lastName: { type: string }
|
||||||
|
* salary: { type: number }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @param {*} value - The value to inspect
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
$Ref.isExtended$Ref = function (value) {
|
||||||
|
return $Ref.is$Ref(value) && Object.keys(value).length > 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the resolved value of a JSON Reference.
|
||||||
|
* If necessary, the resolved value is merged with the JSON Reference to create a new object
|
||||||
|
*
|
||||||
|
* @example:
|
||||||
|
* {
|
||||||
|
* person: {
|
||||||
|
* properties: {
|
||||||
|
* firstName: { type: string }
|
||||||
|
* lastName: { type: string }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* employee: {
|
||||||
|
* properties: {
|
||||||
|
* $ref: #/person/properties
|
||||||
|
* salary: { type: number }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* When "person" and "employee" are merged, you end up with the following object:
|
||||||
|
*
|
||||||
|
* {
|
||||||
|
* properties: {
|
||||||
|
* firstName: { type: string }
|
||||||
|
* lastName: { type: string }
|
||||||
|
* salary: { type: number }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @param {object} $ref - The JSON reference object (the one with the "$ref" property)
|
||||||
|
* @param {*} resolvedValue - The resolved value, which can be any type
|
||||||
|
* @returns {*} - Returns the dereferenced value
|
||||||
|
*/
|
||||||
|
$Ref.dereference = function ($ref, resolvedValue) {
|
||||||
|
if (resolvedValue && typeof resolvedValue === "object" && $Ref.isExtended$Ref($ref)) {
|
||||||
|
let merged = {};
|
||||||
|
for (let key of Object.keys($ref)) {
|
||||||
|
if (key !== "$ref") {
|
||||||
|
merged[key] = $ref[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let key of Object.keys(resolvedValue)) {
|
||||||
|
if (!(key in merged)) {
|
||||||
|
merged[key] = resolvedValue[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Completely replace the original reference with the resolved value
|
||||||
|
return resolvedValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
197
node_modules/@apidevtools/json-schema-ref-parser/lib/refs.js
generated
vendored
Normal file
197
node_modules/@apidevtools/json-schema-ref-parser/lib/refs.js
generated
vendored
Normal file
|
|
@ -0,0 +1,197 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const { ono } = require("@jsdevtools/ono");
|
||||||
|
const $Ref = require("./ref");
|
||||||
|
const url = require("./util/url");
|
||||||
|
|
||||||
|
module.exports = $Refs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a map of JSON references and their resolved values.
|
||||||
|
*/
|
||||||
|
function $Refs () {
|
||||||
|
/**
|
||||||
|
* Indicates whether the schema contains any circular references.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.circular = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A map of paths/urls to {@link $Ref} objects
|
||||||
|
*
|
||||||
|
* @type {object}
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
this._$refs = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link $Ref} object that is the root of the JSON schema.
|
||||||
|
*
|
||||||
|
* @type {$Ref}
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
this._root$Ref = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the paths of all the files/URLs that are referenced by the JSON schema,
|
||||||
|
* including the schema itself.
|
||||||
|
*
|
||||||
|
* @param {...string|string[]} [types] - Only return paths of the given types ("file", "http", etc.)
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
$Refs.prototype.paths = function (types) { // eslint-disable-line no-unused-vars
|
||||||
|
let paths = getPaths(this._$refs, arguments);
|
||||||
|
return paths.map((path) => {
|
||||||
|
return path.decoded;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the map of JSON references and their resolved values.
|
||||||
|
*
|
||||||
|
* @param {...string|string[]} [types] - Only return references of the given types ("file", "http", etc.)
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
$Refs.prototype.values = function (types) { // eslint-disable-line no-unused-vars
|
||||||
|
let $refs = this._$refs;
|
||||||
|
let paths = getPaths($refs, arguments);
|
||||||
|
return paths.reduce((obj, path) => {
|
||||||
|
obj[path.decoded] = $refs[path.encoded].value;
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a POJO (plain old JavaScript object) for serialization as JSON.
|
||||||
|
*
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
$Refs.prototype.toJSON = $Refs.prototype.values;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given JSON reference exists.
|
||||||
|
*
|
||||||
|
* @param {string} path - The path being resolved, optionally with a JSON pointer in the hash
|
||||||
|
* @param {$RefParserOptions} [options]
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
$Refs.prototype.exists = function (path, options) {
|
||||||
|
try {
|
||||||
|
this._resolve(path, "", options);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the given JSON reference and returns the resolved value.
|
||||||
|
*
|
||||||
|
* @param {string} path - The path being resolved, with a JSON pointer in the hash
|
||||||
|
* @param {$RefParserOptions} [options]
|
||||||
|
* @returns {*} - Returns the resolved value
|
||||||
|
*/
|
||||||
|
$Refs.prototype.get = function (path, options) {
|
||||||
|
return this._resolve(path, "", options).value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a nested property within this {@link $Ref#value}.
|
||||||
|
* If the property, or any of its parents don't exist, they will be created.
|
||||||
|
*
|
||||||
|
* @param {string} path - The path of the property to set, optionally with a JSON pointer in the hash
|
||||||
|
* @param {*} value - The value to assign
|
||||||
|
*/
|
||||||
|
$Refs.prototype.set = function (path, value) {
|
||||||
|
let absPath = url.resolve(this._root$Ref.path, path);
|
||||||
|
let withoutHash = url.stripHash(absPath);
|
||||||
|
let $ref = this._$refs[withoutHash];
|
||||||
|
|
||||||
|
if (!$ref) {
|
||||||
|
throw ono(`Error resolving $ref pointer "${path}". \n"${withoutHash}" not found.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ref.set(absPath, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link $Ref} object and adds it to this {@link $Refs} object.
|
||||||
|
*
|
||||||
|
* @param {string} path - The file path or URL of the referenced file
|
||||||
|
*/
|
||||||
|
$Refs.prototype._add = function (path) {
|
||||||
|
let withoutHash = url.stripHash(path);
|
||||||
|
|
||||||
|
let $ref = new $Ref();
|
||||||
|
$ref.path = withoutHash;
|
||||||
|
$ref.$refs = this;
|
||||||
|
|
||||||
|
this._$refs[withoutHash] = $ref;
|
||||||
|
this._root$Ref = this._root$Ref || $ref;
|
||||||
|
|
||||||
|
return $ref;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the given JSON reference.
|
||||||
|
*
|
||||||
|
* @param {string} path - The path being resolved, optionally with a JSON pointer in the hash
|
||||||
|
* @param {string} pathFromRoot - The path of `obj` from the schema root
|
||||||
|
* @param {$RefParserOptions} [options]
|
||||||
|
* @returns {Pointer}
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
$Refs.prototype._resolve = function (path, pathFromRoot, options) {
|
||||||
|
let absPath = url.resolve(this._root$Ref.path, path);
|
||||||
|
let withoutHash = url.stripHash(absPath);
|
||||||
|
let $ref = this._$refs[withoutHash];
|
||||||
|
|
||||||
|
if (!$ref) {
|
||||||
|
throw ono(`Error resolving $ref pointer "${path}". \n"${withoutHash}" not found.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ref.resolve(absPath, options, path, pathFromRoot);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the specified {@link $Ref} object, or undefined.
|
||||||
|
*
|
||||||
|
* @param {string} path - The path being resolved, optionally with a JSON pointer in the hash
|
||||||
|
* @returns {$Ref|undefined}
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
$Refs.prototype._get$Ref = function (path) {
|
||||||
|
path = url.resolve(this._root$Ref.path, path);
|
||||||
|
let withoutHash = url.stripHash(path);
|
||||||
|
return this._$refs[withoutHash];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the encoded and decoded paths keys of the given object.
|
||||||
|
*
|
||||||
|
* @param {object} $refs - The object whose keys are URL-encoded paths
|
||||||
|
* @param {...string|string[]} [types] - Only return paths of the given types ("file", "http", etc.)
|
||||||
|
* @returns {object[]}
|
||||||
|
*/
|
||||||
|
function getPaths ($refs, types) {
|
||||||
|
let paths = Object.keys($refs);
|
||||||
|
|
||||||
|
// Filter the paths by type
|
||||||
|
types = Array.isArray(types[0]) ? types[0] : Array.prototype.slice.call(types);
|
||||||
|
if (types.length > 0 && types[0]) {
|
||||||
|
paths = paths.filter((key) => {
|
||||||
|
return types.indexOf($refs[key].pathType) !== -1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode local filesystem paths
|
||||||
|
return paths.map((path) => {
|
||||||
|
return {
|
||||||
|
encoded: path,
|
||||||
|
decoded: $refs[path].pathType === "file" ? url.toFileSystemPath(path, true) : path
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
129
node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js
generated
vendored
Normal file
129
node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js
generated
vendored
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const $Ref = require("./ref");
|
||||||
|
const Pointer = require("./pointer");
|
||||||
|
const parse = require("./parse");
|
||||||
|
const url = require("./util/url");
|
||||||
|
const { isHandledError } = require("./util/errors");
|
||||||
|
|
||||||
|
module.exports = resolveExternal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crawls the JSON schema, finds all external JSON references, and resolves their values.
|
||||||
|
* This method does not mutate the JSON schema. The resolved values are added to {@link $RefParser#$refs}.
|
||||||
|
*
|
||||||
|
* NOTE: We only care about EXTERNAL references here. INTERNAL references are only relevant when dereferencing.
|
||||||
|
*
|
||||||
|
* @param {$RefParser} parser
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*
|
||||||
|
* @returns {Promise}
|
||||||
|
* The promise resolves once all JSON references in the schema have been resolved,
|
||||||
|
* including nested references that are contained in externally-referenced files.
|
||||||
|
*/
|
||||||
|
function resolveExternal (parser, options) {
|
||||||
|
if (!options.resolve.external) {
|
||||||
|
// Nothing to resolve, so exit early
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// console.log('Resolving $ref pointers in %s', parser.$refs._root$Ref.path);
|
||||||
|
let promises = crawl(parser.schema, parser.$refs._root$Ref.path + "#", parser.$refs, options);
|
||||||
|
return Promise.all(promises);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return Promise.reject(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively crawls the given value, and resolves any external JSON references.
|
||||||
|
*
|
||||||
|
* @param {*} obj - The value to crawl. If it's not an object or array, it will be ignored.
|
||||||
|
* @param {string} path - The full path of `obj`, possibly with a JSON Pointer in the hash
|
||||||
|
* @param {$Refs} $refs
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
* @param {Set} seen - Internal.
|
||||||
|
*
|
||||||
|
* @returns {Promise[]}
|
||||||
|
* Returns an array of promises. There will be one promise for each JSON reference in `obj`.
|
||||||
|
* If `obj` does not contain any JSON references, then the array will be empty.
|
||||||
|
* If any of the JSON references point to files that contain additional JSON references,
|
||||||
|
* then the corresponding promise will internally reference an array of promises.
|
||||||
|
*/
|
||||||
|
function crawl (obj, path, $refs, options, seen) {
|
||||||
|
seen = seen || new Set();
|
||||||
|
let promises = [];
|
||||||
|
|
||||||
|
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !seen.has(obj)) {
|
||||||
|
seen.add(obj); // Track previously seen objects to avoid infinite recursion
|
||||||
|
if ($Ref.isExternal$Ref(obj)) {
|
||||||
|
promises.push(resolve$Ref(obj, path, $refs, options));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (let key of Object.keys(obj)) {
|
||||||
|
let keyPath = Pointer.join(path, key);
|
||||||
|
let value = obj[key];
|
||||||
|
|
||||||
|
if ($Ref.isExternal$Ref(value)) {
|
||||||
|
promises.push(resolve$Ref(value, keyPath, $refs, options));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
promises = promises.concat(crawl(value, keyPath, $refs, options, seen));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return promises;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the given JSON Reference, and then crawls the resulting value.
|
||||||
|
*
|
||||||
|
* @param {{$ref: string}} $ref - The JSON Reference to resolve
|
||||||
|
* @param {string} path - The full path of `$ref`, possibly with a JSON Pointer in the hash
|
||||||
|
* @param {$Refs} $refs
|
||||||
|
* @param {$RefParserOptions} options
|
||||||
|
*
|
||||||
|
* @returns {Promise}
|
||||||
|
* The promise resolves once all JSON references in the object have been resolved,
|
||||||
|
* including nested references that are contained in externally-referenced files.
|
||||||
|
*/
|
||||||
|
async function resolve$Ref ($ref, path, $refs, options) {
|
||||||
|
// console.log('Resolving $ref pointer "%s" at %s', $ref.$ref, path);
|
||||||
|
|
||||||
|
let resolvedPath = url.resolve(path, $ref.$ref);
|
||||||
|
let withoutHash = url.stripHash(resolvedPath);
|
||||||
|
|
||||||
|
// Do we already have this $ref?
|
||||||
|
$ref = $refs._$refs[withoutHash];
|
||||||
|
if ($ref) {
|
||||||
|
// We've already parsed this $ref, so use the existing value
|
||||||
|
return Promise.resolve($ref.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the $referenced file/url
|
||||||
|
try {
|
||||||
|
const result = await parse(resolvedPath, $refs, options);
|
||||||
|
|
||||||
|
// Crawl the parsed value
|
||||||
|
// console.log('Resolving $ref pointers in %s', withoutHash);
|
||||||
|
let promises = crawl(result, withoutHash + "#", $refs, options);
|
||||||
|
|
||||||
|
return Promise.all(promises);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (!options.continueOnError || !isHandledError(err)) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($refs._$refs[withoutHash]) {
|
||||||
|
err.source = decodeURI(url.stripHash(path));
|
||||||
|
err.path = url.safePointerToPath(url.getHash(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
64
node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers/file.js
generated
vendored
Normal file
64
node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers/file.js
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
"use strict";
|
||||||
|
const fs = require("fs");
|
||||||
|
const { ono } = require("@jsdevtools/ono");
|
||||||
|
const url = require("../util/url");
|
||||||
|
const { ResolverError } = require("../util/errors");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* The order that this resolver will run, in relation to other resolvers.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
order: 100,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this resolver can read a given file reference.
|
||||||
|
* Resolvers that return true will be tried, in order, until one successfully resolves the file.
|
||||||
|
* Resolvers that return false will not be given a chance to resolve the file.
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
canRead (file) {
|
||||||
|
return url.isFileSystemPath(file.url);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the given file and returns its raw contents as a Buffer.
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
read (file) {
|
||||||
|
return new Promise(((resolve, reject) => {
|
||||||
|
let path;
|
||||||
|
try {
|
||||||
|
path = url.toFileSystemPath(file.url);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
reject(new ResolverError(ono.uri(err, `Malformed URI: ${file.url}`), file.url));
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log('Opening file: %s', path);
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.readFile(path, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
reject(new ResolverError(ono(err, `Error opening file "${path}"`), path));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
reject(new ResolverError(ono(err, `Error opening file "${path}"`), path));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
180
node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers/http.js
generated
vendored
Normal file
180
node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers/http.js
generated
vendored
Normal file
|
|
@ -0,0 +1,180 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const http = require("http");
|
||||||
|
const https = require("https");
|
||||||
|
const { ono } = require("@jsdevtools/ono");
|
||||||
|
const url = require("../util/url");
|
||||||
|
const { ResolverError } = require("../util/errors");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* The order that this resolver will run, in relation to other resolvers.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
order: 200,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP headers to send when downloading files.
|
||||||
|
*
|
||||||
|
* @example:
|
||||||
|
* {
|
||||||
|
* "User-Agent": "JSON Schema $Ref Parser",
|
||||||
|
* Accept: "application/json"
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
|
headers: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request timeout (in milliseconds).
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
timeout: 5000, // 5 seconds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum number of HTTP redirects to follow.
|
||||||
|
* To disable automatic following of redirects, set this to zero.
|
||||||
|
*
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
redirects: 5,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `withCredentials` option of XMLHttpRequest.
|
||||||
|
* Set this to `true` if you're downloading files from a CORS-enabled server that requires authentication
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
withCredentials: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this resolver can read a given file reference.
|
||||||
|
* Resolvers that return true will be tried in order, until one successfully resolves the file.
|
||||||
|
* Resolvers that return false will not be given a chance to resolve the file.
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
canRead (file) {
|
||||||
|
return url.isHttp(file.url);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the given URL and returns its raw contents as a Buffer.
|
||||||
|
*
|
||||||
|
* @param {object} file - An object containing information about the referenced file
|
||||||
|
* @param {string} file.url - The full URL of the referenced file
|
||||||
|
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
read (file) {
|
||||||
|
let u = url.parse(file.url);
|
||||||
|
|
||||||
|
if (process.browser && !u.protocol) {
|
||||||
|
// Use the protocol of the current page
|
||||||
|
u.protocol = url.parse(location.href).protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
return download(u, this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads the given file.
|
||||||
|
*
|
||||||
|
* @param {Url|string} u - The url to download (can be a parsed {@link Url} object)
|
||||||
|
* @param {object} httpOptions - The `options.resolve.http` object
|
||||||
|
* @param {number} [redirects] - The redirect URLs that have already been followed
|
||||||
|
*
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
* The promise resolves with the raw downloaded data, or rejects if there is an HTTP error.
|
||||||
|
*/
|
||||||
|
function download (u, httpOptions, redirects) {
|
||||||
|
return new Promise(((resolve, reject) => {
|
||||||
|
u = url.parse(u);
|
||||||
|
redirects = redirects || [];
|
||||||
|
redirects.push(u.href);
|
||||||
|
|
||||||
|
get(u, httpOptions)
|
||||||
|
.then((res) => {
|
||||||
|
if (res.statusCode >= 400) {
|
||||||
|
throw ono({ status: res.statusCode }, `HTTP ERROR ${res.statusCode}`);
|
||||||
|
}
|
||||||
|
else if (res.statusCode >= 300) {
|
||||||
|
if (redirects.length > httpOptions.redirects) {
|
||||||
|
reject(new ResolverError(ono({ status: res.statusCode },
|
||||||
|
`Error downloading ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`)));
|
||||||
|
}
|
||||||
|
else if (!res.headers.location) {
|
||||||
|
throw ono({ status: res.statusCode }, `HTTP ${res.statusCode} redirect with no location header`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// console.log('HTTP %d redirect %s -> %s', res.statusCode, u.href, res.headers.location);
|
||||||
|
let redirectTo = url.resolve(u, res.headers.location);
|
||||||
|
download(redirectTo, httpOptions, redirects).then(resolve, reject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve(res.body || Buffer.alloc(0));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
reject(new ResolverError(ono(err, `Error downloading ${u.href}`), u.href));
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an HTTP GET request.
|
||||||
|
*
|
||||||
|
* @param {Url} u - A parsed {@link Url} object
|
||||||
|
* @param {object} httpOptions - The `options.resolve.http` object
|
||||||
|
*
|
||||||
|
* @returns {Promise<Response>}
|
||||||
|
* The promise resolves with the HTTP Response object.
|
||||||
|
*/
|
||||||
|
function get (u, httpOptions) {
|
||||||
|
return new Promise(((resolve, reject) => {
|
||||||
|
// console.log('GET', u.href);
|
||||||
|
|
||||||
|
let protocol = u.protocol === "https:" ? https : http;
|
||||||
|
let req = protocol.get({
|
||||||
|
hostname: u.hostname,
|
||||||
|
port: u.port,
|
||||||
|
path: u.path,
|
||||||
|
auth: u.auth,
|
||||||
|
protocol: u.protocol,
|
||||||
|
headers: httpOptions.headers || {},
|
||||||
|
withCredentials: httpOptions.withCredentials
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof req.setTimeout === "function") {
|
||||||
|
req.setTimeout(httpOptions.timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
req.on("timeout", () => {
|
||||||
|
req.abort();
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on("error", reject);
|
||||||
|
|
||||||
|
req.once("response", (res) => {
|
||||||
|
res.body = Buffer.alloc(0);
|
||||||
|
|
||||||
|
res.on("data", (data) => {
|
||||||
|
res.body = Buffer.concat([res.body, Buffer.from(data)]);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on("error", reject);
|
||||||
|
|
||||||
|
res.on("end", () => {
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}
|
||||||
136
node_modules/@apidevtools/json-schema-ref-parser/lib/util/errors.js
generated
vendored
Normal file
136
node_modules/@apidevtools/json-schema-ref-parser/lib/util/errors.js
generated
vendored
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const { Ono } = require("@jsdevtools/ono");
|
||||||
|
|
||||||
|
const { stripHash, toFileSystemPath } = require("./url");
|
||||||
|
|
||||||
|
const JSONParserError = exports.JSONParserError = class JSONParserError extends Error {
|
||||||
|
constructor (message, source) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.code = "EUNKNOWN";
|
||||||
|
this.message = message;
|
||||||
|
this.source = source;
|
||||||
|
this.path = null;
|
||||||
|
|
||||||
|
Ono.extend(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
get footprint () {
|
||||||
|
return `${this.path}+${this.source}+${this.code}+${this.message}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setErrorName(JSONParserError);
|
||||||
|
|
||||||
|
const JSONParserErrorGroup = exports.JSONParserErrorGroup = class JSONParserErrorGroup extends Error {
|
||||||
|
constructor (parser) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.files = parser;
|
||||||
|
this.message = `${this.errors.length} error${this.errors.length > 1 ? "s" : ""} occurred while reading '${toFileSystemPath(parser.$refs._root$Ref.path)}'`;
|
||||||
|
|
||||||
|
Ono.extend(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static getParserErrors (parser) {
|
||||||
|
const errors = [];
|
||||||
|
|
||||||
|
for (const $ref of Object.values(parser.$refs._$refs)) {
|
||||||
|
if ($ref.errors) {
|
||||||
|
errors.push(...$ref.errors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
get errors () {
|
||||||
|
return JSONParserErrorGroup.getParserErrors(this.files);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setErrorName(JSONParserErrorGroup);
|
||||||
|
|
||||||
|
const ParserError = exports.ParserError = class ParserError extends JSONParserError {
|
||||||
|
constructor (message, source) {
|
||||||
|
super(`Error parsing ${source}: ${message}`, source);
|
||||||
|
|
||||||
|
this.code = "EPARSER";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setErrorName(ParserError);
|
||||||
|
|
||||||
|
const UnmatchedParserError = exports.UnmatchedParserError = class UnmatchedParserError extends JSONParserError {
|
||||||
|
constructor (source) {
|
||||||
|
super(`Could not find parser for "${source}"`, source);
|
||||||
|
|
||||||
|
this.code = "EUNMATCHEDPARSER";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setErrorName(UnmatchedParserError);
|
||||||
|
|
||||||
|
const ResolverError = exports.ResolverError = class ResolverError extends JSONParserError {
|
||||||
|
constructor (ex, source) {
|
||||||
|
super(ex.message || `Error reading file "${source}"`, source);
|
||||||
|
|
||||||
|
this.code = "ERESOLVER";
|
||||||
|
|
||||||
|
if ("code" in ex) {
|
||||||
|
this.ioErrorCode = String(ex.code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setErrorName(ResolverError);
|
||||||
|
|
||||||
|
const UnmatchedResolverError = exports.UnmatchedResolverError = class UnmatchedResolverError extends JSONParserError {
|
||||||
|
constructor (source) {
|
||||||
|
super(`Could not find resolver for "${source}"`, source);
|
||||||
|
|
||||||
|
this.code = "EUNMATCHEDRESOLVER";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setErrorName(UnmatchedResolverError);
|
||||||
|
|
||||||
|
const MissingPointerError = exports.MissingPointerError = class MissingPointerError extends JSONParserError {
|
||||||
|
constructor (token, path) {
|
||||||
|
super(`Token "${token}" does not exist.`, stripHash(path));
|
||||||
|
|
||||||
|
this.code = "EMISSINGPOINTER";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setErrorName(MissingPointerError);
|
||||||
|
|
||||||
|
const InvalidPointerError = exports.InvalidPointerError = class InvalidPointerError extends JSONParserError {
|
||||||
|
constructor (pointer, path) {
|
||||||
|
super(`Invalid $ref pointer "${pointer}". Pointers must begin with "#/"`, stripHash(path));
|
||||||
|
|
||||||
|
this.code = "EINVALIDPOINTER";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setErrorName(InvalidPointerError);
|
||||||
|
|
||||||
|
function setErrorName (err) {
|
||||||
|
Object.defineProperty(err.prototype, "name", {
|
||||||
|
value: err.name,
|
||||||
|
enumerable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.isHandledError = function (err) {
|
||||||
|
return err instanceof JSONParserError || err instanceof JSONParserErrorGroup;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.normalizeError = function (err) {
|
||||||
|
if (err.path === null) {
|
||||||
|
err.path = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
};
|
||||||
159
node_modules/@apidevtools/json-schema-ref-parser/lib/util/plugins.js
generated
vendored
Normal file
159
node_modules/@apidevtools/json-schema-ref-parser/lib/util/plugins.js
generated
vendored
Normal file
|
|
@ -0,0 +1,159 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the given plugins as an array, rather than an object map.
|
||||||
|
* All other methods in this module expect an array of plugins rather than an object map.
|
||||||
|
*
|
||||||
|
* @param {object} plugins - A map of plugin objects
|
||||||
|
* @return {object[]}
|
||||||
|
*/
|
||||||
|
exports.all = function (plugins) {
|
||||||
|
return Object.keys(plugins)
|
||||||
|
.filter((key) => {
|
||||||
|
return typeof plugins[key] === "object";
|
||||||
|
})
|
||||||
|
.map((key) => {
|
||||||
|
plugins[key].name = key;
|
||||||
|
return plugins[key];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the given plugins, returning only the ones return `true` for the given method.
|
||||||
|
*
|
||||||
|
* @param {object[]} plugins - An array of plugin objects
|
||||||
|
* @param {string} method - The name of the filter method to invoke for each plugin
|
||||||
|
* @param {object} file - A file info object, which will be passed to each method
|
||||||
|
* @return {object[]}
|
||||||
|
*/
|
||||||
|
exports.filter = function (plugins, method, file) {
|
||||||
|
return plugins
|
||||||
|
.filter((plugin) => {
|
||||||
|
return !!getResult(plugin, method, file);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts the given plugins, in place, by their `order` property.
|
||||||
|
*
|
||||||
|
* @param {object[]} plugins - An array of plugin objects
|
||||||
|
* @returns {object[]}
|
||||||
|
*/
|
||||||
|
exports.sort = function (plugins) {
|
||||||
|
for (let plugin of plugins) {
|
||||||
|
plugin.order = plugin.order || Number.MAX_SAFE_INTEGER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugins.sort((a, b) => { return a.order - b.order; });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the specified method of the given plugins, in order, until one of them returns a successful result.
|
||||||
|
* Each method can return a synchronous value, a Promise, or call an error-first callback.
|
||||||
|
* If the promise resolves successfully, or the callback is called without an error, then the result
|
||||||
|
* is immediately returned and no further plugins are called.
|
||||||
|
* If the promise rejects, or the callback is called with an error, then the next plugin is called.
|
||||||
|
* If ALL plugins fail, then the last error is thrown.
|
||||||
|
*
|
||||||
|
* @param {object[]} plugins - An array of plugin objects
|
||||||
|
* @param {string} method - The name of the method to invoke for each plugin
|
||||||
|
* @param {object} file - A file info object, which will be passed to each method
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
exports.run = function (plugins, method, file, $refs) {
|
||||||
|
let plugin, lastError, index = 0;
|
||||||
|
|
||||||
|
return new Promise(((resolve, reject) => {
|
||||||
|
runNextPlugin();
|
||||||
|
|
||||||
|
function runNextPlugin () {
|
||||||
|
plugin = plugins[index++];
|
||||||
|
if (!plugin) {
|
||||||
|
// There are no more functions, so re-throw the last error
|
||||||
|
return reject(lastError);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// console.log(' %s', plugin.name);
|
||||||
|
let result = getResult(plugin, method, file, callback, $refs);
|
||||||
|
if (result && typeof result.then === "function") {
|
||||||
|
// A promise was returned
|
||||||
|
result.then(onSuccess, onError);
|
||||||
|
}
|
||||||
|
else if (result !== undefined) {
|
||||||
|
// A synchronous result was returned
|
||||||
|
onSuccess(result);
|
||||||
|
}
|
||||||
|
else if (index === plugins.length) {
|
||||||
|
throw new Error("No promise has been returned or callback has been called.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
onError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function callback (err, result) {
|
||||||
|
if (err) {
|
||||||
|
onError(err);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
onSuccess(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSuccess (result) {
|
||||||
|
// console.log(' success');
|
||||||
|
resolve({
|
||||||
|
plugin,
|
||||||
|
result
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError (error) {
|
||||||
|
// console.log(' %s', err.message || err);
|
||||||
|
lastError = {
|
||||||
|
plugin,
|
||||||
|
error,
|
||||||
|
};
|
||||||
|
runNextPlugin();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the given property.
|
||||||
|
* If the property is a function, then the result of the function is returned.
|
||||||
|
* If the value is a RegExp, then it will be tested against the file URL.
|
||||||
|
* If the value is an aray, then it will be compared against the file extension.
|
||||||
|
*
|
||||||
|
* @param {object} obj - The object whose property/method is called
|
||||||
|
* @param {string} prop - The name of the property/method to invoke
|
||||||
|
* @param {object} file - A file info object, which will be passed to the method
|
||||||
|
* @param {function} [callback] - A callback function, which will be passed to the method
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
function getResult (obj, prop, file, callback, $refs) {
|
||||||
|
let value = obj[prop];
|
||||||
|
|
||||||
|
if (typeof value === "function") {
|
||||||
|
return value.apply(obj, [file, callback, $refs]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!callback) {
|
||||||
|
// The synchronous plugin functions (canParse and canRead)
|
||||||
|
// allow a "shorthand" syntax, where the user can match
|
||||||
|
// files by RegExp or by file extension.
|
||||||
|
if (value instanceof RegExp) {
|
||||||
|
return value.test(file.url);
|
||||||
|
}
|
||||||
|
else if (typeof value === "string") {
|
||||||
|
return value === file.extension;
|
||||||
|
}
|
||||||
|
else if (Array.isArray(value)) {
|
||||||
|
return value.indexOf(file.extension) !== -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
271
node_modules/@apidevtools/json-schema-ref-parser/lib/util/url.js
generated
vendored
Normal file
271
node_modules/@apidevtools/json-schema-ref-parser/lib/util/url.js
generated
vendored
Normal file
|
|
@ -0,0 +1,271 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
let isWindows = /^win/.test(process.platform),
|
||||||
|
forwardSlashPattern = /\//g,
|
||||||
|
protocolPattern = /^(\w{2,}):\/\//i,
|
||||||
|
url = module.exports,
|
||||||
|
jsonPointerSlash = /~1/g,
|
||||||
|
jsonPointerTilde = /~0/g;
|
||||||
|
|
||||||
|
// RegExp patterns to URL-encode special characters in local filesystem paths
|
||||||
|
let urlEncodePatterns = [
|
||||||
|
/\?/g, "%3F",
|
||||||
|
/\#/g, "%23",
|
||||||
|
];
|
||||||
|
|
||||||
|
// RegExp patterns to URL-decode special characters for local filesystem paths
|
||||||
|
let urlDecodePatterns = [
|
||||||
|
/\%23/g, "#",
|
||||||
|
/\%24/g, "$",
|
||||||
|
/\%26/g, "&",
|
||||||
|
/\%2C/g, ",",
|
||||||
|
/\%40/g, "@"
|
||||||
|
];
|
||||||
|
|
||||||
|
exports.parse = require("url").parse;
|
||||||
|
exports.resolve = require("url").resolve;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current working directory (in Node) or the current page URL (in browsers).
|
||||||
|
*
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
exports.cwd = function cwd () {
|
||||||
|
if (process.browser) {
|
||||||
|
return location.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = process.cwd();
|
||||||
|
|
||||||
|
let lastChar = path.slice(-1);
|
||||||
|
if (lastChar === "/" || lastChar === "\\") {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return path + "/";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the protocol of the given URL, or `undefined` if it has no protocol.
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @returns {?string}
|
||||||
|
*/
|
||||||
|
exports.getProtocol = function getProtocol (path) {
|
||||||
|
let match = protocolPattern.exec(path);
|
||||||
|
if (match) {
|
||||||
|
return match[1].toLowerCase();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the lowercased file extension of the given URL,
|
||||||
|
* or an empty string if it has no extension.
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
exports.getExtension = function getExtension (path) {
|
||||||
|
let lastDot = path.lastIndexOf(".");
|
||||||
|
if (lastDot >= 0) {
|
||||||
|
return url.stripQuery(path.substr(lastDot).toLowerCase());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the query, if any, from the given path.
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
exports.stripQuery = function stripQuery (path) {
|
||||||
|
let queryIndex = path.indexOf("?");
|
||||||
|
if (queryIndex >= 0) {
|
||||||
|
path = path.substr(0, queryIndex);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the hash (URL fragment), of the given path.
|
||||||
|
* If there is no hash, then the root hash ("#") is returned.
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
exports.getHash = function getHash (path) {
|
||||||
|
let hashIndex = path.indexOf("#");
|
||||||
|
if (hashIndex >= 0) {
|
||||||
|
return path.substr(hashIndex);
|
||||||
|
}
|
||||||
|
return "#";
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the hash (URL fragment), if any, from the given path.
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
exports.stripHash = function stripHash (path) {
|
||||||
|
let hashIndex = path.indexOf("#");
|
||||||
|
if (hashIndex >= 0) {
|
||||||
|
path = path.substr(0, hashIndex);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given path is an HTTP(S) URL.
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
exports.isHttp = function isHttp (path) {
|
||||||
|
let protocol = url.getProtocol(path);
|
||||||
|
if (protocol === "http" || protocol === "https") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (protocol === undefined) {
|
||||||
|
// There is no protocol. If we're running in a browser, then assume it's HTTP.
|
||||||
|
return process.browser;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// It's some other protocol, such as "ftp://", "mongodb://", etc.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the given path is a filesystem path.
|
||||||
|
* This includes "file://" URLs.
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
exports.isFileSystemPath = function isFileSystemPath (path) {
|
||||||
|
if (process.browser) {
|
||||||
|
// We're running in a browser, so assume that all paths are URLs.
|
||||||
|
// This way, even relative paths will be treated as URLs rather than as filesystem paths
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let protocol = url.getProtocol(path);
|
||||||
|
return protocol === undefined || protocol === "file";
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a filesystem path to a properly-encoded URL.
|
||||||
|
*
|
||||||
|
* This is intended to handle situations where JSON Schema $Ref Parser is called
|
||||||
|
* with a filesystem path that contains characters which are not allowed in URLs.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* The following filesystem paths would be converted to the following URLs:
|
||||||
|
*
|
||||||
|
* <"!@#$%^&*+=?'>.json ==> %3C%22!@%23$%25%5E&*+=%3F\'%3E.json
|
||||||
|
* C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json
|
||||||
|
* file://Project #42/file.json ==> file://Project%20%2342/file.json
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
exports.fromFileSystemPath = function fromFileSystemPath (path) {
|
||||||
|
// Step 1: On Windows, replace backslashes with forward slashes,
|
||||||
|
// rather than encoding them as "%5C"
|
||||||
|
if (isWindows) {
|
||||||
|
path = path.replace(/\\/g, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: `encodeURI` will take care of MOST characters
|
||||||
|
path = encodeURI(path);
|
||||||
|
|
||||||
|
// Step 3: Manually encode characters that are not encoded by `encodeURI`.
|
||||||
|
// This includes characters such as "#" and "?", which have special meaning in URLs,
|
||||||
|
// but are just normal characters in a filesystem path.
|
||||||
|
for (let i = 0; i < urlEncodePatterns.length; i += 2) {
|
||||||
|
path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a URL to a local filesystem path.
|
||||||
|
*
|
||||||
|
* @param {string} path
|
||||||
|
* @param {boolean} [keepFileProtocol] - If true, then "file://" will NOT be stripped
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
exports.toFileSystemPath = function toFileSystemPath (path, keepFileProtocol) {
|
||||||
|
// Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.
|
||||||
|
path = decodeURI(path);
|
||||||
|
|
||||||
|
// Step 2: Manually decode characters that are not decoded by `decodeURI`.
|
||||||
|
// This includes characters such as "#" and "?", which have special meaning in URLs,
|
||||||
|
// but are just normal characters in a filesystem path.
|
||||||
|
for (let i = 0; i < urlDecodePatterns.length; i += 2) {
|
||||||
|
path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 3: If it's a "file://" URL, then format it consistently
|
||||||
|
// or convert it to a local filesystem path
|
||||||
|
let isFileUrl = path.substr(0, 7).toLowerCase() === "file://";
|
||||||
|
if (isFileUrl) {
|
||||||
|
// Strip-off the protocol, and the initial "/", if there is one
|
||||||
|
path = path[7] === "/" ? path.substr(8) : path.substr(7);
|
||||||
|
|
||||||
|
// insert a colon (":") after the drive letter on Windows
|
||||||
|
if (isWindows && path[1] === "/") {
|
||||||
|
path = path[0] + ":" + path.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keepFileProtocol) {
|
||||||
|
// Return the consistently-formatted "file://" URL
|
||||||
|
path = "file:///" + path;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Convert the "file://" URL to a local filesystem path.
|
||||||
|
// On Windows, it will start with something like "C:/".
|
||||||
|
// On Posix, it will start with "/"
|
||||||
|
isFileUrl = false;
|
||||||
|
path = isWindows ? path : "/" + path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4: Normalize Windows paths (unless it's a "file://" URL)
|
||||||
|
if (isWindows && !isFileUrl) {
|
||||||
|
// Replace forward slashes with backslashes
|
||||||
|
path = path.replace(forwardSlashPattern, "\\");
|
||||||
|
|
||||||
|
// Capitalize the drive letter
|
||||||
|
if (path.substr(1, 2) === ":\\") {
|
||||||
|
path = path[0].toUpperCase() + path.substr(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a $ref pointer to a valid JSON Path.
|
||||||
|
*
|
||||||
|
* @param {string} pointer
|
||||||
|
* @returns {Array<number | string>}
|
||||||
|
*/
|
||||||
|
exports.safePointerToPath = function safePointerToPath (pointer) {
|
||||||
|
if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return pointer
|
||||||
|
.slice(2)
|
||||||
|
.split("/")
|
||||||
|
.map((value) => {
|
||||||
|
return decodeURIComponent(value)
|
||||||
|
.replace(jsonPointerSlash, "/")
|
||||||
|
.replace(jsonPointerTilde, "~");
|
||||||
|
});
|
||||||
|
};
|
||||||
105
node_modules/@apidevtools/json-schema-ref-parser/package.json
generated
vendored
Normal file
105
node_modules/@apidevtools/json-schema-ref-parser/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
{
|
||||||
|
"name": "@apidevtools/json-schema-ref-parser",
|
||||||
|
"version": "9.1.2",
|
||||||
|
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
|
||||||
|
"keywords": [
|
||||||
|
"json",
|
||||||
|
"schema",
|
||||||
|
"jsonschema",
|
||||||
|
"json-schema",
|
||||||
|
"json-pointer",
|
||||||
|
"$ref",
|
||||||
|
"dereference",
|
||||||
|
"resolve"
|
||||||
|
],
|
||||||
|
"author": {
|
||||||
|
"name": "James Messinger",
|
||||||
|
"url": "https://jamesmessinger.com"
|
||||||
|
},
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Boris Cherny",
|
||||||
|
"email": "boris@performancejs.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jakub Rożek",
|
||||||
|
"email": "jakub@stoplight.io"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"homepage": "https://apitools.dev/json-schema-ref-parser/",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/APIDevTools/json-schema-ref-parser.git"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"typings": "lib/index.d.ts",
|
||||||
|
"browser": {
|
||||||
|
"fs": false
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"build": "cp LICENSE *.md dist",
|
||||||
|
"clean": "shx rm -rf .nyc_output coverage",
|
||||||
|
"lint": "eslint lib test/fixtures test/specs",
|
||||||
|
"test": "npm run test:node && npm run test:typescript && npm run test:browser && npm run lint",
|
||||||
|
"test:node": "mocha",
|
||||||
|
"test:browser": "karma start --single-run",
|
||||||
|
"test:typescript": "tsc --noEmit --strict --lib esnext,dom test/specs/typescript-definition.spec.ts",
|
||||||
|
"coverage": "npm run coverage:node && npm run coverage:browser",
|
||||||
|
"coverage:node": "nyc node_modules/mocha/bin/mocha",
|
||||||
|
"coverage:browser": "npm run test:browser -- --coverage",
|
||||||
|
"upgrade": "npm-check -u && npm audit fix"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/polyfill": "^7.12.1",
|
||||||
|
"@jsdevtools/eslint-config": "^1.0.7",
|
||||||
|
"@jsdevtools/host-environment": "^2.1.2",
|
||||||
|
"@jsdevtools/karma-config": "^3.1.7",
|
||||||
|
"@types/node": "^14.14.21",
|
||||||
|
"chai": "^4.2.0",
|
||||||
|
"chai-subset": "^1.6.0",
|
||||||
|
"eslint": "^7.18.0",
|
||||||
|
"karma": "^5.0.2",
|
||||||
|
"karma-cli": "^2.0.0",
|
||||||
|
"mocha": "^8.2.1",
|
||||||
|
"npm-check": "^5.9.0",
|
||||||
|
"nyc": "^15.0.1",
|
||||||
|
"semantic-release-plugin-update-version-in-files": "^1.1.0",
|
||||||
|
"shx": "^0.3.2",
|
||||||
|
"typescript": "^4.0.5"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@jsdevtools/ono": "^7.1.3",
|
||||||
|
"@types/json-schema": "^7.0.6",
|
||||||
|
"call-me-maybe": "^1.0.1",
|
||||||
|
"js-yaml": "^4.1.0"
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"branches": [
|
||||||
|
"main",
|
||||||
|
"v9",
|
||||||
|
{
|
||||||
|
"name": "v9.1.x",
|
||||||
|
"range": "9.1.x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"@semantic-release/commit-analyzer",
|
||||||
|
"@semantic-release/release-notes-generator",
|
||||||
|
[
|
||||||
|
"semantic-release-plugin-update-version-in-files",
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"dist/package.json"
|
||||||
|
],
|
||||||
|
"placeholder": "X.X.X"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@semantic-release/npm",
|
||||||
|
"@semantic-release/github"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
20
node_modules/@apidevtools/openapi-schemas/CHANGELOG.md
generated
vendored
Normal file
20
node_modules/@apidevtools/openapi-schemas/CHANGELOG.md
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
Change Log
|
||||||
|
====================================================================================================
|
||||||
|
All notable changes will be documented in this file.
|
||||||
|
OpenAPI Schemas adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
[v2.0.0](https://github.com/APIDevTools/openapi-schemas/tree/v2.0.0) (2020-03-10)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Moved OpenAPI Schemas to the [@APIDevTools scope](https://www.npmjs.com/org/apidevtools) on NPM
|
||||||
|
|
||||||
|
- The "openapi-schemas" NPM package is now just a wrapper around the scoped "@apidevtools/openapi-schemas" package
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/openapi-schemas/compare/v1.0.3...v2.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
[v1.0.0](https://github.com/APIDevTools/openapi-schemas/tree/v1.0.0) (2019-06-22)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Initial release 🎉
|
||||||
21
node_modules/@apidevtools/openapi-schemas/LICENSE
generated
vendored
Normal file
21
node_modules/@apidevtools/openapi-schemas/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2019 James Messinger
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
116
node_modules/@apidevtools/openapi-schemas/README.md
generated
vendored
Normal file
116
node_modules/@apidevtools/openapi-schemas/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
# OpenAPI Specification Schemas
|
||||||
|
|
||||||
|
[](https://github.com/APIDevTools/openapi-schemas/actions)
|
||||||
|
[](https://github.com/APIDevTools/openapi-schemas/actions)
|
||||||
|
|
||||||
|
[](https://coveralls.io/github/APIDevTools/openapi-schemas)
|
||||||
|
[](https://david-dm.org/APIDevTools/openapi-schemas)
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/@apidevtools/openapi-schemas)
|
||||||
|
[](LICENSE)
|
||||||
|
[](https://plant.treeware.earth/APIDevTools/openapi-schemas)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
This package contains [**the official JSON Schemas**](https://github.com/OAI/OpenAPI-Specification/tree/master/schemas) for every version of Swagger/OpenAPI Specification:
|
||||||
|
|
||||||
|
| Version | Schema | Docs
|
||||||
|
|---------|--------|-------
|
||||||
|
| Swagger 1.2 | [v1.2 schema](https://github.com/OAI/OpenAPI-Specification/tree/master/schemas/v1.2) | [v1.2 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/1.2.md)
|
||||||
|
| Swagger 2.0 | [v2.0 schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json) | [v2.0 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md)
|
||||||
|
| OpenAPI 3.0.x | [v3.0.x schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.json) | [v3.0.3 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md)
|
||||||
|
| OpenAPI 3.1.x | [v3.1.x schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.1/schema.json) | [v3.1.0 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md)
|
||||||
|
|
||||||
|
|
||||||
|
All schemas are kept up-to-date with the latest official definitions via an automated CI/CD job. 🤖📦
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
--------------------------
|
||||||
|
You can install OpenAPI Schemas via [npm](https://docs.npmjs.com/about-npm/).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install @apidevtools/openapi-schemas
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
The default export contains all OpenAPI Specification versions:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const openapi = require("@apidevtools/openapi-schemas");
|
||||||
|
|
||||||
|
console.log(openapi.v1); // { $schema, id, properties, definitions, ... }
|
||||||
|
console.log(openapi.v2); // { $schema, id, properties, definitions, ... }
|
||||||
|
console.log(openapi.v3); // { $schema, id, properties, definitions, ... }
|
||||||
|
console.log(openapi.v31); // { $schema, id, properties, definitions, ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
Or you can import the specific version(s) that you need:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { openapiV1, openapiV2, openapiV3, openapiV31 } = require("@apidevtools/openapi-schemas");
|
||||||
|
|
||||||
|
console.log(openapiV1); // { $schema, id, properties, definitions, ... }
|
||||||
|
console.log(openapiV2); // { $schema, id, properties, definitions, ... }
|
||||||
|
console.log(openapiV3); // { $schema, id, properties, definitions, ... }
|
||||||
|
console.log(openapiV31); // { $schema, id, properties, definitions, ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use a JSON Schema validator such as [Z-Schema](https://www.npmjs.com/package/z-schema) or [AJV](https://www.npmjs.com/package/ajv) to validate OpenAPI definitions against the specification.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { openapiV31 } = require("@apidevtools/openapi-schemas");
|
||||||
|
const ZSchema = require("z-schema");
|
||||||
|
|
||||||
|
// Create a ZSchema validator
|
||||||
|
let validator = new ZSchema();
|
||||||
|
|
||||||
|
// Validate an OpenAPI definition against the OpenAPI v3.0 specification
|
||||||
|
validator.validate(openapiDefinition, openapiV31);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
--------------------------
|
||||||
|
Contributions, enhancements, and bug-fixes are welcome! [Open an issue](https://github.com/APIDevTools/openapi-schemas/issues) on GitHub and [submit a pull request](https://github.com/APIDevTools/openapi-schemas/pulls).
|
||||||
|
|
||||||
|
#### Building
|
||||||
|
To build the project locally on your computer:
|
||||||
|
|
||||||
|
1. __Clone this repo__<br>
|
||||||
|
`git clone https://github.com/APIDevTools/openapi-schemas.git`
|
||||||
|
|
||||||
|
2. __Install dependencies__<br>
|
||||||
|
`npm install`
|
||||||
|
|
||||||
|
3. __Build the code__<br>
|
||||||
|
`npm run build`
|
||||||
|
|
||||||
|
4. __Run the tests__<br>
|
||||||
|
`npm test`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
License
|
||||||
|
--------------------------
|
||||||
|
OpenAPI Schemas 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/openapi-schemas) 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
|
||||||
|
--------------------------
|
||||||
|
Thanks to these awesome companies for their support of Open Source developers ❤
|
||||||
|
|
||||||
|
[](https://github.com/open-source)
|
||||||
|
[](https://www.npmjs.com/)
|
||||||
|
[](https://coveralls.io)
|
||||||
|
[](https://travis-ci.com)
|
||||||
|
[](https://saucelabs.com)
|
||||||
28
node_modules/@apidevtools/openapi-schemas/lib/index.d.ts
generated
vendored
Normal file
28
node_modules/@apidevtools/openapi-schemas/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { JsonSchemaDraft4, JsonSchemaDraft202012 } from "./json-schema";
|
||||||
|
export { JsonSchemaDraft4, JsonSchemaDraft202012 };
|
||||||
|
/**
|
||||||
|
* JSON Schema for OpenAPI Specification v1.2
|
||||||
|
*/
|
||||||
|
export declare const openapiV1: JsonSchemaDraft4;
|
||||||
|
/**
|
||||||
|
* JSON Schema for OpenAPI Specification v2.0
|
||||||
|
*/
|
||||||
|
export declare const openapiV2: JsonSchemaDraft4;
|
||||||
|
/**
|
||||||
|
* JSON Schema for OpenAPI Specification v3.0
|
||||||
|
*/
|
||||||
|
export declare const openapiV3: JsonSchemaDraft4;
|
||||||
|
/**
|
||||||
|
* JSON Schema for OpenAPI Specification v3.1
|
||||||
|
*/
|
||||||
|
export declare const openapiV31: JsonSchemaDraft202012;
|
||||||
|
/**
|
||||||
|
* JSON Schemas for every version of the OpenAPI Specification
|
||||||
|
*/
|
||||||
|
export declare const openapi: {
|
||||||
|
v1: JsonSchemaDraft4;
|
||||||
|
v2: JsonSchemaDraft4;
|
||||||
|
v3: JsonSchemaDraft4;
|
||||||
|
v31: JsonSchemaDraft202012;
|
||||||
|
};
|
||||||
|
export default openapi;
|
||||||
36
node_modules/@apidevtools/openapi-schemas/lib/index.js
generated
vendored
Normal file
36
node_modules/@apidevtools/openapi-schemas/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.openapi = exports.openapiV31 = exports.openapiV3 = exports.openapiV2 = exports.openapiV1 = void 0;
|
||||||
|
/**
|
||||||
|
* JSON Schema for OpenAPI Specification v1.2
|
||||||
|
*/
|
||||||
|
exports.openapiV1 = require("../schemas/v1.2/apiDeclaration.json");
|
||||||
|
/**
|
||||||
|
* JSON Schema for OpenAPI Specification v2.0
|
||||||
|
*/
|
||||||
|
exports.openapiV2 = require("../schemas/v2.0/schema.json");
|
||||||
|
/**
|
||||||
|
* JSON Schema for OpenAPI Specification v3.0
|
||||||
|
*/
|
||||||
|
exports.openapiV3 = require("../schemas/v3.0/schema.json");
|
||||||
|
/**
|
||||||
|
* JSON Schema for OpenAPI Specification v3.1
|
||||||
|
*/
|
||||||
|
exports.openapiV31 = require("../schemas/v3.1/schema.json");
|
||||||
|
/**
|
||||||
|
* JSON Schemas for every version of the OpenAPI Specification
|
||||||
|
*/
|
||||||
|
exports.openapi = {
|
||||||
|
v1: exports.openapiV1,
|
||||||
|
v2: exports.openapiV2,
|
||||||
|
v3: exports.openapiV3,
|
||||||
|
v31: exports.openapiV31,
|
||||||
|
};
|
||||||
|
// Export `openapi` as the default export
|
||||||
|
exports.default = exports.openapi;
|
||||||
|
// CommonJS default export hack
|
||||||
|
/* eslint-env commonjs */
|
||||||
|
if (typeof module === "object" && typeof module.exports === "object") {
|
||||||
|
module.exports = Object.assign(module.exports.default, module.exports);
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=index.js.map
|
||||||
1
node_modules/@apidevtools/openapi-schemas/lib/index.js.map
generated
vendored
Normal file
1
node_modules/@apidevtools/openapi-schemas/lib/index.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACU,QAAA,SAAS,GAAG,OAAO,CAAC,qCAAqC,CAAqB,CAAC;AAE5F;;GAEG;AACU,QAAA,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAqB,CAAC;AAEpF;;GAEG;AACU,QAAA,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAqB,CAAC;AAEpF;;GAEG;AACU,QAAA,UAAU,GAAG,OAAO,CAAC,6BAA6B,CAA0B,CAAC;AAE1F;;GAEG;AACU,QAAA,OAAO,GAAG;IACrB,EAAE,EAAE,iBAAS;IACb,EAAE,EAAE,iBAAS;IACb,EAAE,EAAE,iBAAS;IACb,GAAG,EAAE,kBAAU;CAChB,CAAC;AAEF,yCAAyC;AACzC,kBAAe,eAAO,CAAC;AAEvB,+BAA+B;AAC/B,yBAAyB;AACzB,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE;IACpE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACxE"}
|
||||||
88
node_modules/@apidevtools/openapi-schemas/lib/json-schema.d.ts
generated
vendored
Normal file
88
node_modules/@apidevtools/openapi-schemas/lib/json-schema.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
/**
|
||||||
|
* A JSON Schema 4.0 definition for an OpenAPI Specification
|
||||||
|
*/
|
||||||
|
export interface JsonSchemaDraft4 {
|
||||||
|
id?: string;
|
||||||
|
$schema?: string;
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
multipleOf?: number;
|
||||||
|
maximum?: number;
|
||||||
|
exclusiveMaximum?: boolean;
|
||||||
|
minimum?: number;
|
||||||
|
exclusiveMinimum?: boolean;
|
||||||
|
maxLength?: number;
|
||||||
|
minLength?: number;
|
||||||
|
pattern?: string;
|
||||||
|
additionalItems?: boolean | JsonSchemaDraft4;
|
||||||
|
items?: JsonSchemaDraft4 | JsonSchemaDraft4[];
|
||||||
|
maxItems?: number;
|
||||||
|
minItems?: number;
|
||||||
|
uniqueItems?: boolean;
|
||||||
|
maxProperties?: number;
|
||||||
|
minProperties?: number;
|
||||||
|
required?: string[];
|
||||||
|
additionalProperties?: boolean | JsonSchemaDraft4;
|
||||||
|
definitions?: {
|
||||||
|
[name: string]: JsonSchemaDraft4;
|
||||||
|
};
|
||||||
|
properties?: {
|
||||||
|
[name: string]: JsonSchemaDraft4;
|
||||||
|
};
|
||||||
|
patternProperties?: {
|
||||||
|
[name: string]: JsonSchemaDraft4;
|
||||||
|
};
|
||||||
|
dependencies?: {
|
||||||
|
[name: string]: JsonSchemaDraft4 | string[];
|
||||||
|
};
|
||||||
|
enum?: string[];
|
||||||
|
type?: string | string[];
|
||||||
|
allOf?: JsonSchemaDraft4[];
|
||||||
|
anyOf?: JsonSchemaDraft4[];
|
||||||
|
oneOf?: JsonSchemaDraft4[];
|
||||||
|
not?: JsonSchemaDraft4;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* A JSON Schema 2020-12 definition for an OpenAPI Specification
|
||||||
|
*/
|
||||||
|
export interface JsonSchemaDraft202012 {
|
||||||
|
$id?: string;
|
||||||
|
$schema?: string;
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
multipleOf?: number;
|
||||||
|
maximum?: number;
|
||||||
|
exclusiveMaximum?: boolean;
|
||||||
|
minimum?: number;
|
||||||
|
exclusiveMinimum?: boolean;
|
||||||
|
maxLength?: number;
|
||||||
|
minLength?: number;
|
||||||
|
pattern?: string;
|
||||||
|
additionalItems?: boolean | JsonSchemaDraft202012;
|
||||||
|
items?: JsonSchemaDraft202012 | JsonSchemaDraft202012[];
|
||||||
|
maxItems?: number;
|
||||||
|
minItems?: number;
|
||||||
|
uniqueItems?: boolean;
|
||||||
|
maxProperties?: number;
|
||||||
|
minProperties?: number;
|
||||||
|
required?: string[];
|
||||||
|
additionalProperties?: boolean | JsonSchemaDraft202012;
|
||||||
|
$defs?: {
|
||||||
|
[name: string]: JsonSchemaDraft202012;
|
||||||
|
};
|
||||||
|
properties?: {
|
||||||
|
[name: string]: JsonSchemaDraft202012;
|
||||||
|
};
|
||||||
|
patternProperties?: {
|
||||||
|
[name: string]: JsonSchemaDraft202012;
|
||||||
|
};
|
||||||
|
dependencies?: {
|
||||||
|
[name: string]: JsonSchemaDraft202012 | string[];
|
||||||
|
};
|
||||||
|
enum?: string[];
|
||||||
|
type?: string | string[];
|
||||||
|
allOf?: JsonSchemaDraft202012[];
|
||||||
|
anyOf?: JsonSchemaDraft202012[];
|
||||||
|
oneOf?: JsonSchemaDraft202012[];
|
||||||
|
not?: JsonSchemaDraft202012;
|
||||||
|
}
|
||||||
3
node_modules/@apidevtools/openapi-schemas/lib/json-schema.js
generated
vendored
Normal file
3
node_modules/@apidevtools/openapi-schemas/lib/json-schema.js
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
//# sourceMappingURL=json-schema.js.map
|
||||||
1
node_modules/@apidevtools/openapi-schemas/lib/json-schema.js.map
generated
vendored
Normal file
1
node_modules/@apidevtools/openapi-schemas/lib/json-schema.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":""}
|
||||||
66
node_modules/@apidevtools/openapi-schemas/package.json
generated
vendored
Normal file
66
node_modules/@apidevtools/openapi-schemas/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
{
|
||||||
|
"name": "@apidevtools/openapi-schemas",
|
||||||
|
"version": "2.1.0",
|
||||||
|
"description": "JSON Schemas for every version of the OpenAPI Specification",
|
||||||
|
"keywords": [
|
||||||
|
"openapi",
|
||||||
|
"open-api",
|
||||||
|
"swagger",
|
||||||
|
"oas",
|
||||||
|
"api",
|
||||||
|
"rest",
|
||||||
|
"json",
|
||||||
|
"specification",
|
||||||
|
"definition",
|
||||||
|
"schema"
|
||||||
|
],
|
||||||
|
"author": {
|
||||||
|
"name": "James Messinger",
|
||||||
|
"url": "https://jamesmessinger.com"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"homepage": "https://apitools.dev/openapi-schemas",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/APIDevTools/openapi-schemas.git"
|
||||||
|
},
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"types": "lib/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"lib",
|
||||||
|
"schemas"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"clean": "shx rm -rf .nyc_output coverage lib .tmp schemas",
|
||||||
|
"clone": "git clone https://github.com/OAI/OpenAPI-Specification.git .tmp",
|
||||||
|
"copy": "shx cp -r .tmp/schemas schemas",
|
||||||
|
"lint": "eslint src test",
|
||||||
|
"build": "npm run build:schemas && npm run build:typescript",
|
||||||
|
"build:schemas": "npm run clean && npm run clone && npm run copy",
|
||||||
|
"build:typescript": "tsc",
|
||||||
|
"watch": "tsc --watch",
|
||||||
|
"test": "mocha && npm run lint",
|
||||||
|
"coverage": "nyc node_modules/mocha/bin/mocha",
|
||||||
|
"upgrade": "npm-check -u && npm audit fix",
|
||||||
|
"bump": "bump --tag --push --all",
|
||||||
|
"release": "npm run upgrade && npm run clean && npm run build && npm test && npm run bump"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@jsdevtools/eslint-config": "^1.1.4",
|
||||||
|
"@jsdevtools/version-bump-prompt": "^6.1.0",
|
||||||
|
"@types/chai": "^4.2.17",
|
||||||
|
"@types/command-line-args": "^5.0.0",
|
||||||
|
"@types/mocha": "^8.2.2",
|
||||||
|
"@types/node": "^15.0.1",
|
||||||
|
"chai": "^4.3.4",
|
||||||
|
"eslint": "^7.25.0",
|
||||||
|
"mocha": "^8.3.2",
|
||||||
|
"npm-check": "^5.9.2",
|
||||||
|
"nyc": "^15.1.0",
|
||||||
|
"shx": "^0.3.3",
|
||||||
|
"typescript": "^4.2.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/README.md
generated
vendored
Normal file
5
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Swagger Specification JSON Schemas
|
||||||
|
|
||||||
|
The work on the JSON Schema for the Swagger Specification was donated to the community by [Francis Galiegue](https://github.com/fge)!
|
||||||
|
|
||||||
|
Keep in mind that due to some JSON Schema limitations, not all constraints can be described. The missing constraints will be listed here in the future.
|
||||||
61
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/apiDeclaration.json
generated
vendored
Normal file
61
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/apiDeclaration.json
generated
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/apiDeclaration.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "swaggerVersion", "basePath", "apis" ],
|
||||||
|
"properties": {
|
||||||
|
"swaggerVersion": { "enum": [ "1.2" ] },
|
||||||
|
"apiVersion": { "type": "string" },
|
||||||
|
"basePath": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uri",
|
||||||
|
"pattern": "^https?://"
|
||||||
|
},
|
||||||
|
"resourcePath": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uri",
|
||||||
|
"pattern": "^/"
|
||||||
|
},
|
||||||
|
"apis": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "#/definitions/apiObject" }
|
||||||
|
},
|
||||||
|
"models": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"$ref": "modelsObject.json#"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"produces": { "$ref": "#/definitions/mimeTypeArray" },
|
||||||
|
"consumes": { "$ref": "#/definitions/mimeTypeArray" },
|
||||||
|
"authorizations": { "$ref": "authorizationObject.json#" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"definitions": {
|
||||||
|
"apiObject": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "path", "operations" ],
|
||||||
|
"properties": {
|
||||||
|
"path": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uri-template",
|
||||||
|
"pattern": "^/"
|
||||||
|
},
|
||||||
|
"description": { "type": "string" },
|
||||||
|
"operations": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "operationObject.json#" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"mimeTypeArray": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "mime-type"
|
||||||
|
},
|
||||||
|
"uniqueItems": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
59
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/authorizationObject.json
generated
vendored
Normal file
59
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/authorizationObject.json
generated
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/authorizationObject.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/basicAuth"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/apiKey"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/oauth2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"basicAuth": {
|
||||||
|
"required": [ "type" ],
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "basicAuth" ] }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"apiKey": {
|
||||||
|
"required": [ "type", "passAs", "keyname" ],
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "apiKey" ] },
|
||||||
|
"passAs": { "enum": [ "header", "query" ] },
|
||||||
|
"keyname": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"oauth2": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "type", "grantTypes" ],
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "oauth2" ] },
|
||||||
|
"scopes": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "#/definitions/oauth2Scope" }
|
||||||
|
},
|
||||||
|
"grantTypes": { "$ref": "oauth2GrantType.json#" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"oauth2Scope": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "scope" ],
|
||||||
|
"properties": {
|
||||||
|
"scope": { "type": "string" },
|
||||||
|
"description": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
132
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/dataType.json
generated
vendored
Normal file
132
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/dataType.json
generated
vendored
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/dataType.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"description": "Data type as described by the specification (version 1.2)",
|
||||||
|
"type": "object",
|
||||||
|
"oneOf": [
|
||||||
|
{ "$ref": "#/definitions/refType" },
|
||||||
|
{ "$ref": "#/definitions/voidType" },
|
||||||
|
{ "$ref": "#/definitions/primitiveType" },
|
||||||
|
{ "$ref": "#/definitions/modelType" },
|
||||||
|
{ "$ref": "#/definitions/arrayType" }
|
||||||
|
],
|
||||||
|
"definitions": {
|
||||||
|
"refType": {
|
||||||
|
"required": [ "$ref" ],
|
||||||
|
"properties": {
|
||||||
|
"$ref": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"voidType": {
|
||||||
|
"enum": [ { "type": "void" } ]
|
||||||
|
},
|
||||||
|
"modelType": {
|
||||||
|
"required": [ "type" ],
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
"not": {
|
||||||
|
"enum": [ "boolean", "integer", "number", "string", "array" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"primitiveType": {
|
||||||
|
"required": [ "type" ],
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"enum": [ "boolean", "integer", "number", "string" ]
|
||||||
|
},
|
||||||
|
"format": { "type": "string" },
|
||||||
|
"defaultValue": {
|
||||||
|
"not": { "type": [ "array", "object", "null" ] }
|
||||||
|
},
|
||||||
|
"enum": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "type": "string" },
|
||||||
|
"minItems": 1,
|
||||||
|
"uniqueItems": true
|
||||||
|
},
|
||||||
|
"minimum": { "type": "string" },
|
||||||
|
"maximum": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"dependencies": {
|
||||||
|
"format": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "integer" ] },
|
||||||
|
"format": { "enum": [ "int32", "int64" ] }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "number" ] },
|
||||||
|
"format": { "enum": [ "float", "double" ] }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "string" ] },
|
||||||
|
"format": {
|
||||||
|
"enum": [ "byte", "date", "date-time" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"enum": {
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "string" ] }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minimum": {
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "integer", "number" ] }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"maximum": {
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "integer", "number" ] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"arrayType": {
|
||||||
|
"required": [ "type", "items" ],
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "array" ] },
|
||||||
|
"items": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "#/definitions/itemsObject" }
|
||||||
|
},
|
||||||
|
"uniqueItems": { "type": "boolean" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"itemsObject": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/refType"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/primitiveType"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": {},
|
||||||
|
"format": {}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
81
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/dataTypeBase.json
generated
vendored
Normal file
81
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/dataTypeBase.json
generated
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/dataTypeBase.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"description": "Data type fields (section 4.3.3)",
|
||||||
|
"type": "object",
|
||||||
|
"oneOf": [
|
||||||
|
{ "required": [ "type" ] },
|
||||||
|
{ "required": [ "$ref" ] }
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"type": { "type": "string" },
|
||||||
|
"$ref": { "type": "string" },
|
||||||
|
"format": { "type": "string" },
|
||||||
|
"defaultValue": {
|
||||||
|
"not": { "type": [ "array", "object", "null" ] }
|
||||||
|
},
|
||||||
|
"enum": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "type": "string" },
|
||||||
|
"uniqueItems": true,
|
||||||
|
"minItems": 1
|
||||||
|
},
|
||||||
|
"minimum": { "type": "string" },
|
||||||
|
"maximum": { "type": "string" },
|
||||||
|
"items": { "$ref": "#/definitions/itemsObject" },
|
||||||
|
"uniqueItems": { "type": "boolean" }
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"format": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "integer" ] },
|
||||||
|
"format": { "enum": [ "int32", "int64" ] }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "number" ] },
|
||||||
|
"format": { "enum": [ "float", "double" ] }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "string" ] },
|
||||||
|
"format": {
|
||||||
|
"enum": [ "byte", "date", "date-time" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"itemsObject": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "$ref" ],
|
||||||
|
"properties": {
|
||||||
|
"$ref": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"allOf": [
|
||||||
|
{ "$ref": "#" },
|
||||||
|
{
|
||||||
|
"required": [ "type" ],
|
||||||
|
"properties": {
|
||||||
|
"type": {},
|
||||||
|
"format": {}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/infoObject.json
generated
vendored
Normal file
16
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/infoObject.json
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/infoObject.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"description": "info object (section 5.1.3)",
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "title", "description" ],
|
||||||
|
"properties": {
|
||||||
|
"title": { "type": "string" },
|
||||||
|
"description": { "type": "string" },
|
||||||
|
"termsOfServiceUrl": { "type": "string", "format": "uri" },
|
||||||
|
"contact": { "type": "string", "format": "email" },
|
||||||
|
"license": { "type": "string" },
|
||||||
|
"licenseUrl": { "type": "string", "format": "uri" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
36
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/modelsObject.json
generated
vendored
Normal file
36
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/modelsObject.json
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/modelsObject.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "id", "properties" ],
|
||||||
|
"properties": {
|
||||||
|
"id": { "type": "string" },
|
||||||
|
"description": { "type": "string" },
|
||||||
|
"properties": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": { "$ref": "#/definitions/propertyObject" }
|
||||||
|
},
|
||||||
|
"subTypes": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "type": "string" },
|
||||||
|
"uniqueItems": true
|
||||||
|
},
|
||||||
|
"discriminator": { "type": "string" }
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"subTypes": [ "discriminator" ]
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"propertyObject": {
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"not": { "$ref": "#" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "dataTypeBase.json#"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
57
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/oauth2GrantType.json
generated
vendored
Normal file
57
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/oauth2GrantType.json
generated
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/oauth2GrantType.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"minProperties": 1,
|
||||||
|
"properties": {
|
||||||
|
"implicit": { "$ref": "#/definitions/implicit" },
|
||||||
|
"authorization_code": { "$ref": "#/definitions/authorizationCode" }
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"implicit": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "loginEndpoint" ],
|
||||||
|
"properties": {
|
||||||
|
"loginEndpoint": { "$ref": "#/definitions/loginEndpoint" },
|
||||||
|
"tokenName": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"authorizationCode": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "tokenEndpoint", "tokenRequestEndpoint" ],
|
||||||
|
"properties": {
|
||||||
|
"tokenEndpoint": { "$ref": "#/definitions/tokenEndpoint" },
|
||||||
|
"tokenRequestEndpoint": { "$ref": "#/definitions/tokenRequestEndpoint" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"loginEndpoint": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "url" ],
|
||||||
|
"properties": {
|
||||||
|
"url": { "type": "string", "format": "uri" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"tokenEndpoint": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "url" ],
|
||||||
|
"properties": {
|
||||||
|
"url": { "type": "string", "format": "uri" },
|
||||||
|
"tokenName": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"tokenRequestEndpoint": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "url" ],
|
||||||
|
"properties": {
|
||||||
|
"url": { "type": "string", "format": "uri" },
|
||||||
|
"clientIdName": { "type": "string" },
|
||||||
|
"clientSecretName": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/operationObject.json
generated
vendored
Normal file
65
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/operationObject.json
generated
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/operationObject.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"allOf": [
|
||||||
|
{ "$ref": "dataTypeBase.json#" },
|
||||||
|
{
|
||||||
|
"required": [ "method", "nickname", "parameters" ],
|
||||||
|
"properties": {
|
||||||
|
"method": { "enum": [ "GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS" ] },
|
||||||
|
"summary": { "type": "string", "maxLength": 120 },
|
||||||
|
"notes": { "type": "string" },
|
||||||
|
"nickname": {
|
||||||
|
"type": "string",
|
||||||
|
"pattern": "^[a-zA-Z0-9_]+$"
|
||||||
|
},
|
||||||
|
"authorizations": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "authorizationObject.json#/definitions/oauth2Scope"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parameters": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "parameterObject.json#" }
|
||||||
|
},
|
||||||
|
"responseMessages": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "#/definitions/responseMessageObject"}
|
||||||
|
},
|
||||||
|
"produces": { "$ref": "#/definitions/mimeTypeArray" },
|
||||||
|
"consumes": { "$ref": "#/definitions/mimeTypeArray" },
|
||||||
|
"deprecated": { "enum": [ "true", "false" ] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"definitions": {
|
||||||
|
"responseMessageObject": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "code", "message" ],
|
||||||
|
"properties": {
|
||||||
|
"code": { "$ref": "#/definitions/rfc2616section10" },
|
||||||
|
"message": { "type": "string" },
|
||||||
|
"responseModel": { "type": "string" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rfc2616section10": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 100,
|
||||||
|
"maximum": 600,
|
||||||
|
"exclusiveMaximum": true
|
||||||
|
},
|
||||||
|
"mimeTypeArray": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "mime-type"
|
||||||
|
},
|
||||||
|
"uniqueItems": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/parameterObject.json
generated
vendored
Normal file
37
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/parameterObject.json
generated
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/parameterObject.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"allOf": [
|
||||||
|
{ "$ref": "dataTypeBase.json#" },
|
||||||
|
{
|
||||||
|
"required": [ "paramType", "name" ],
|
||||||
|
"properties": {
|
||||||
|
"paramType": {
|
||||||
|
"enum": [ "path", "query", "body", "header", "form" ]
|
||||||
|
},
|
||||||
|
"name": { "type": "string" },
|
||||||
|
"description": { "type": "string" },
|
||||||
|
"required": { "type": "boolean" },
|
||||||
|
"allowMultiple": { "type": "boolean" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "type File requires special paramType and consumes",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": { "not": { "enum": [ "File" ] } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"type": { "enum": [ "File" ] },
|
||||||
|
"paramType": { "enum": [ "form" ] },
|
||||||
|
"consumes": { "enum": [ "multipart/form-data" ] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
16
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/resourceListing.json
generated
vendored
Normal file
16
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/resourceListing.json
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/resourceListing.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "swaggerVersion", "apis" ],
|
||||||
|
"properties": {
|
||||||
|
"swaggerVersion": { "enum": [ "1.2" ] },
|
||||||
|
"apis": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "resourceObject.json#" }
|
||||||
|
},
|
||||||
|
"apiVersion": { "type": "string" },
|
||||||
|
"info": { "$ref": "infoObject.json#" },
|
||||||
|
"authorizations": { "$ref": "authorizationObject.json#" }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/resourceObject.json
generated
vendored
Normal file
11
node_modules/@apidevtools/openapi-schemas/schemas/v1.2/resourceObject.json
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"id": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v1.2/resourceObject.json#",
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"required": [ "path" ],
|
||||||
|
"properties": {
|
||||||
|
"path": { "type": "string", "format": "uri" },
|
||||||
|
"description": { "type": "string" }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
13
node_modules/@apidevtools/openapi-schemas/schemas/v2.0/README.md
generated
vendored
Normal file
13
node_modules/@apidevtools/openapi-schemas/schemas/v2.0/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
# OpenAPI Specification v2.0 JSON Schema
|
||||||
|
|
||||||
|
This is the JSON Schema file for the OpenAPI Specification version 2.0. Download and install it via NPM.
|
||||||
|
|
||||||
|
## Install via NPM
|
||||||
|
|
||||||
|
```shell
|
||||||
|
npm install --save swagger-schema-official
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Apache-2.0
|
||||||
1607
node_modules/@apidevtools/openapi-schemas/schemas/v2.0/schema.json
generated
vendored
Normal file
1607
node_modules/@apidevtools/openapi-schemas/schemas/v2.0/schema.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
16
node_modules/@apidevtools/openapi-schemas/schemas/v3.0/README.md
generated
vendored
Normal file
16
node_modules/@apidevtools/openapi-schemas/schemas/v3.0/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
OpenAPI 3.0.X JSON Schema
|
||||||
|
---
|
||||||
|
|
||||||
|
Here you can find the JSON Schema for validating OpenAPI definitions of versions 3.0.X.
|
||||||
|
|
||||||
|
As a reminder, the JSON Schema is not the source of truth for the Specification. In cases of conflicts between the Specification itself and the JSON Schema, the Specification wins. Also, some Specification constraints cannot be represented with the JSON Schema so it's highly recommended to employ other methods to ensure compliance.
|
||||||
|
|
||||||
|
The iteration version of the JSON Schema can be found in the `id` field. For example, the value of `id: https://spec.openapis.org/oas/3.0/schema/2019-04-02` means this iteration was created on April 2nd, 2019.
|
||||||
|
|
||||||
|
To submit improvements to the schema, modify the schema.yaml file only.
|
||||||
|
|
||||||
|
The TSC will then:
|
||||||
|
- Run tests on the updated schema
|
||||||
|
- Update the iteration version
|
||||||
|
- Convert the schema.yaml to schema.json
|
||||||
|
- Publish the new version
|
||||||
1654
node_modules/@apidevtools/openapi-schemas/schemas/v3.0/schema.json
generated
vendored
Normal file
1654
node_modules/@apidevtools/openapi-schemas/schemas/v3.0/schema.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1003
node_modules/@apidevtools/openapi-schemas/schemas/v3.0/schema.yaml
generated
vendored
Normal file
1003
node_modules/@apidevtools/openapi-schemas/schemas/v3.0/schema.yaml
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
41
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/README.md
generated
vendored
Normal file
41
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
# OpenAPI 3.1.X JSON Schema
|
||||||
|
|
||||||
|
Here you can find the JSON Schema for validating OpenAPI definitions of versions
|
||||||
|
3.1.X.
|
||||||
|
|
||||||
|
As a reminder, the JSON Schema is not the source of truth for the Specification.
|
||||||
|
In cases of conflicts between the Specification itself and the JSON Schema, the
|
||||||
|
Specification wins. Also, some Specification constraints cannot be represented
|
||||||
|
with the JSON Schema so it's highly recommended to employ other methods to
|
||||||
|
ensure compliance.
|
||||||
|
|
||||||
|
The iteration version of the JSON Schema can be found in the `$id` field. For
|
||||||
|
example, the value of `$id: https://spec.openapis.org/oas/3.1/schema/2021-03-02`
|
||||||
|
means this iteration was created on March 2nd, 2021.
|
||||||
|
|
||||||
|
The `schema.yaml` schema doesn't validate the JSON Schemas in your OpenAPI
|
||||||
|
document because 3.1 allows you to use any JSON Schema dialect you choose. We
|
||||||
|
have also included `schema-base.yaml` that extends the main schema to validate
|
||||||
|
that all schemas use the default OAS base vocabulary.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
To submit improvements to the schema, modify the schema.yaml file only.
|
||||||
|
|
||||||
|
The TSC will then:
|
||||||
|
- Run tests on the updated schema
|
||||||
|
- Update the iteration version
|
||||||
|
- Convert the schema.yaml to schema.json
|
||||||
|
- Publish the new version
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
The test suite is included as a git submodule of https://github.com/Mermade/openapi3-examples.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx mocha --recursive tests
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also validate a document individually.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/validate.js path/to/document/to/validate.yaml
|
||||||
|
```
|
||||||
21
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/dialect/base.schema.json
generated
vendored
Normal file
21
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/dialect/base.schema.json
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"$id": "https://spec.openapis.org/oas/3.1/dialect/base",
|
||||||
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"$vocabulary": {
|
||||||
|
"https://json-schema.org/draft/2020-12/vocab/core": true,
|
||||||
|
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
|
||||||
|
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
|
||||||
|
"https://json-schema.org/draft/2020-12/vocab/validation": true,
|
||||||
|
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
|
||||||
|
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
|
||||||
|
"https://json-schema.org/draft/2020-12/vocab/content": true,
|
||||||
|
"https://spec.openapis.org/oas/3.1/vocab/base": false
|
||||||
|
},
|
||||||
|
"$dynamicAnchor": "meta",
|
||||||
|
|
||||||
|
"title": "OpenAPI 3.1 Schema Object Dialect",
|
||||||
|
"allOf": [
|
||||||
|
{ "$ref": "https://json-schema.org/draft/2020-12/schema" },
|
||||||
|
{ "$ref": "https://spec.openapis.org/oas/3.1/meta/base" }
|
||||||
|
]
|
||||||
|
}
|
||||||
79
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/meta/base.schema.json
generated
vendored
Normal file
79
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/meta/base.schema.json
generated
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
{
|
||||||
|
"$id": "https://spec.openapis.org/oas/3.1/meta/base",
|
||||||
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"$vocabulary": {
|
||||||
|
"https://spec.openapis.org/oas/3.1/vocab/base": true
|
||||||
|
},
|
||||||
|
"$dynamicAnchor": "meta",
|
||||||
|
"title": "OAS Base vocabulary",
|
||||||
|
|
||||||
|
"type": ["object", "boolean"],
|
||||||
|
"properties": {
|
||||||
|
"example": true,
|
||||||
|
"discriminator": { "$ref": "#/$defs/discriminator" },
|
||||||
|
"externalDocs": { "$ref": "#/$defs/external-docs" },
|
||||||
|
"xml": { "$ref": "#/$defs/xml" }
|
||||||
|
},
|
||||||
|
"$defs": {
|
||||||
|
"extensible": {
|
||||||
|
"patternProperties": {
|
||||||
|
"^x-": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"discriminator": {
|
||||||
|
"$ref": "#/$defs/extensible",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"propertyName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"mapping": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["propertyName"],
|
||||||
|
"unevaluatedProperties": false
|
||||||
|
},
|
||||||
|
"external-docs": {
|
||||||
|
"$ref": "#/$defs/extensible",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"url": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uri-reference"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["url"],
|
||||||
|
"unevaluatedProperties": false
|
||||||
|
},
|
||||||
|
"xml": {
|
||||||
|
"$ref": "#/$defs/extensible",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"namespace": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uri"
|
||||||
|
},
|
||||||
|
"prefix": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"attribute": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"wrapped": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"unevaluatedProperties": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/schema-base.json
generated
vendored
Normal file
24
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/schema-base.json
generated
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"$id": "https://spec.openapis.org/oas/3.1/schema-base/2021-04-15",
|
||||||
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"$ref": "https://spec.openapis.org/oas/3.1/schema/2021-04-15",
|
||||||
|
"properties": {
|
||||||
|
"jsonSchemaDialect": {
|
||||||
|
"$ref": "#/$defs/dialect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"$defs": {
|
||||||
|
"dialect": {
|
||||||
|
"const": "https://spec.openapis.org/oas/3.1/dialect/base"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"$dynamicAnchor": "meta",
|
||||||
|
"$ref\"": "https://spec.openapis.org/oas/3.1/dialect/base",
|
||||||
|
"properties": {
|
||||||
|
"$schema": {
|
||||||
|
"$ref": "#/$defs/dialect"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/schema-base.yaml
generated
vendored
Normal file
17
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/schema-base.yaml
generated
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
$id: 'https://spec.openapis.org/oas/3.1/schema-base/2021-04-15'
|
||||||
|
$schema: 'https://json-schema.org/draft/2020-12/schema'
|
||||||
|
|
||||||
|
$ref: 'https://spec.openapis.org/oas/3.1/schema/2021-04-15'
|
||||||
|
properties:
|
||||||
|
jsonSchemaDialect:
|
||||||
|
$ref: '#/$defs/dialect'
|
||||||
|
|
||||||
|
$defs:
|
||||||
|
dialect:
|
||||||
|
const: 'https://spec.openapis.org/oas/3.1/dialect/base'
|
||||||
|
schema:
|
||||||
|
$dynamicAnchor: meta
|
||||||
|
$ref": 'https://spec.openapis.org/oas/3.1/dialect/base'
|
||||||
|
properties:
|
||||||
|
$schema:
|
||||||
|
$ref: '#/$defs/dialect'
|
||||||
1343
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/schema.json
generated
vendored
Normal file
1343
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/schema.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
913
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/schema.yaml
generated
vendored
Normal file
913
node_modules/@apidevtools/openapi-schemas/schemas/v3.1/schema.yaml
generated
vendored
Normal file
|
|
@ -0,0 +1,913 @@
|
||||||
|
$id: 'https://spec.openapis.org/oas/3.1/schema/2021-04-15'
|
||||||
|
$schema: 'https://json-schema.org/draft/2020-12/schema'
|
||||||
|
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
openapi:
|
||||||
|
type: string
|
||||||
|
pattern: '^3\.1\.\d+(-.+)?$'
|
||||||
|
info:
|
||||||
|
$ref: '#/$defs/info'
|
||||||
|
jsonSchemaDialect:
|
||||||
|
$ref: '#/$defs/uri'
|
||||||
|
default: 'https://spec.openapis.org/oas/3.1/dialect/base'
|
||||||
|
servers:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/$defs/server'
|
||||||
|
paths:
|
||||||
|
$ref: '#/$defs/paths'
|
||||||
|
webhooks:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/path-item-or-reference'
|
||||||
|
components:
|
||||||
|
$ref: '#/$defs/components'
|
||||||
|
security:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/$defs/security-requirement'
|
||||||
|
tags:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/$defs/tag'
|
||||||
|
externalDocs:
|
||||||
|
$ref: '#/$defs/external-documentation'
|
||||||
|
required:
|
||||||
|
- openapi
|
||||||
|
- info
|
||||||
|
anyOf:
|
||||||
|
- required:
|
||||||
|
- paths
|
||||||
|
- required:
|
||||||
|
- components
|
||||||
|
- required:
|
||||||
|
- webhooks
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
$defs:
|
||||||
|
info:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
title:
|
||||||
|
type: string
|
||||||
|
summary:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
termsOfService:
|
||||||
|
type: string
|
||||||
|
contact:
|
||||||
|
$ref: '#/$defs/contact'
|
||||||
|
license:
|
||||||
|
$ref: '#/$defs/license'
|
||||||
|
version:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- title
|
||||||
|
- version
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
contact:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
url:
|
||||||
|
type: string
|
||||||
|
email:
|
||||||
|
type: string
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
license:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
identifier:
|
||||||
|
type: string
|
||||||
|
url:
|
||||||
|
$ref: '#/$defs/uri'
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
oneOf:
|
||||||
|
- required:
|
||||||
|
- identifier
|
||||||
|
- required:
|
||||||
|
- url
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
server:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
url:
|
||||||
|
$ref: '#/$defs/uri'
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
variables:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/server-variable'
|
||||||
|
required:
|
||||||
|
- url
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
server-variable:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
enum:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
minItems: 1
|
||||||
|
default:
|
||||||
|
type: string
|
||||||
|
descriptions:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- default
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
components:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
schemas:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$dynamicRef: '#meta'
|
||||||
|
responses:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/response-or-reference'
|
||||||
|
parameters:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/parameter-or-reference'
|
||||||
|
examples:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/example-or-reference'
|
||||||
|
requestBodies:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/request-body-or-reference'
|
||||||
|
headers:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/header-or-reference'
|
||||||
|
securitySchemes:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/security-scheme-or-reference'
|
||||||
|
links:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/link-or-reference'
|
||||||
|
callbacks:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/callbacks-or-reference'
|
||||||
|
pathItems:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/path-item-or-reference'
|
||||||
|
patternProperties:
|
||||||
|
'^(schemas|responses|parameters|examples|requestBodies|headers|securitySchemes|links|callbacks|pathItems)$':
|
||||||
|
$comment: Enumerating all of the property names in the regex above is necessary for unevaluatedProperties to work as expected
|
||||||
|
propertyNames:
|
||||||
|
pattern: '^[a-zA-Z0-9._-]+$'
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
paths:
|
||||||
|
type: object
|
||||||
|
patternProperties:
|
||||||
|
'^/':
|
||||||
|
$ref: '#/$defs/path-item'
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
path-item:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
summary:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
servers:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/$defs/server'
|
||||||
|
parameters:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/$defs/parameter-or-reference'
|
||||||
|
patternProperties:
|
||||||
|
'^(get|put|post|delete|options|head|patch|trace)$':
|
||||||
|
$ref: '#/$defs/operation'
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
path-item-or-reference:
|
||||||
|
if:
|
||||||
|
required:
|
||||||
|
- $ref
|
||||||
|
then:
|
||||||
|
$ref: '#/$defs/reference'
|
||||||
|
else:
|
||||||
|
$ref: '#/$defs/path-item'
|
||||||
|
|
||||||
|
operation:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
tags:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
summary:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
externalDocs:
|
||||||
|
$ref: '#/$defs/external-documentation'
|
||||||
|
operationId:
|
||||||
|
type: string
|
||||||
|
parameters:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/$defs/parameter-or-reference'
|
||||||
|
requestBody:
|
||||||
|
$ref: '#/$defs/request-body-or-reference'
|
||||||
|
responses:
|
||||||
|
$ref: '#/$defs/responses'
|
||||||
|
callbacks:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/callbacks-or-reference'
|
||||||
|
deprecated:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
security:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/$defs/security-requirement'
|
||||||
|
servers:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/$defs/server'
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
external-documentation:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
url:
|
||||||
|
$ref: '#/$defs/uri'
|
||||||
|
required:
|
||||||
|
- url
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
parameter:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
in:
|
||||||
|
enum:
|
||||||
|
- query
|
||||||
|
- header
|
||||||
|
- path
|
||||||
|
- cookie
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
deprecated:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
allowEmptyValue:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
schema:
|
||||||
|
$dynamicRef: '#meta'
|
||||||
|
content:
|
||||||
|
$ref: '#/$defs/content'
|
||||||
|
required:
|
||||||
|
- in
|
||||||
|
oneOf:
|
||||||
|
- required:
|
||||||
|
- schema
|
||||||
|
- required:
|
||||||
|
- content
|
||||||
|
dependentSchemas:
|
||||||
|
schema:
|
||||||
|
properties:
|
||||||
|
style:
|
||||||
|
type: string
|
||||||
|
explode:
|
||||||
|
type: boolean
|
||||||
|
allowReserved:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/$defs/examples'
|
||||||
|
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-path'
|
||||||
|
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-header'
|
||||||
|
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-query'
|
||||||
|
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-cookie'
|
||||||
|
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-form'
|
||||||
|
|
||||||
|
$defs:
|
||||||
|
styles-for-path:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
in:
|
||||||
|
const: path
|
||||||
|
required:
|
||||||
|
- in
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
style:
|
||||||
|
default: simple
|
||||||
|
enum:
|
||||||
|
- matrix
|
||||||
|
- label
|
||||||
|
- simple
|
||||||
|
required:
|
||||||
|
const: true
|
||||||
|
required:
|
||||||
|
- required
|
||||||
|
|
||||||
|
styles-for-header:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
in:
|
||||||
|
const: header
|
||||||
|
required:
|
||||||
|
- in
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
style:
|
||||||
|
default: simple
|
||||||
|
enum:
|
||||||
|
- simple
|
||||||
|
|
||||||
|
styles-for-query:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
in:
|
||||||
|
const: query
|
||||||
|
required:
|
||||||
|
- in
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
style:
|
||||||
|
default: form
|
||||||
|
enum:
|
||||||
|
- form
|
||||||
|
- spaceDelimited
|
||||||
|
- pipeDelimited
|
||||||
|
- deepObject
|
||||||
|
|
||||||
|
styles-for-cookie:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
in:
|
||||||
|
const: cookie
|
||||||
|
required:
|
||||||
|
- in
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
style:
|
||||||
|
default: form
|
||||||
|
enum:
|
||||||
|
- form
|
||||||
|
|
||||||
|
styles-for-form:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
style:
|
||||||
|
const: form
|
||||||
|
required:
|
||||||
|
- style
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
explode:
|
||||||
|
default: true
|
||||||
|
else:
|
||||||
|
properties:
|
||||||
|
explode:
|
||||||
|
default: false
|
||||||
|
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
parameter-or-reference:
|
||||||
|
if:
|
||||||
|
required:
|
||||||
|
- $ref
|
||||||
|
then:
|
||||||
|
$ref: '#/$defs/reference'
|
||||||
|
else:
|
||||||
|
$ref: '#/$defs/parameter'
|
||||||
|
|
||||||
|
request-body:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
content:
|
||||||
|
$ref: '#/$defs/content'
|
||||||
|
required:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
required:
|
||||||
|
- content
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
request-body-or-reference:
|
||||||
|
if:
|
||||||
|
required:
|
||||||
|
- $ref
|
||||||
|
then:
|
||||||
|
$ref: '#/$defs/reference'
|
||||||
|
else:
|
||||||
|
$ref: '#/$defs/request-body'
|
||||||
|
|
||||||
|
content:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/media-type'
|
||||||
|
propertyNames:
|
||||||
|
format: media-range
|
||||||
|
|
||||||
|
media-type:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
schema:
|
||||||
|
$dynamicRef: '#meta'
|
||||||
|
encoding:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/encoding'
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/$defs/specification-extensions'
|
||||||
|
- $ref: '#/$defs/examples'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
encoding:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
contentType:
|
||||||
|
type: string
|
||||||
|
format: media-range
|
||||||
|
headers:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/header-or-reference'
|
||||||
|
style:
|
||||||
|
default: form
|
||||||
|
enum:
|
||||||
|
- form
|
||||||
|
- spaceDelimited
|
||||||
|
- pipeDelimited
|
||||||
|
- deepObject
|
||||||
|
explode:
|
||||||
|
type: boolean
|
||||||
|
allowReserved:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/$defs/specification-extensions'
|
||||||
|
- $ref: '#/$defs/encoding/$defs/explode-default'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
$defs:
|
||||||
|
explode-default:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
style:
|
||||||
|
const: form
|
||||||
|
required:
|
||||||
|
- style
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
explode:
|
||||||
|
default: true
|
||||||
|
else:
|
||||||
|
properties:
|
||||||
|
explode:
|
||||||
|
default: false
|
||||||
|
|
||||||
|
responses:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
default:
|
||||||
|
$ref: '#/$defs/response-or-reference'
|
||||||
|
patternProperties:
|
||||||
|
'^[1-5][0-9X]{2}$':
|
||||||
|
$ref: '#/$defs/response-or-reference'
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
headers:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/header-or-reference'
|
||||||
|
content:
|
||||||
|
$ref: '#/$defs/content'
|
||||||
|
links:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/link-or-reference'
|
||||||
|
required:
|
||||||
|
- description
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
response-or-reference:
|
||||||
|
if:
|
||||||
|
required:
|
||||||
|
- $ref
|
||||||
|
then:
|
||||||
|
$ref: '#/$defs/reference'
|
||||||
|
else:
|
||||||
|
$ref: '#/$defs/response'
|
||||||
|
|
||||||
|
callbacks:
|
||||||
|
type: object
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/path-item-or-reference'
|
||||||
|
|
||||||
|
callbacks-or-reference:
|
||||||
|
if:
|
||||||
|
required:
|
||||||
|
- $ref
|
||||||
|
then:
|
||||||
|
$ref: '#/$defs/reference'
|
||||||
|
else:
|
||||||
|
$ref: '#/$defs/callbacks'
|
||||||
|
|
||||||
|
example:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
summary:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
value: true
|
||||||
|
externalValue:
|
||||||
|
$ref: '#/$defs/uri'
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
example-or-reference:
|
||||||
|
if:
|
||||||
|
required:
|
||||||
|
- $ref
|
||||||
|
then:
|
||||||
|
$ref: '#/$defs/reference'
|
||||||
|
else:
|
||||||
|
$ref: '#/$defs/example'
|
||||||
|
|
||||||
|
link:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
operationRef:
|
||||||
|
$ref: '#/$defs/uri'
|
||||||
|
operationId: true
|
||||||
|
parameters:
|
||||||
|
$ref: '#/$defs/map-of-strings'
|
||||||
|
requestBody: true
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
body:
|
||||||
|
$ref: '#/$defs/server'
|
||||||
|
oneOf:
|
||||||
|
- required:
|
||||||
|
- operationRef
|
||||||
|
- required:
|
||||||
|
- operationId
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
link-or-reference:
|
||||||
|
if:
|
||||||
|
required:
|
||||||
|
- $ref
|
||||||
|
then:
|
||||||
|
$ref: '#/$defs/reference'
|
||||||
|
else:
|
||||||
|
$ref: '#/$defs/link'
|
||||||
|
|
||||||
|
header:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
deprecated:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
allowEmptyValue:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
dependentSchemas:
|
||||||
|
schema:
|
||||||
|
properties:
|
||||||
|
style:
|
||||||
|
default: simple
|
||||||
|
enum:
|
||||||
|
- simple
|
||||||
|
explode:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
allowReserved:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
schema:
|
||||||
|
$dynamicRef: '#meta'
|
||||||
|
$ref: '#/$defs/examples'
|
||||||
|
content:
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
$ref: '#/$defs/content'
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
header-or-reference:
|
||||||
|
if:
|
||||||
|
required:
|
||||||
|
- $ref
|
||||||
|
then:
|
||||||
|
$ref: '#/$defs/reference'
|
||||||
|
else:
|
||||||
|
$ref: '#/$defs/header'
|
||||||
|
|
||||||
|
tag:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
externalDocs:
|
||||||
|
$ref: '#/$defs/external-documentation'
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
reference:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
$ref:
|
||||||
|
$ref: '#/$defs/uri'
|
||||||
|
summary:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
schema:
|
||||||
|
$dynamicAnchor: meta
|
||||||
|
type:
|
||||||
|
- object
|
||||||
|
- boolean
|
||||||
|
|
||||||
|
security-scheme:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
enum:
|
||||||
|
- apiKey
|
||||||
|
- http
|
||||||
|
- mutualTLS
|
||||||
|
- oauth2
|
||||||
|
- openIdConnect
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- type
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/$defs/specification-extensions'
|
||||||
|
- $ref: '#/$defs/security-scheme/$defs/type-apikey'
|
||||||
|
- $ref: '#/$defs/security-scheme/$defs/type-http'
|
||||||
|
- $ref: '#/$defs/security-scheme/$defs/type-http-bearer'
|
||||||
|
- $ref: '#/$defs/security-scheme/$defs/type-oauth2'
|
||||||
|
- $ref: '#/$defs/security-scheme/$defs/type-oidc'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
$defs:
|
||||||
|
type-apikey:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
const: apiKey
|
||||||
|
required:
|
||||||
|
- type
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
in:
|
||||||
|
enum:
|
||||||
|
- query
|
||||||
|
- header
|
||||||
|
- cookie
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
- in
|
||||||
|
|
||||||
|
type-http:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
const: http
|
||||||
|
required:
|
||||||
|
- type
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
scheme:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- scheme
|
||||||
|
|
||||||
|
type-http-bearer:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
const: http
|
||||||
|
scheme:
|
||||||
|
const: bearer
|
||||||
|
required:
|
||||||
|
- type
|
||||||
|
- scheme
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
bearerFormat:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- scheme
|
||||||
|
|
||||||
|
type-oauth2:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
const: oauth2
|
||||||
|
required:
|
||||||
|
- type
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
flows:
|
||||||
|
$ref: '#/$defs/oauth-flows'
|
||||||
|
required:
|
||||||
|
- flows
|
||||||
|
|
||||||
|
type-oidc:
|
||||||
|
if:
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
const: openIdConnect
|
||||||
|
required:
|
||||||
|
- type
|
||||||
|
then:
|
||||||
|
properties:
|
||||||
|
openIdConnectUrl:
|
||||||
|
$ref: '#/$defs/uri'
|
||||||
|
required:
|
||||||
|
- openIdConnectUrl
|
||||||
|
|
||||||
|
security-scheme-or-reference:
|
||||||
|
if:
|
||||||
|
required:
|
||||||
|
- $ref
|
||||||
|
then:
|
||||||
|
$ref: '#/$defs/reference'
|
||||||
|
else:
|
||||||
|
$ref: '#/$defs/security-scheme'
|
||||||
|
|
||||||
|
oauth-flows:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
implicit:
|
||||||
|
$ref: '#/$defs/oauth-flows/$defs/implicit'
|
||||||
|
password:
|
||||||
|
$ref: '#/$defs/oauth-flows/$defs/password'
|
||||||
|
clientCredentials:
|
||||||
|
$ref: '#/$defs/oauth-flows/$defs/client-credentials'
|
||||||
|
authorizationCode:
|
||||||
|
$ref: '#/$defs/oauth-flows/$defs/authorization-code'
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
$defs:
|
||||||
|
implicit:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
authorizationUrl:
|
||||||
|
type: string
|
||||||
|
refreshUrl:
|
||||||
|
type: string
|
||||||
|
scopes:
|
||||||
|
$ref: '#/$defs/map-of-strings'
|
||||||
|
required:
|
||||||
|
- authorizationUrl
|
||||||
|
- scopes
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
password:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
tokenUrl:
|
||||||
|
type: string
|
||||||
|
refreshUrl:
|
||||||
|
type: string
|
||||||
|
scopes:
|
||||||
|
$ref: '#/$defs/map-of-strings'
|
||||||
|
required:
|
||||||
|
- tokenUrl
|
||||||
|
- scopes
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
client-credentials:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
tokenUrl:
|
||||||
|
type: string
|
||||||
|
refreshUrl:
|
||||||
|
type: string
|
||||||
|
scopes:
|
||||||
|
$ref: '#/$defs/map-of-strings'
|
||||||
|
required:
|
||||||
|
- tokenUrl
|
||||||
|
- scopes
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
authorization-code:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
authorizationUrl:
|
||||||
|
type: string
|
||||||
|
tokenUrl:
|
||||||
|
type: string
|
||||||
|
refreshUrl:
|
||||||
|
type: string
|
||||||
|
scopes:
|
||||||
|
$ref: '#/$defs/map-of-strings'
|
||||||
|
required:
|
||||||
|
- authorizationUrl
|
||||||
|
- tokenUrl
|
||||||
|
- scopes
|
||||||
|
$ref: '#/$defs/specification-extensions'
|
||||||
|
unevaluatedProperties: false
|
||||||
|
|
||||||
|
security-requirement:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
specification-extensions:
|
||||||
|
patternProperties:
|
||||||
|
'^x-': true
|
||||||
|
|
||||||
|
examples:
|
||||||
|
properties:
|
||||||
|
example: true
|
||||||
|
examples:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
$ref: '#/$defs/example-or-reference'
|
||||||
|
|
||||||
|
uri:
|
||||||
|
type: string
|
||||||
|
format: uri
|
||||||
|
|
||||||
|
map-of-strings:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
type: string
|
||||||
35
node_modules/@apidevtools/swagger-methods/CHANGELOG.md
generated
vendored
Normal file
35
node_modules/@apidevtools/swagger-methods/CHANGELOG.md
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
Change Log
|
||||||
|
====================================================================================================
|
||||||
|
All notable changes will be documented in this file.
|
||||||
|
Swagger Methods adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v3.0.0](https://github.com/APIDevTools/swagger-methods/tree/v3.0.0) (2020-03-10)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Moved Swagger Methods to the [@APIDevTools scope](https://www.npmjs.com/org/apidevtools) on NPM
|
||||||
|
|
||||||
|
- The "swagger-methods" NPM package is now just a wrapper around the scoped "@apidevtools/swagger-methods" package
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-methods/compare/v2.1.0...v3.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v2.0.0](https://github.com/APIDevTools/swagger-methods/tree/v2.0.0) (2019-06-11)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
- Dropped support for Node 0.10 through 6.0.0
|
||||||
|
|
||||||
|
- Converted to ES6 syntax
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-methods/compare/v1.0.1...v2.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v1.0.0](https://github.com/APIDevTools/swagger-methods/tree/v1.0.0) (2015-09-07)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Initial release 🎉
|
||||||
21
node_modules/@apidevtools/swagger-methods/LICENSE
generated
vendored
Normal file
21
node_modules/@apidevtools/swagger-methods/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 James Messinger
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
83
node_modules/@apidevtools/swagger-methods/README.md
generated
vendored
Normal file
83
node_modules/@apidevtools/swagger-methods/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
Swagger Methods
|
||||||
|
============================
|
||||||
|
#### HTTP methods that are supported by Swagger 2.0
|
||||||
|
|
||||||
|
[](https://github.com/APIDevTools/swagger-methods/actions)
|
||||||
|
[](https://github.com/APIDevTools/swagger-methods/actions)
|
||||||
|
|
||||||
|
[](https://coveralls.io/github/APIDevTools/swagger-methods?branch=master)
|
||||||
|
[](https://david-dm.org/APIDevTools/swagger-methods)
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/@apidevtools/swagger-methods)
|
||||||
|
[](LICENSE)
|
||||||
|
[](https://plant.treeware.earth/APIDevTools/swagger-methods)
|
||||||
|
|
||||||
|
This is an array of lower-case HTTP method names that are supported by the [Swagger 2.0 spec](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md).
|
||||||
|
|
||||||
|
This module is [tested](test/index.spec.js) against the [Swagger 2.0 schema](https://www.npmjs.com/package/swagger-schema-official)
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
--------------------------
|
||||||
|
Install using [npm](https://docs.npmjs.com/about-npm/):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install @apidevtools/swagger-methods
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var methods = require('@apidevtools/swagger-methods');
|
||||||
|
|
||||||
|
methods.forEach(function(method) {
|
||||||
|
console.log(method);
|
||||||
|
});
|
||||||
|
|
||||||
|
// get
|
||||||
|
// put
|
||||||
|
// post
|
||||||
|
// delete
|
||||||
|
// options
|
||||||
|
// head
|
||||||
|
// patch
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
--------------------------
|
||||||
|
I welcome any contributions, enhancements, and bug-fixes. [Open an issue](https://github.com/APIDevTools/swagger-methods/issues) on GitHub and [submit a pull request](https://github.com/APIDevTools/swagger-methods/pulls).
|
||||||
|
|
||||||
|
#### Building/Testing
|
||||||
|
To build/test the project locally on your computer:
|
||||||
|
|
||||||
|
1. **Clone this repo**<br>
|
||||||
|
`git clone https://github.com/APIDevTools/swagger-methods.git`
|
||||||
|
|
||||||
|
2. **Install dev dependencies**<br>
|
||||||
|
`npm install`
|
||||||
|
|
||||||
|
3. **Run the unit tests**<br>
|
||||||
|
`npm test`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
License
|
||||||
|
--------------------------
|
||||||
|
[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/swagger-methods) 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
|
||||||
|
--------------------------
|
||||||
|
Thanks to these awesome companies for their support of Open Source developers ❤
|
||||||
|
|
||||||
|
[](https://travis-ci.com)
|
||||||
|
[](https://saucelabs.com)
|
||||||
|
[](https://coveralls.io)
|
||||||
5
node_modules/@apidevtools/swagger-methods/lib/index.js
generated
vendored
Normal file
5
node_modules/@apidevtools/swagger-methods/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
"get", "put", "post", "delete", "options", "head", "patch"
|
||||||
|
];
|
||||||
46
node_modules/@apidevtools/swagger-methods/package.json
generated
vendored
Normal file
46
node_modules/@apidevtools/swagger-methods/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"name": "@apidevtools/swagger-methods",
|
||||||
|
"version": "3.0.2",
|
||||||
|
"description": "HTTP methods that are supported by Swagger 2.0",
|
||||||
|
"keywords": [
|
||||||
|
"swagger",
|
||||||
|
"http",
|
||||||
|
"methods"
|
||||||
|
],
|
||||||
|
"author": {
|
||||||
|
"name": "James Messinger",
|
||||||
|
"url": "https://jamesmessinger.com"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"homepage": "https://github.com/APIDevTools/swagger-methods",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"files": [
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"clean": "shx rm -rf .nyc_output coverage",
|
||||||
|
"lint": "eslint lib test",
|
||||||
|
"test": "mocha && npm run lint",
|
||||||
|
"coverage": "nyc node_modules/mocha/bin/mocha",
|
||||||
|
"upgrade": "npm-check -u && npm audit fix",
|
||||||
|
"bump": "bump --tag --push --all",
|
||||||
|
"release": "npm run upgrade && npm run clean && npm test && npm run bump"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/APIDevTools/swagger-methods.git"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@jsdevtools/eslint-config": "^1.0.4",
|
||||||
|
"@jsdevtools/version-bump-prompt": "^6.0.6",
|
||||||
|
"chai": "^4.2.0",
|
||||||
|
"eslint": "^7.5.0",
|
||||||
|
"methods": "^1.1.2",
|
||||||
|
"mocha": "^8.0.1",
|
||||||
|
"npm-check": "^5.9.0",
|
||||||
|
"nyc": "^15.1.0",
|
||||||
|
"shx": "^0.3.2",
|
||||||
|
"swagger-schema-official": "2.0.0-bab6bed"
|
||||||
|
},
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
||||||
192
node_modules/@apidevtools/swagger-parser/CHANGELOG.md
generated
vendored
Normal file
192
node_modules/@apidevtools/swagger-parser/CHANGELOG.md
generated
vendored
Normal file
|
|
@ -0,0 +1,192 @@
|
||||||
|
Change Log
|
||||||
|
====================================================================================================
|
||||||
|
All notable changes will be documented in this file.
|
||||||
|
Swagger Parser adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v10.0.0](https://github.com/APIDevTools/swagger-parser/tree/v10.0.0) (2020-07-10)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#### Breaking Changes
|
||||||
|
|
||||||
|
- Removed the `YAML` export. We recommend using [`@stoplight/yaml`](https://www.npmjs.com/package/@stoplight/yaml) instead
|
||||||
|
|
||||||
|
|
||||||
|
#### Other Changes
|
||||||
|
|
||||||
|
- Added a new [`continueOnError` option](https://apitools.dev/swagger-parser/docs/options) that allows you to get all errors rather than just the first one
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v9.0.1...v10.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v9.0.0](https://github.com/APIDevTools/swagger-parser/tree/v9.0.0) (2020-03-14)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Moved Swagger Parser to the [@APIDevTools scope](https://www.npmjs.com/org/apidevtools) on NPM
|
||||||
|
|
||||||
|
- The "swagger-parser" NPM package is now just a wrapper around the scoped "@apidevtools/swagger-parser" package
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v8.0.4...v9.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v8.0.0](https://github.com/APIDevTools/swagger-parser/tree/v8.0.0) (2019-06-22)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#### Potentially Breaking Changes
|
||||||
|
|
||||||
|
- [The `validate()` function](https://apitools.dev/swagger-parser/docs/swagger-parser.html#validateapi-options-callback) now uses [the official JSON Schemas](https://github.com/OAI/OpenAPI-Specification/tree/master/schemas) for Swagger 2.0 and OpenAPI 3.0 schema validation. We tested this change on [over 1,500 real-world APIs](https://apis.guru/browse-apis/) and there were **no breaking changes**, but we're bumped the major version number just to be safe.
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v7.0.1...v8.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v7.0.0](https://github.com/APIDevTools/swagger-parser/tree/v7.0.0) (2019-06-12)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#### Breaking Changes
|
||||||
|
|
||||||
|
- Dropped support for Node 6
|
||||||
|
|
||||||
|
- Updated all code to ES6+ syntax (async/await, template literals, arrow functions, etc.)
|
||||||
|
|
||||||
|
- No longer including a pre-built bundle in the package. such as [Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/), [Parcel](https://parceljs.org/), or [Browserify](http://browserify.org/) to include Swagger Parser in your app
|
||||||
|
|
||||||
|
#### Other Changes
|
||||||
|
|
||||||
|
- Added [TypeScript definitions](lib/index.d.ts)
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v6.0.5...v7.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v6.0.0](https://github.com/APIDevTools/swagger-parser/tree/v6.0.0) (2018-10-05)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Dropped support for [Bower](https://www.npmjs.com/package/bower), since it has been deprecated
|
||||||
|
|
||||||
|
- Removed the [`debug`](https://npmjs.com/package/debug) dependency
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v5.0.0...v6.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v5.0.0](https://github.com/APIDevTools/swagger-parser/tree/v5.0.0) (2018-05-25)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- After [months](https://github.com/APIDevTools/swagger-parser/issues/62) and [months](https://github.com/APIDevTools/swagger-parser/issues/72) of delays, initial support for OpenAPI 3.0 is finally here! A big "Thank You!" to [Leo Long](https://github.com/yujunlong2000) for doing the work and submitting [PR #88](https://github.com/APIDevTools/swagger-parser/pull/88).
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v4.1.0...v5.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v4.1.0](https://github.com/APIDevTools/swagger-parser/tree/v4.1.0) (2018-04-11)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- [@marcelstoer](https://github.com/marcelstoer) submitted [PR #83](https://github.com/APIDevTools/swagger-parser/pull/83) and [PR #84](https://github.com/APIDevTools/swagger-parser/pull/84), both of which improve the [`validate()` method](https://github.com/APIDevTools/swagger-parser/blob/master/docs/swagger-parser.md#validateapi-options-callback). It will now detect when a JSON Schema in your API definition has `required` properties that don't exist.
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v4.0.0...v4.1.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v4.0.0](https://github.com/APIDevTools/swagger-parser/tree/v4.0.0) (2017-10-19)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#### Breaking Changes
|
||||||
|
|
||||||
|
- Update the [Swagger 2.0 JSON schema](https://www.npmjs.com/package/swagger-schema-official), so it's possible that an API that previously passed validation may no longer pass due to changes in the Swagger schema
|
||||||
|
|
||||||
|
- To reduce the size of this library, it no longer includes polyfills for [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) and [TypedArrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), which are natively supported in the latest versions of Node and web browsers. If you need to support older browsers (such as IE9), then just use [this `Promise` polyfill](https://github.com/stefanpenner/es6-promise) and [this `TypedArray` polyfill](https://github.com/inexorabletash/polyfill/blob/master/typedarray.js).
|
||||||
|
|
||||||
|
#### Minor Changes
|
||||||
|
|
||||||
|
- [PR #74](https://github.com/APIDevTools/swagger-parser/pull/74) - Fixes [an edge-case bug](https://github.com/APIDevTools/swagger-parser/issues/73) with the `validate()` method and `x-` vendor extensions
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v4.0.0-beta.2...v4.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v4.0.0-beta.2](https://github.com/APIDevTools/swagger-parser/tree/v4.0.0-beta.2) (2016-04-25)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#### Just one small fix
|
||||||
|
Fixed [issue #13](https://github.com/APIDevTools/json-schema-ref-parser/issues/13). You can now pass a URL _and_ an object to any method.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
SwaggerParser.validate("http://example.com/my-schema.json", mySchemaObject, {})
|
||||||
|
```
|
||||||
|
|
||||||
|
> **NOTE:** As shown in the example above, you _must_ also pass an options object (even an empty object will work), otherwise, the method signature looks like you're just passing a URL and options.
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v4.4.0-beta.1...v4.0.0-beta.2)
|
||||||
|
|
||||||
|
|
||||||
|
[v4.0.0-beta.1](https://github.com/APIDevTools/swagger-parser/tree/v4.0.0-beta.1) (2016-04-10)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#### Plug-ins !!!
|
||||||
|
That's the major new feature in this version. Originally requested in [PR #8](https://github.com/APIDevTools/json-schema-ref-parser/pull/8), and refined a few times over the past few months, the plug-in API is now finalized and ready to use. You can now define your own [resolvers](https://github.com/APIDevTools/json-schema-ref-parser/blob/v3.0.0/docs/plugins/resolvers.md) and [parsers](https://github.com/APIDevTools/json-schema-ref-parser/blob/v3.0.0/docs/plugins/parsers.md).
|
||||||
|
|
||||||
|
#### Breaking Changes
|
||||||
|
The available [options have changed](https://github.com/APIDevTools/swagger-parser/blob/releases/4.0.0/docs/options.md), mostly due to the new plug-in API. There's not a one-to-one mapping of old options to new options, so you'll have to read the docs and determine which options you need to set. If any. The out-of-the-box configuration works for most people.
|
||||||
|
|
||||||
|
All of the [caching options have been removed](https://github.com/APIDevTools/json-schema-ref-parser/commit/1f4260184bfd370e9cd385b523fb08c098fac6db). Instead, files are now cached by default, and the entire cache is reset for each new parse operation. Caching options may come back in a future release, if there is enough demand for it. If you used the old caching options, please open an issue and explain your use-case and requirements. I need a better understanding of what caching functionality is actually needed by users.
|
||||||
|
|
||||||
|
#### Bug Fixes
|
||||||
|
Lots of little bug fixes, and a couple major bug fixes:
|
||||||
|
- [completely rewrote the bundling logic](https://github.com/APIDevTools/json-schema-ref-parser/commit/32510a38a29723fb24f56d30f055e7358acdd935) to fix [issue #16](https://github.com/APIDevTools/swagger-parser/issues/16)
|
||||||
|
- Added support for [root-level `$ref`s](https://github.com/APIDevTools/json-schema-ref-parser/issues/16)
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v3.3.0...v4.0.0-beta.1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v3.3.0](https://github.com/APIDevTools/swagger-parser/tree/v3.3.0) (2015-10-02)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Updated to the latest version of [the Official Swagger 2.0 Schema](https://www.npmjs.com/package/swagger-schema-official). The schema [hadn't been updated for six months](https://github.com/OAI/OpenAPI-Specification/issues/335), so Swagger Parser was missing [several recent changes](https://github.com/OAI/OpenAPI-Specification/commits/master/schemas/v2.0/schema.json).
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v3.2.0...v3.3.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v3.2.0](https://github.com/APIDevTools/swagger-parser/tree/v3.2.0) (2015-10-01)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Swagger Parser now uses [call-me-maybe](https://www.npmjs.com/package/call-me-maybe) to support [promises or callbacks](https://github.com/APIDevTools/swagger-parser/tree/master/docs#callbacks-vs-promises).
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v3.1.0...v3.2.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v3.1.0](https://github.com/APIDevTools/swagger-parser/tree/v3.1.0) (2015-09-28)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Fixed several bugs with circular references, particularly with the [`validate()`](https://github.com/APIDevTools/swagger-parser/blob/master/docs/swagger-parser.md#validateapi-options-callback) method.
|
||||||
|
|
||||||
|
Added a new [`$refs.circular` option](https://github.com/APIDevTools/swagger-parser/blob/master/docs/options.md) to determine how circular references are handled. Options are fully-dereferencing them (default), throwing an error, or ignoring them.
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v3.0.0...v3.1.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v3.0.0](https://github.com/APIDevTools/swagger-parser/tree/v3.0.0) (2015-09-25)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This is a **complete rewrite** of Swagger Parser. Major changes include:
|
||||||
|
|
||||||
|
**Swagger 2.0 Compliant**<br>
|
||||||
|
Previous versions of Swagger Parser were based on early drafts of Swagger 2.0, and were not compliant with [the final version of the spec](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md). Swagger Parser v3.0 is now compliant with the final spec as well as related specs, such as [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) and [JSON Pointer](https://tools.ietf.org/html/rfc6901)
|
||||||
|
|
||||||
|
**All-New API**<br>
|
||||||
|
The old API only had a single method: `parse()`. But depending on which options you passed it, the method did _much_ more than its name implied. The new API has separate methods to make things a bit more intuitive. The most commonly used will be [`validate()`](https://github.com/APIDevTools/swagger-parser/blob/master/docs/swagger-parser.md#validateapi-options-callback), [`bundle()`](https://github.com/APIDevTools/swagger-parser/blob/master/docs/swagger-parser.md#bundleapi-options-callback), and [`dereference()`](https://github.com/APIDevTools/swagger-parser/blob/master/docs/swagger-parser.md#dereferenceapi-options-callback). The [`parse()`](https://github.com/APIDevTools/swagger-parser/blob/master/docs/swagger-parser.md#parseapi-options-callback) and [`resolve()`](https://github.com/APIDevTools/swagger-parser/blob/master/docs/swagger-parser.md#resolveapi-options-callback) methods are also available, but these are mostly just for internal use by the other methods.
|
||||||
|
|
||||||
|
**Asynchronous API**<br>
|
||||||
|
The old API was "asynchronous", but it relied on global state, so it did not support multiple simultaneous operations. The new API is truly asynchronous and supports both [ES6 Promises](http://javascriptplayground.com/blog/2015/02/promises/) and Node-style callbacks.
|
||||||
|
|
||||||
|
**New JSON Schema Validator**<br>
|
||||||
|
Swagger Parser has switched from [tv4](https://github.com/geraintluff/tv4) to [Z-Schema](https://github.com/zaggino/z-schema), which is [faster](https://rawgit.com/zaggino/z-schema/master/benchmark/results.html) and performs [more accurate validation](https://github.com/ebdrup/json-schema-benchmark#test-failure-summary). This means that some APIs that previously passed validation will now fail. But that's a _good_ thing!
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/APIDevTools/swagger-parser/compare/v2.5.0...v3.0.0)
|
||||||
21
node_modules/@apidevtools/swagger-parser/LICENSE
generated
vendored
Normal file
21
node_modules/@apidevtools/swagger-parser/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 James Messinger
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
146
node_modules/@apidevtools/swagger-parser/README.md
generated
vendored
Normal file
146
node_modules/@apidevtools/swagger-parser/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
Swagger 2.0 and OpenAPI 3.0 parser/validator
|
||||||
|
============================
|
||||||
|
|
||||||
|
[](https://github.com/APIDevTools/swagger-parser/actions)
|
||||||
|
[](https://coveralls.io/github/APIDevTools/swagger-parser)
|
||||||
|
[](https://apis.guru/browse-apis/)
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/@apidevtools/swagger-parser)
|
||||||
|
[](https://david-dm.org/APIDevTools/swagger-parser)
|
||||||
|
[](LICENSE)
|
||||||
|
[](https://plant.treeware.earth/APIDevTools/swagger-parser)
|
||||||
|
|
||||||
|
[](https://github.com/APIDevTools/swagger-parser/actions)
|
||||||
|
|
||||||
|
[](https://apitools.dev/swagger-parser/online/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Features
|
||||||
|
--------------------------
|
||||||
|
- Parses Swagger specs in **JSON** or **YAML** format
|
||||||
|
- 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)
|
||||||
|
- [Resolves](https://apitools.dev/swagger-parser/docs/swagger-parser.html#resolveapi-options-callback) all `$ref` pointers, including external files and URLs
|
||||||
|
- Can [bundle](https://apitools.dev/swagger-parser/docs/swagger-parser.html#bundleapi-options-callback) all your Swagger files into a single file that only has _internal_ `$ref` pointers
|
||||||
|
- Can [dereference](https://apitools.dev/swagger-parser/docs/swagger-parser.html#dereferenceapi-options-callback) all `$ref` pointers, giving you a normal JavaScript object that's easy to work with
|
||||||
|
- **[Tested](https://github.com/APIDevTools/swagger-parser/actions)** in Node.js and all modern web browsers on Mac, Windows, and Linux
|
||||||
|
- Tested on **[over 1,500 real-world APIs](https://apis.guru/browse-apis/)** from Google, Microsoft, Facebook, Spotify, etc.
|
||||||
|
- Supports [circular references](https://apitools.dev/swagger-parser/docs/#circular-refs), nested references, back-references, and cross-references
|
||||||
|
- Maintains object reference equality — `$ref` pointers to the same value always resolve to the same object instance
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Related Projects
|
||||||
|
--------------------------
|
||||||
|
- [Swagger CLI](https://github.com/APIDevTools/swagger-cli)
|
||||||
|
- [Swagger Express Middleware](https://github.com/APIDevTools/swagger-express-middleware)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Example
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
SwaggerParser.validate(myAPI, (err, api) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("API name: %s, Version: %s", api.info.title, api.info.version);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Or use `async`/`await` or [Promise](http://javascriptplayground.com/blog/2015/02/promises/) syntax instead. The following example is the same as above:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
try {
|
||||||
|
let api = await SwaggerParser.validate(myAPI);
|
||||||
|
console.log("API name: %s, Version: %s", api.info.title, api.info.version);
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For more detailed examples, please see the [API Documentation](https://apitools.dev/swagger-parser/docs/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
--------------------------
|
||||||
|
Install using [npm](https://docs.npmjs.com/about-npm/):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install @apidevtools/swagger-parser
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
--------------------------
|
||||||
|
When using Swagger Parser in Node.js apps, you'll probably want to use **CommonJS** syntax:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const SwaggerParser = require("@apidevtools/swagger-parser");
|
||||||
|
```
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Browser support
|
||||||
|
--------------------------
|
||||||
|
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).
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
API Documentation
|
||||||
|
--------------------------
|
||||||
|
Full API documentation is available [right here](https://apitools.dev/swagger-parser/docs/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
--------------------------
|
||||||
|
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).
|
||||||
|
|
||||||
|
#### Building/Testing
|
||||||
|
To build/test the project locally on your computer:
|
||||||
|
|
||||||
|
1. __Clone this repo__<br>
|
||||||
|
`git clone https://github.com/APIDevTools/swagger-parser.git`
|
||||||
|
|
||||||
|
2. __Install dependencies__<br>
|
||||||
|
`npm install`
|
||||||
|
|
||||||
|
3. __Run the build script__<br>
|
||||||
|
`npm run build`
|
||||||
|
|
||||||
|
4. __Run the tests__<br>
|
||||||
|
`npm test`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
License
|
||||||
|
--------------------------
|
||||||
|
Swagger 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/swagger-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
|
||||||
|
--------------------------
|
||||||
|
Thanks to these awesome companies for their support of Open Source developers ❤
|
||||||
|
|
||||||
|
[](https://github.com/open-source)
|
||||||
|
[](https://www.npmjs.com/)
|
||||||
|
[](https://coveralls.io)
|
||||||
|
[](https://saucelabs.com)
|
||||||
439
node_modules/@apidevtools/swagger-parser/lib/index.d.ts
generated
vendored
Normal file
439
node_modules/@apidevtools/swagger-parser/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,439 @@
|
||||||
|
import { OpenAPI } from "openapi-types";
|
||||||
|
|
||||||
|
export = SwaggerParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the default export of Swagger Parser. You can creates instances of this class using new SwaggerParser(), or you can just call its static methods.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html
|
||||||
|
*/
|
||||||
|
declare class SwaggerParser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `api` property is the parsed/bundled/dereferenced OpenAPI definition. This is the same value that is passed to the callback function (or Promise) when calling the parse, bundle, or dereference methods.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#api
|
||||||
|
*/
|
||||||
|
public api: OpenAPI.Document;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The $refs property is a `$Refs` object, which lets you access all of the externally-referenced files in the OpenAPI definition, as well as easily get and set specific values in the OpenAPI definition using JSON pointers.
|
||||||
|
*
|
||||||
|
* This is the same value that is passed to the callback function (or Promise) when calling the `resolve` method.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#refs
|
||||||
|
*/
|
||||||
|
public $refs: SwaggerParser.$Refs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses, dereferences, and validates the given Swagger API.
|
||||||
|
* Depending on the options, validation can include JSON Schema validation and/or Swagger Spec validation.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#validateapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the dereferenced OpenAPI definition
|
||||||
|
*/
|
||||||
|
public validate(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public validate(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public validate(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public validate(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
|
||||||
|
public validate(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
public validate(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses, dereferences, and validates the given Swagger API.
|
||||||
|
* Depending on the options, validation can include JSON Schema validation and/or Swagger Spec validation.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#validateapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the dereferenced OpenAPI definition
|
||||||
|
*/
|
||||||
|
public static validate(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static validate(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static validate(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static validate(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
|
||||||
|
public static validate(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
public static validate(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dereferences all `$ref` pointers in the OpenAPI definition, replacing each reference with its resolved value. This results in an API definition that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
|
||||||
|
*
|
||||||
|
* The dereference method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of circular references, so be careful if you intend to serialize the API definition using `JSON.stringify()`. Consider using the bundle method instead, which does not create circular references.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#dereferenceapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the dereferenced OpenAPI definition
|
||||||
|
*/
|
||||||
|
public dereference(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public dereference(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public dereference(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public dereference(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
|
||||||
|
public dereference(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
public dereference(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dereferences all `$ref` pointers in the OpenAPI definition, replacing each reference with its resolved value. This results in an API definition that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.
|
||||||
|
*
|
||||||
|
* The dereference method maintains object reference equality, meaning that all `$ref` pointers that point to the same object will be replaced with references to the same object. Again, this is great for programmatic usage, but it does introduce the risk of circular references, so be careful if you intend to serialize the API definition using `JSON.stringify()`. Consider using the bundle method instead, which does not create circular references.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#dereferenceapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the dereferenced OpenAPI definition
|
||||||
|
*/
|
||||||
|
public static dereference(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static dereference(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static dereference(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static dereference(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
|
||||||
|
public static dereference(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
public static dereference(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bundles all referenced files/URLs into a single API definition that only has internal `$ref` pointers. This lets you split-up your API definition however you want while you're building it, but easily combine all those files together when it's time to package or distribute the API definition to other people. The resulting API definition size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
|
||||||
|
*
|
||||||
|
* This also eliminates the risk of circular references, so the API definition can be safely serialized using `JSON.stringify()`.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#bundleapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the bundled API definition object
|
||||||
|
*/
|
||||||
|
public bundle(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public bundle(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public bundle(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public bundle(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
|
||||||
|
public bundle(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
public bundle(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bundles all referenced files/URLs into a single API definition that only has internal `$ref` pointers. This lets you split-up your API definition however you want while you're building it, but easily combine all those files together when it's time to package or distribute the API definition to other people. The resulting API definition size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.
|
||||||
|
*
|
||||||
|
* This also eliminates the risk of circular references, so the API definition can be safely serialized using `JSON.stringify()`.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#bundleapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the bundled API definition object
|
||||||
|
*/
|
||||||
|
public static bundle(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static bundle(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static bundle(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static bundle(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
|
||||||
|
public static bundle(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
public static bundle(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
||||||
|
*
|
||||||
|
* Parses the given OpenAPI definition file (in JSON or YAML format), and returns it as a JavaScript object. This method `does not` resolve `$ref` pointers or dereference anything. It simply parses one file and returns it.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#parseapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. The path can be absolute or relative. In Node, the path is relative to `process.cwd()`. In the browser, it's relative to the URL of the page.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the parsed OpenAPI definition object, or an error
|
||||||
|
*/
|
||||||
|
public parse(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public parse(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public parse(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public parse(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
|
||||||
|
public parse(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
public parse(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
||||||
|
*
|
||||||
|
* Parses the given OpenAPI definition file (in JSON or YAML format), and returns it as a JavaScript object. This method `does not` resolve `$ref` pointers or dereference anything. It simply parses one file and returns it.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#parseapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. The path can be absolute or relative. In Node, the path is relative to `process.cwd()`. In the browser, it's relative to the URL of the page.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive the parsed OpenAPI definition object, or an error
|
||||||
|
*/
|
||||||
|
public static parse(api: string | OpenAPI.Document, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static parse(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static parse(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.ApiCallback): void;
|
||||||
|
public static parse(api: string | OpenAPI.Document): Promise<OpenAPI.Document>;
|
||||||
|
public static parse(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
public static parse(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<OpenAPI.Document>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
||||||
|
*
|
||||||
|
* Resolves all JSON references (`$ref` pointers) in the given OpenAPI definition file. If it references any other files/URLs, then they will be downloaded and resolved as well. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#resolveapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
||||||
|
*/
|
||||||
|
public resolve(api: string | OpenAPI.Document, callback: SwaggerParser.$RefsCallback): void;
|
||||||
|
public resolve(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.$RefsCallback): void;
|
||||||
|
public resolve(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.$RefsCallback): void;
|
||||||
|
public resolve(api: string | OpenAPI.Document): Promise<SwaggerParser.$Refs>;
|
||||||
|
public resolve(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<SwaggerParser.$Refs>;
|
||||||
|
public resolve(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<SwaggerParser.$Refs>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*
|
||||||
|
*
|
||||||
|
* Resolves all JSON references (`$ref` pointers) in the given OpenAPI definition file. If it references any other files/URLs, then they will be downloaded and resolved as well. This method **does not** dereference anything. It simply gives you a `$Refs` object, which is a map of all the resolved references and their values.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/swagger-parser.html#resolveapi-options-callback
|
||||||
|
*
|
||||||
|
* @param api An OpenAPI definition, or the file path or URL of an OpenAPI definition. See the `parse` method for more info.
|
||||||
|
* @param options (optional)
|
||||||
|
* @param callback (optional) A callback that will receive a `$Refs` object
|
||||||
|
*/
|
||||||
|
public static resolve(api: string | OpenAPI.Document, callback: SwaggerParser.$RefsCallback): void;
|
||||||
|
public static resolve(api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.$RefsCallback): void;
|
||||||
|
public static resolve(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options, callback: SwaggerParser.$RefsCallback): void;
|
||||||
|
public static resolve(api: string | OpenAPI.Document): Promise<SwaggerParser.$Refs>;
|
||||||
|
public static resolve(api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<SwaggerParser.$Refs>;
|
||||||
|
public static resolve(baseUrl: string, api: string | OpenAPI.Document, options: SwaggerParser.Options): Promise<SwaggerParser.$Refs>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-redeclare
|
||||||
|
declare namespace SwaggerParser {
|
||||||
|
|
||||||
|
export type ApiCallback = (err: Error | null, api?: OpenAPI.Document) => any;
|
||||||
|
export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/options.html
|
||||||
|
*/
|
||||||
|
export interface Options {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `parse` options determine how different types of files will be parsed.
|
||||||
|
*
|
||||||
|
* JSON Schema `$Ref` Parser comes with built-in JSON, YAML, plain-text, and binary parsers, any of which you can configure or disable. You can also add your own custom parsers if you want.
|
||||||
|
*/
|
||||||
|
parse?: {
|
||||||
|
json?: ParserOptions | boolean;
|
||||||
|
yaml?: ParserOptions | boolean;
|
||||||
|
text?: (ParserOptions & { encoding?: string }) | boolean;
|
||||||
|
[key: string]: ParserOptions | boolean | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `resolve` options control how Swagger Parser will resolve file paths and URLs, and how those files will be read/downloaded.
|
||||||
|
*
|
||||||
|
* JSON Schema `$Ref` Parser comes with built-in support for HTTP and HTTPS, as well as support for local files (when running in Node.js). You can configure or disable either of these built-in resolvers. You can also add your own custom resolvers if you want.
|
||||||
|
*/
|
||||||
|
resolve?: {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether external $ref pointers will be resolved. If this option is disabled, then external `$ref` pointers will simply be ignored.
|
||||||
|
*/
|
||||||
|
external?: boolean;
|
||||||
|
file?: Partial<ResolverOptions> | boolean;
|
||||||
|
http?: HTTPResolverOptions | boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `dereference` options control how JSON Schema `$Ref` Parser will dereference `$ref` pointers within the JSON schema.
|
||||||
|
*/
|
||||||
|
dereference?: {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether circular `$ref` pointers are handled.
|
||||||
|
*
|
||||||
|
* If set to `false`, then a `ReferenceError` will be thrown if the schema contains any circular references.
|
||||||
|
*
|
||||||
|
* If set to `"ignore"`, then circular references will simply be ignored. No error will be thrown, but the `$Refs.circular` property will still be set to `true`.
|
||||||
|
*/
|
||||||
|
circular?: boolean | "ignore";
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `validate` options control how Swagger Parser will validate the API.
|
||||||
|
*/
|
||||||
|
validate?: {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to `false`, then validating against the Swagger 2.0 Schema or OpenAPI 3.0 Schema is disabled.
|
||||||
|
*/
|
||||||
|
schema?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to `false`, then validating against the Swagger 2.0 Specification is disabled.
|
||||||
|
*/
|
||||||
|
spec?: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HTTPResolverOptions extends Partial<ResolverOptions> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can specify any HTTP headers that should be sent when downloading files. For example, some servers may require you to set the `Accept` or `Referrer` header.
|
||||||
|
*/
|
||||||
|
headers?: object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount of time (in milliseconds) to wait for a response from the server when downloading files. The default is 5 seconds.
|
||||||
|
*/
|
||||||
|
timeout?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum number of HTTP redirects to follow per file. The default is 5. To disable automatic following of redirects, set this to zero.
|
||||||
|
*/
|
||||||
|
redirects?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this to `true` if you're downloading files from a CORS-enabled server that requires authentication
|
||||||
|
*/
|
||||||
|
withCredentials?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON Schema `$Ref` Parser comes with built-in resolvers for HTTP and HTTPS URLs, as well as local filesystem paths (when running in Node.js). You can add your own custom resolvers to support additional protocols, or even replace any of the built-in resolvers with your own custom implementation.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/plugins/resolvers.html
|
||||||
|
*/
|
||||||
|
export interface ResolverOptions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All resolvers have an order property, even the built-in resolvers. If you don't specify an order property, then your resolver will run last. Specifying `order: 1`, like we did in this example, will make your resolver run first. Or you can squeeze your resolver in-between some of the built-in resolvers. For example, `order: 101` would make it run after the file resolver, but before the HTTP resolver. You can see the order of all the built-in resolvers by looking at their source code.
|
||||||
|
*
|
||||||
|
* The order property and canRead property are related to each other. For each file that Swagger Parser needs to resolve, it first determines which resolvers can read that file by checking their canRead property. If only one resolver matches a file, then only that one resolver is called, regardless of its order. If multiple resolvers match a file, then those resolvers are tried in order until one of them successfully reads the file. Once a resolver successfully reads the file, the rest of the resolvers are skipped.
|
||||||
|
*/
|
||||||
|
order?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `canRead` property tells JSON Schema `$Ref` Parser what kind of files your resolver can read. In this example, we've simply specified a regular expression that matches "mogodb://" URLs, but we could have used a simple boolean, or even a function with custom logic to determine which files to resolve. Here are examples of each approach:
|
||||||
|
*/
|
||||||
|
canRead: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is where the real work of a resolver happens. The `read` method accepts the same file info object as the `canRead` function, but rather than returning a boolean value, the `read` method should return the contents of the file. The file contents should be returned in as raw a form as possible, such as a string or a byte array. Any further parsing or processing should be done by parsers.
|
||||||
|
*
|
||||||
|
* Unlike the `canRead` function, the `read` method can also be asynchronous. This might be important if your resolver needs to read data from a database or some other external source. You can return your asynchronous value using either an ES6 Promise or a Node.js-style error-first callback. Of course, if your resolver has the ability to return its data synchronously, then that's fine too. Here are examples of all three approaches:
|
||||||
|
*/
|
||||||
|
read(
|
||||||
|
file: FileInfo,
|
||||||
|
callback?: (error: Error | null, data: string | null) => any
|
||||||
|
): string | Buffer | Promise<string | Buffer>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ParserOptions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parsers run in a specific order, relative to other parsers. For example, a parser with `order: 5` will run before a parser with `order: 10`. If a parser is unable to successfully parse a file, then the next parser is tried, until one succeeds or they all fail.
|
||||||
|
*
|
||||||
|
* You can change the order in which parsers run, which is useful if you know that most of your referenced files will be a certain type, or if you add your own custom parser that you want to run first.
|
||||||
|
*/
|
||||||
|
order?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All of the built-in parsers allow empty files by default. The JSON and YAML parsers will parse empty files as `undefined`. The text parser will parse empty files as an empty string. The binary parser will parse empty files as an empty byte array.
|
||||||
|
*
|
||||||
|
* You can set `allowEmpty: false` on any parser, which will cause an error to be thrown if a file empty.
|
||||||
|
*/
|
||||||
|
allowEmpty?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines which parsers will be used for which files.
|
||||||
|
*
|
||||||
|
* A regular expression can be used to match files by their full path. A string (or array of strings) can be used to match files by their file extension. Or a function can be used to perform more complex matching logic. See the custom parser docs for details.
|
||||||
|
*/
|
||||||
|
canParse?: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON Schema `$Ref` Parser supports plug-ins, such as resolvers and parsers. These plug-ins can have methods such as `canRead()`, `read()`, `canParse()`, and `parse()`. All of these methods accept the same object as their parameter: an object containing information about the file being read or parsed.
|
||||||
|
*
|
||||||
|
* The file info object currently only consists of a few properties, but it may grow in the future if plug-ins end up needing more information.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/json-schema-ref-parser/docs/plugins/file-info-object.html
|
||||||
|
*/
|
||||||
|
export interface FileInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The full URL of the file. This could be any type of URL, including "http://", "https://", "file://", "ftp://", "mongodb://", or even a local filesystem path (when running in Node.js).
|
||||||
|
*/
|
||||||
|
url: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The lowercase file extension, such as ".json", ".yaml", ".txt", etc.
|
||||||
|
*/
|
||||||
|
extension: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The raw file contents, in whatever form they were returned by the resolver that read the file.
|
||||||
|
*/
|
||||||
|
data: string | Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you call the resolve method, the value that gets passed to the callback function (or Promise) is a $Refs object. This same object is accessible via the parser.$refs property of SwaggerParser objects.
|
||||||
|
*
|
||||||
|
* This object is a map of JSON References and their resolved values. It also has several convenient helper methods that make it easy for you to navigate and manipulate the JSON References.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/refs.html
|
||||||
|
*/
|
||||||
|
export class $Refs {
|
||||||
|
/**
|
||||||
|
* This property is true if the API definition contains any circular references. You may want to check this property before serializing the dereferenced API definition as JSON, since JSON.stringify() does not support circular references by default.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/refs.html#circular
|
||||||
|
*/
|
||||||
|
public circular: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the paths/URLs of all the files in your API definition (including the main API definition file).
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/refs.html#pathstypes
|
||||||
|
*
|
||||||
|
* @param types (optional) Optionally only return certain types of paths ("file", "http", etc.)
|
||||||
|
*/
|
||||||
|
public paths(...types: string[]): string[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a map of paths/URLs and their correspond values.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/refs.html#valuestypes
|
||||||
|
*
|
||||||
|
* @param types (optional) Optionally only return values from certain locations ("file", "http", etc.)
|
||||||
|
*/
|
||||||
|
public values(...types: string[]): { [url: string]: any }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns `true` if the given path exists in the OpenAPI definition; otherwise, returns `false`
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/refs.html#existsref
|
||||||
|
*
|
||||||
|
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
||||||
|
*/
|
||||||
|
public exists($ref: string): boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value at the given path in the OpenAPI definition. Throws an error if the path does not exist.
|
||||||
|
*
|
||||||
|
* See https://apitools.dev/swagger-parser/docs/refs.html#getref
|
||||||
|
*
|
||||||
|
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
||||||
|
*/
|
||||||
|
public get($ref: string): any
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value at the given path in the OpenAPI definition. If the property, or any of its parents, don't exist, they will be created.
|
||||||
|
*
|
||||||
|
* @param $ref The JSON Reference path, optionally with a JSON Pointer in the hash
|
||||||
|
* @param value The value to assign. Can be anything (object, string, number, etc.)
|
||||||
|
*/
|
||||||
|
public set($ref: string, value: any): void
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
187
node_modules/@apidevtools/swagger-parser/lib/index.js
generated
vendored
Normal file
187
node_modules/@apidevtools/swagger-parser/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,187 @@
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const validateSchema = require("./validators/schema");
|
||||||
|
const validateSpec = require("./validators/spec");
|
||||||
|
const normalizeArgs = require("@apidevtools/json-schema-ref-parser/lib/normalize-args");
|
||||||
|
const util = require("./util");
|
||||||
|
const Options = require("./options");
|
||||||
|
const maybe = require("call-me-maybe");
|
||||||
|
const { ono } = require("@jsdevtools/ono");
|
||||||
|
const $RefParser = require("@apidevtools/json-schema-ref-parser");
|
||||||
|
const dereference = require("@apidevtools/json-schema-ref-parser/lib/dereference");
|
||||||
|
|
||||||
|
module.exports = SwaggerParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class parses a Swagger 2.0 or 3.0 API, resolves its JSON references and their resolved values,
|
||||||
|
* and provides methods for traversing, dereferencing, and validating the API.
|
||||||
|
*
|
||||||
|
* @class
|
||||||
|
* @augments $RefParser
|
||||||
|
*/
|
||||||
|
function SwaggerParser () {
|
||||||
|
$RefParser.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
util.inherits(SwaggerParser, $RefParser);
|
||||||
|
SwaggerParser.parse = $RefParser.parse;
|
||||||
|
SwaggerParser.resolve = $RefParser.resolve;
|
||||||
|
SwaggerParser.bundle = $RefParser.bundle;
|
||||||
|
SwaggerParser.dereference = $RefParser.dereference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias {@link $RefParser#schema} as {@link SwaggerParser#api}
|
||||||
|
*/
|
||||||
|
Object.defineProperty(SwaggerParser.prototype, "api", {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true,
|
||||||
|
get () {
|
||||||
|
return this.schema;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given Swagger API.
|
||||||
|
* This method does not resolve any JSON references.
|
||||||
|
* It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [api] - The Swagger API object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {ParserOptions} [options] - Options that determine how the API is parsed
|
||||||
|
* @param {Function} [callback] - An error-first callback. The second parameter is the parsed API object.
|
||||||
|
* @returns {Promise} - The returned promise resolves with the parsed API object.
|
||||||
|
*/
|
||||||
|
SwaggerParser.prototype.parse = async function (path, api, options, callback) {
|
||||||
|
let args = normalizeArgs(arguments);
|
||||||
|
args.options = new Options(args.options);
|
||||||
|
|
||||||
|
try {
|
||||||
|
let schema = await $RefParser.prototype.parse.call(this, args.path, args.schema, args.options);
|
||||||
|
|
||||||
|
if (schema.swagger) {
|
||||||
|
// Verify that the parsed object is a Swagger API
|
||||||
|
if (schema.swagger === undefined || schema.info === undefined || schema.paths === undefined) {
|
||||||
|
throw ono.syntax(`${args.path || args.schema} is not a valid Swagger API definition`);
|
||||||
|
}
|
||||||
|
else if (typeof schema.swagger === "number") {
|
||||||
|
// This is a very common mistake, so give a helpful error message
|
||||||
|
throw ono.syntax('Swagger version number must be a string (e.g. "2.0") not a number.');
|
||||||
|
}
|
||||||
|
else if (typeof schema.info.version === "number") {
|
||||||
|
// This is a very common mistake, so give a helpful error message
|
||||||
|
throw ono.syntax('API version number must be a string (e.g. "1.0.0") not a number.');
|
||||||
|
}
|
||||||
|
else if (schema.swagger !== "2.0") {
|
||||||
|
throw ono.syntax(`Unrecognized Swagger version: ${schema.swagger}. Expected 2.0`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let supportedVersions = ["3.0.0", "3.0.1", "3.0.2", "3.0.3"];
|
||||||
|
|
||||||
|
// Verify that the parsed object is a Openapi API
|
||||||
|
if (schema.openapi === undefined || schema.info === undefined || schema.paths === undefined) {
|
||||||
|
throw ono.syntax(`${args.path || args.schema} is not a valid Openapi API definition`);
|
||||||
|
}
|
||||||
|
else if (typeof schema.openapi === "number") {
|
||||||
|
// This is a very common mistake, so give a helpful error message
|
||||||
|
throw ono.syntax('Openapi version number must be a string (e.g. "3.0.0") not a number.');
|
||||||
|
}
|
||||||
|
else if (typeof schema.info.version === "number") {
|
||||||
|
// This is a very common mistake, so give a helpful error message
|
||||||
|
throw ono.syntax('API version number must be a string (e.g. "1.0.0") not a number.');
|
||||||
|
}
|
||||||
|
else if (supportedVersions.indexOf(schema.openapi) === -1) {
|
||||||
|
throw ono.syntax(
|
||||||
|
`Unsupported OpenAPI version: ${schema.openapi}. ` +
|
||||||
|
`Swagger Parser only supports versions ${supportedVersions.join(", ")}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Looks good!
|
||||||
|
return maybe(args.callback, Promise.resolve(schema));
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return maybe(args.callback, Promise.reject(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses, dereferences, and validates the given Swagger API.
|
||||||
|
* Depending on the options, validation can include JSON Schema validation and/or Swagger Spec validation.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [api] - The Swagger API object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {ParserOptions} [options] - Options that determine how the API is parsed, dereferenced, and validated
|
||||||
|
* @param {Function} [callback] - An error-first callback. The second parameter is the parsed API object.
|
||||||
|
* @returns {Promise} - The returned promise resolves with the parsed API object.
|
||||||
|
*/
|
||||||
|
SwaggerParser.validate = function (path, api, options, callback) {
|
||||||
|
let Class = this; // eslint-disable-line consistent-this
|
||||||
|
let instance = new Class();
|
||||||
|
return instance.validate.apply(instance, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses, dereferences, and validates the given Swagger API.
|
||||||
|
* Depending on the options, validation can include JSON Schema validation and/or Swagger Spec validation.
|
||||||
|
*
|
||||||
|
* @param {string} [path] - The file path or URL of the JSON schema
|
||||||
|
* @param {object} [api] - The Swagger API object. This object will be used instead of reading from `path`.
|
||||||
|
* @param {ParserOptions} [options] - Options that determine how the API is parsed, dereferenced, and validated
|
||||||
|
* @param {Function} [callback] - An error-first callback. The second parameter is the parsed API object.
|
||||||
|
* @returns {Promise} - The returned promise resolves with the parsed API object.
|
||||||
|
*/
|
||||||
|
SwaggerParser.prototype.validate = async function (path, api, options, callback) {
|
||||||
|
let me = this;
|
||||||
|
let args = normalizeArgs(arguments);
|
||||||
|
args.options = new Options(args.options);
|
||||||
|
|
||||||
|
// ZSchema doesn't support circular objects, so don't dereference circular $refs yet
|
||||||
|
// (see https://github.com/zaggino/z-schema/issues/137)
|
||||||
|
let circular$RefOption = args.options.dereference.circular;
|
||||||
|
args.options.validate.schema && (args.options.dereference.circular = "ignore");
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.dereference(args.path, args.schema, args.options);
|
||||||
|
|
||||||
|
// Restore the original options, now that we're done dereferencing
|
||||||
|
args.options.dereference.circular = circular$RefOption;
|
||||||
|
|
||||||
|
if (args.options.validate.schema) {
|
||||||
|
// Validate the API against the Swagger schema
|
||||||
|
// NOTE: This is safe to do, because we haven't dereferenced circular $refs yet
|
||||||
|
validateSchema(me.api);
|
||||||
|
|
||||||
|
if (me.$refs.circular) {
|
||||||
|
if (circular$RefOption === true) {
|
||||||
|
// The API has circular references,
|
||||||
|
// so we need to do a second-pass to fully-dereference it
|
||||||
|
dereference(me, args.options);
|
||||||
|
}
|
||||||
|
else if (circular$RefOption === false) {
|
||||||
|
// The API has circular references, and they're not allowed, so throw an error
|
||||||
|
throw ono.reference("The API contains circular references");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.options.validate.spec) {
|
||||||
|
// Validate the API against the Swagger spec
|
||||||
|
validateSpec(me.api);
|
||||||
|
}
|
||||||
|
|
||||||
|
return maybe(args.callback, Promise.resolve(me.schema));
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return maybe(args.callback, Promise.reject(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Swagger object
|
||||||
|
* https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#swagger-object
|
||||||
|
*
|
||||||
|
* @typedef {{swagger: string, info: {}, paths: {}}} SwaggerObject
|
||||||
|
*/
|
||||||
35
node_modules/@apidevtools/swagger-parser/lib/options.js
generated
vendored
Normal file
35
node_modules/@apidevtools/swagger-parser/lib/options.js
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const $RefParserOptions = require("@apidevtools/json-schema-ref-parser/lib/options");
|
||||||
|
const schemaValidator = require("./validators/schema");
|
||||||
|
const specValidator = require("./validators/spec");
|
||||||
|
const util = require("util");
|
||||||
|
|
||||||
|
module.exports = ParserOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options that determine how Swagger APIs are parsed, resolved, dereferenced, and validated.
|
||||||
|
*
|
||||||
|
* @param {object|ParserOptions} [_options] - Overridden options
|
||||||
|
* @class
|
||||||
|
* @augments $RefParserOptions
|
||||||
|
*/
|
||||||
|
function ParserOptions (_options) {
|
||||||
|
$RefParserOptions.call(this, ParserOptions.defaults);
|
||||||
|
$RefParserOptions.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
ParserOptions.defaults = {
|
||||||
|
/**
|
||||||
|
* Determines how the API definition will be validated.
|
||||||
|
*
|
||||||
|
* You can add additional validators of your own, replace an existing one with
|
||||||
|
* your own implemenation, or disable any validator by setting it to false.
|
||||||
|
*/
|
||||||
|
validate: {
|
||||||
|
schema: schemaValidator,
|
||||||
|
spec: specValidator,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
util.inherits(ParserOptions, $RefParserOptions);
|
||||||
11
node_modules/@apidevtools/swagger-parser/lib/util.js
generated
vendored
Normal file
11
node_modules/@apidevtools/swagger-parser/lib/util.js
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const util = require("util");
|
||||||
|
|
||||||
|
exports.format = util.format;
|
||||||
|
exports.inherits = util.inherits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regular Expression that matches Swagger path params.
|
||||||
|
*/
|
||||||
|
exports.swaggerParamRegExp = /\{([^/}]+)}/g;
|
||||||
70
node_modules/@apidevtools/swagger-parser/lib/validators/schema.js
generated
vendored
Normal file
70
node_modules/@apidevtools/swagger-parser/lib/validators/schema.js
generated
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const util = require("../util");
|
||||||
|
const { ono } = require("@jsdevtools/ono");
|
||||||
|
const ZSchema = require("z-schema");
|
||||||
|
const { openapi } = require("@apidevtools/openapi-schemas");
|
||||||
|
|
||||||
|
module.exports = validateSchema;
|
||||||
|
|
||||||
|
let zSchema = initializeZSchema();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the given Swagger API against the Swagger 2.0 or 3.0 schema.
|
||||||
|
*
|
||||||
|
* @param {SwaggerObject} api
|
||||||
|
*/
|
||||||
|
function validateSchema (api) {
|
||||||
|
// Choose the appropriate schema (Swagger or OpenAPI)
|
||||||
|
let schema = api.swagger ? openapi.v2 : openapi.v3;
|
||||||
|
|
||||||
|
// Validate against the schema
|
||||||
|
let isValid = zSchema.validate(api, schema);
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
let err = zSchema.getLastError();
|
||||||
|
let message = "Swagger schema validation failed. \n" + formatZSchemaError(err.details);
|
||||||
|
throw ono.syntax(err, { details: err.details }, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs one-time initialization logic to prepare for Swagger Schema validation.
|
||||||
|
*/
|
||||||
|
function initializeZSchema () {
|
||||||
|
// HACK: Delete the OpenAPI schema IDs because ZSchema can't resolve them
|
||||||
|
delete openapi.v2.id;
|
||||||
|
delete openapi.v3.id;
|
||||||
|
|
||||||
|
// The OpenAPI 3.0 schema uses "uri-reference" formats.
|
||||||
|
// Assume that any non-whitespace string is valid.
|
||||||
|
ZSchema.registerFormat("uri-reference", (value) => value.trim().length > 0);
|
||||||
|
|
||||||
|
// Configure ZSchema
|
||||||
|
return new ZSchema({
|
||||||
|
breakOnFirstError: true,
|
||||||
|
noExtraKeywords: true,
|
||||||
|
ignoreUnknownFormats: false,
|
||||||
|
reportPathAsArray: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Z-Schema validation errors are a nested tree structure.
|
||||||
|
* This function crawls that tree and builds an error message string.
|
||||||
|
*
|
||||||
|
* @param {object[]} errors - The Z-Schema error details
|
||||||
|
* @param {string} [indent] - The whitespace used to indent the error message
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function formatZSchemaError (errors, indent) {
|
||||||
|
indent = indent || " ";
|
||||||
|
let message = "";
|
||||||
|
for (let error of errors) {
|
||||||
|
message += util.format(`${indent}${error.message} at #/${error.path.join("/")}\n`);
|
||||||
|
if (error.inner) {
|
||||||
|
message += formatZSchemaError(error.inner, indent + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
344
node_modules/@apidevtools/swagger-parser/lib/validators/spec.js
generated
vendored
Normal file
344
node_modules/@apidevtools/swagger-parser/lib/validators/spec.js
generated
vendored
Normal file
|
|
@ -0,0 +1,344 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const util = require("../util");
|
||||||
|
const { ono } = require("@jsdevtools/ono");
|
||||||
|
const swaggerMethods = require("@apidevtools/swagger-methods");
|
||||||
|
const primitiveTypes = ["array", "boolean", "integer", "number", "string"];
|
||||||
|
const schemaTypes = ["array", "boolean", "integer", "number", "string", "object", "null", undefined];
|
||||||
|
|
||||||
|
module.exports = validateSpec;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates parts of the Swagger 2.0 spec that aren't covered by the Swagger 2.0 JSON Schema.
|
||||||
|
*
|
||||||
|
* @param {SwaggerObject} api
|
||||||
|
*/
|
||||||
|
function validateSpec (api) {
|
||||||
|
if (api.openapi) {
|
||||||
|
// We don't (yet) support validating against the OpenAPI spec
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let paths = Object.keys(api.paths || {});
|
||||||
|
let operationIds = [];
|
||||||
|
for (let pathName of paths) {
|
||||||
|
let path = api.paths[pathName];
|
||||||
|
let pathId = "/paths" + pathName;
|
||||||
|
|
||||||
|
if (path && pathName.indexOf("/") === 0) {
|
||||||
|
validatePath(api, path, pathId, operationIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let definitions = Object.keys(api.definitions || {});
|
||||||
|
for (let definitionName of definitions) {
|
||||||
|
let definition = api.definitions[definitionName];
|
||||||
|
let definitionId = "/definitions/" + definitionName;
|
||||||
|
validateRequiredPropertiesExist(definition, definitionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the given path.
|
||||||
|
*
|
||||||
|
* @param {SwaggerObject} api - The entire Swagger API object
|
||||||
|
* @param {object} path - A Path object, from the Swagger API
|
||||||
|
* @param {string} pathId - A value that uniquely identifies the path
|
||||||
|
* @param {string} operationIds - An array of collected operationIds found in other paths
|
||||||
|
*/
|
||||||
|
function validatePath (api, path, pathId, operationIds) {
|
||||||
|
for (let operationName of swaggerMethods) {
|
||||||
|
let operation = path[operationName];
|
||||||
|
let operationId = pathId + "/" + operationName;
|
||||||
|
|
||||||
|
if (operation) {
|
||||||
|
let declaredOperationId = operation.operationId;
|
||||||
|
if (declaredOperationId) {
|
||||||
|
if (operationIds.indexOf(declaredOperationId) === -1) {
|
||||||
|
operationIds.push(declaredOperationId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw ono.syntax(`Validation failed. Duplicate operation id '${declaredOperationId}'`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
validateParameters(api, path, pathId, operation, operationId);
|
||||||
|
|
||||||
|
let responses = Object.keys(operation.responses || {});
|
||||||
|
for (let responseName of responses) {
|
||||||
|
let response = operation.responses[responseName];
|
||||||
|
let responseId = operationId + "/responses/" + responseName;
|
||||||
|
validateResponse(responseName, (response || {}), responseId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the parameters for the given operation.
|
||||||
|
*
|
||||||
|
* @param {SwaggerObject} api - The entire Swagger API object
|
||||||
|
* @param {object} path - A Path object, from the Swagger API
|
||||||
|
* @param {string} pathId - A value that uniquely identifies the path
|
||||||
|
* @param {object} operation - An Operation object, from the Swagger API
|
||||||
|
* @param {string} operationId - A value that uniquely identifies the operation
|
||||||
|
*/
|
||||||
|
function validateParameters (api, path, pathId, operation, operationId) {
|
||||||
|
let pathParams = path.parameters || [];
|
||||||
|
let operationParams = operation.parameters || [];
|
||||||
|
|
||||||
|
// Check for duplicate path parameters
|
||||||
|
try {
|
||||||
|
checkForDuplicates(pathParams);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
throw ono.syntax(e, `Validation failed. ${pathId} has duplicate parameters`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for duplicate operation parameters
|
||||||
|
try {
|
||||||
|
checkForDuplicates(operationParams);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
throw ono.syntax(e, `Validation failed. ${operationId} has duplicate parameters`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine the path and operation parameters,
|
||||||
|
// with the operation params taking precedence over the path params
|
||||||
|
let params = pathParams.reduce((combinedParams, value) => {
|
||||||
|
let duplicate = combinedParams.some((param) => {
|
||||||
|
return param.in === value.in && param.name === value.name;
|
||||||
|
});
|
||||||
|
if (!duplicate) {
|
||||||
|
combinedParams.push(value);
|
||||||
|
}
|
||||||
|
return combinedParams;
|
||||||
|
}, operationParams.slice());
|
||||||
|
|
||||||
|
validateBodyParameters(params, operationId);
|
||||||
|
validatePathParameters(params, pathId, operationId);
|
||||||
|
validateParameterTypes(params, api, operation, operationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates body and formData parameters for the given operation.
|
||||||
|
*
|
||||||
|
* @param {object[]} params - An array of Parameter objects
|
||||||
|
* @param {string} operationId - A value that uniquely identifies the operation
|
||||||
|
*/
|
||||||
|
function validateBodyParameters (params, operationId) {
|
||||||
|
let bodyParams = params.filter((param) => { return param.in === "body"; });
|
||||||
|
let formParams = params.filter((param) => { return param.in === "formData"; });
|
||||||
|
|
||||||
|
// There can only be one "body" parameter
|
||||||
|
if (bodyParams.length > 1) {
|
||||||
|
throw ono.syntax(
|
||||||
|
`Validation failed. ${operationId} has ${bodyParams.length} body parameters. Only one is allowed.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (bodyParams.length > 0 && formParams.length > 0) {
|
||||||
|
// "body" params and "formData" params are mutually exclusive
|
||||||
|
throw ono.syntax(
|
||||||
|
`Validation failed. ${operationId} has body parameters and formData parameters. Only one or the other is allowed.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates path parameters for the given path.
|
||||||
|
*
|
||||||
|
* @param {object[]} params - An array of Parameter objects
|
||||||
|
* @param {string} pathId - A value that uniquely identifies the path
|
||||||
|
* @param {string} operationId - A value that uniquely identifies the operation
|
||||||
|
*/
|
||||||
|
function validatePathParameters (params, pathId, operationId) {
|
||||||
|
// Find all {placeholders} in the path string
|
||||||
|
let placeholders = pathId.match(util.swaggerParamRegExp) || [];
|
||||||
|
|
||||||
|
// Check for duplicates
|
||||||
|
for (let i = 0; i < placeholders.length; i++) {
|
||||||
|
for (let j = i + 1; j < placeholders.length; j++) {
|
||||||
|
if (placeholders[i] === placeholders[j]) {
|
||||||
|
throw ono.syntax(
|
||||||
|
`Validation failed. ${operationId} has multiple path placeholders named ${placeholders[i]}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params = params.filter((param) => { return param.in === "path"; });
|
||||||
|
|
||||||
|
for (let param of params) {
|
||||||
|
if (param.required !== true) {
|
||||||
|
throw ono.syntax(
|
||||||
|
"Validation failed. Path parameters cannot be optional. " +
|
||||||
|
`Set required=true for the "${param.name}" parameter at ${operationId}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let match = placeholders.indexOf("{" + param.name + "}");
|
||||||
|
if (match === -1) {
|
||||||
|
throw ono.syntax(
|
||||||
|
`Validation failed. ${operationId} has a path parameter named "${param.name}", ` +
|
||||||
|
`but there is no corresponding {${param.name}} in the path string`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
placeholders.splice(match, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (placeholders.length > 0) {
|
||||||
|
throw ono.syntax(`Validation failed. ${operationId} is missing path parameter(s) for ${placeholders}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates data types of parameters for the given operation.
|
||||||
|
*
|
||||||
|
* @param {object[]} params - An array of Parameter objects
|
||||||
|
* @param {object} api - The entire Swagger API object
|
||||||
|
* @param {object} operation - An Operation object, from the Swagger API
|
||||||
|
* @param {string} operationId - A value that uniquely identifies the operation
|
||||||
|
*/
|
||||||
|
function validateParameterTypes (params, api, operation, operationId) {
|
||||||
|
for (let param of params) {
|
||||||
|
let parameterId = operationId + "/parameters/" + param.name;
|
||||||
|
let schema, validTypes;
|
||||||
|
|
||||||
|
switch (param.in) {
|
||||||
|
case "body":
|
||||||
|
schema = param.schema;
|
||||||
|
validTypes = schemaTypes;
|
||||||
|
break;
|
||||||
|
case "formData":
|
||||||
|
schema = param;
|
||||||
|
validTypes = primitiveTypes.concat("file");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
schema = param;
|
||||||
|
validTypes = primitiveTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
validateSchema(schema, parameterId, validTypes);
|
||||||
|
validateRequiredPropertiesExist(schema, parameterId);
|
||||||
|
|
||||||
|
if (schema.type === "file") {
|
||||||
|
// "file" params must consume at least one of these MIME types
|
||||||
|
let formData = /multipart\/(.*\+)?form-data/;
|
||||||
|
let urlEncoded = /application\/(.*\+)?x-www-form-urlencoded/;
|
||||||
|
|
||||||
|
let consumes = operation.consumes || api.consumes || [];
|
||||||
|
|
||||||
|
let hasValidMimeType = consumes.some((consume) => {
|
||||||
|
return formData.test(consume) || urlEncoded.test(consume);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hasValidMimeType) {
|
||||||
|
throw ono.syntax(
|
||||||
|
`Validation failed. ${operationId} has a file parameter, so it must consume multipart/form-data ` +
|
||||||
|
"or application/x-www-form-urlencoded",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the given parameter list for duplicates, and throws an error if found.
|
||||||
|
*
|
||||||
|
* @param {object[]} params - An array of Parameter objects
|
||||||
|
*/
|
||||||
|
function checkForDuplicates (params) {
|
||||||
|
for (let i = 0; i < params.length - 1; i++) {
|
||||||
|
let outer = params[i];
|
||||||
|
for (let j = i + 1; j < params.length; j++) {
|
||||||
|
let inner = params[j];
|
||||||
|
if (outer.name === inner.name && outer.in === inner.in) {
|
||||||
|
throw ono.syntax(`Validation failed. Found multiple ${outer.in} parameters named "${outer.name}"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the given response object.
|
||||||
|
*
|
||||||
|
* @param {string} code - The HTTP response code (or "default")
|
||||||
|
* @param {object} response - A Response object, from the Swagger API
|
||||||
|
* @param {string} responseId - A value that uniquely identifies the response
|
||||||
|
*/
|
||||||
|
function validateResponse (code, response, responseId) {
|
||||||
|
if (code !== "default" && (code < 100 || code > 599)) {
|
||||||
|
throw ono.syntax(`Validation failed. ${responseId} has an invalid response code (${code})`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let headers = Object.keys(response.headers || {});
|
||||||
|
for (let headerName of headers) {
|
||||||
|
let header = response.headers[headerName];
|
||||||
|
let headerId = responseId + "/headers/" + headerName;
|
||||||
|
validateSchema(header, headerId, primitiveTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.schema) {
|
||||||
|
let validTypes = schemaTypes.concat("file");
|
||||||
|
if (validTypes.indexOf(response.schema.type) === -1) {
|
||||||
|
throw ono.syntax(
|
||||||
|
`Validation failed. ${responseId} has an invalid response schema type (${response.schema.type})`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
validateSchema(response.schema, responseId + "/schema", validTypes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the given Swagger schema object.
|
||||||
|
*
|
||||||
|
* @param {object} schema - A Schema object, from the Swagger API
|
||||||
|
* @param {string} schemaId - A value that uniquely identifies the schema object
|
||||||
|
* @param {string[]} validTypes - An array of the allowed schema types
|
||||||
|
*/
|
||||||
|
function validateSchema (schema, schemaId, validTypes) {
|
||||||
|
if (validTypes.indexOf(schema.type) === -1) {
|
||||||
|
throw ono.syntax(
|
||||||
|
`Validation failed. ${schemaId} has an invalid type (${schema.type})`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.type === "array" && !schema.items) {
|
||||||
|
throw ono.syntax(`Validation failed. ${schemaId} is an array, so it must include an "items" schema`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates that the declared properties of the given Swagger schema object actually exist.
|
||||||
|
*
|
||||||
|
* @param {object} schema - A Schema object, from the Swagger API
|
||||||
|
* @param {string} schemaId - A value that uniquely identifies the schema object
|
||||||
|
*/
|
||||||
|
function validateRequiredPropertiesExist (schema, schemaId) {
|
||||||
|
/**
|
||||||
|
* Recursively collects all properties of the schema and its ancestors. They are added to the props object.
|
||||||
|
*/
|
||||||
|
function collectProperties (schemaObj, props) {
|
||||||
|
if (schemaObj.properties) {
|
||||||
|
for (let property in schemaObj.properties) {
|
||||||
|
if (schemaObj.properties.hasOwnProperty(property)) {
|
||||||
|
props[property] = schemaObj.properties[property];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (schemaObj.allOf) {
|
||||||
|
for (let parent of schemaObj.allOf) {
|
||||||
|
collectProperties(parent, props);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.required && Array.isArray(schema.required)) {
|
||||||
|
let props = {};
|
||||||
|
collectProperties(schema, props);
|
||||||
|
for (let requiredProperty of schema.required) {
|
||||||
|
if (!props[requiredProperty]) {
|
||||||
|
throw ono.syntax(
|
||||||
|
`Validation failed. Property '${requiredProperty}' listed as required but does not exist in '${schemaId}'`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
87
node_modules/@apidevtools/swagger-parser/package.json
generated
vendored
Normal file
87
node_modules/@apidevtools/swagger-parser/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
{
|
||||||
|
"name": "@apidevtools/swagger-parser",
|
||||||
|
"version": "10.0.3",
|
||||||
|
"description": "Swagger 2.0 and OpenAPI 3.0 parser and validator for Node and browsers",
|
||||||
|
"keywords": [
|
||||||
|
"swagger",
|
||||||
|
"openapi",
|
||||||
|
"open-api",
|
||||||
|
"json",
|
||||||
|
"yaml",
|
||||||
|
"parse",
|
||||||
|
"parser",
|
||||||
|
"validate",
|
||||||
|
"validator",
|
||||||
|
"validation",
|
||||||
|
"spec",
|
||||||
|
"specification",
|
||||||
|
"schema",
|
||||||
|
"reference",
|
||||||
|
"dereference"
|
||||||
|
],
|
||||||
|
"author": {
|
||||||
|
"name": "James Messinger",
|
||||||
|
"url": "https://jamesmessinger.com"
|
||||||
|
},
|
||||||
|
"homepage": "https://apitools.dev/swagger-parser/",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/APIDevTools/swagger-parser.git"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"typings": "lib/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"clean": "shx rm -rf .nyc_output coverage",
|
||||||
|
"lint": "eslint lib test online/src/js",
|
||||||
|
"build": "npm run build:website && npm run build:sass",
|
||||||
|
"build:website": "simplifyify online/src/js/index.js --outfile online/js/bundle.js --bundle --debug --minify",
|
||||||
|
"build:sass": "node-sass --source-map true --output-style compressed online/src/scss/style.scss online/css/style.min.css",
|
||||||
|
"test": "npm run test:node && npm run test:typescript && npm run test:browser && npm run lint",
|
||||||
|
"test:node": "mocha",
|
||||||
|
"test:browser": "karma start --single-run",
|
||||||
|
"test:typescript": "tsc --noEmit --strict --lib esnext,dom test/specs/typescript-definition.spec.ts",
|
||||||
|
"coverage": "npm run coverage:node && npm run coverage:browser",
|
||||||
|
"coverage:node": "nyc node_modules/mocha/bin/mocha",
|
||||||
|
"coverage:browser": "npm run test:browser -- --coverage",
|
||||||
|
"upgrade": "npm-check -u && npm audit fix",
|
||||||
|
"bump": "bump --tag --push --all",
|
||||||
|
"release": "npm run upgrade && npm run clean && npm run build && npm test && npm run bump"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/polyfill": "^7.11.5",
|
||||||
|
"@jsdevtools/eslint-config": "^1.1.4",
|
||||||
|
"@jsdevtools/host-environment": "^2.1.2",
|
||||||
|
"@jsdevtools/karma-config": "^3.1.7",
|
||||||
|
"@jsdevtools/version-bump-prompt": "^6.1.0",
|
||||||
|
"@types/node": "^14.6.4",
|
||||||
|
"chai": "^4.2.0",
|
||||||
|
"eslint": "^7.8.1",
|
||||||
|
"js-yaml": "^3.14.0",
|
||||||
|
"karma": "^5.2.1",
|
||||||
|
"karma-cli": "^2.0.0",
|
||||||
|
"mocha": "^8.1.3",
|
||||||
|
"node-fetch": "^2.6.1",
|
||||||
|
"node-sass": "^4.14.1",
|
||||||
|
"npm-check": "^5.9.0",
|
||||||
|
"nyc": "^15.1.0",
|
||||||
|
"openapi-types": "^7.0.1",
|
||||||
|
"shx": "^0.3.2",
|
||||||
|
"simplifyify": "^8.0.3",
|
||||||
|
"typescript": "^4.0.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@apidevtools/json-schema-ref-parser": "^9.0.6",
|
||||||
|
"@apidevtools/openapi-schemas": "^2.0.4",
|
||||||
|
"@apidevtools/swagger-methods": "^3.0.2",
|
||||||
|
"@jsdevtools/ono": "^7.1.3",
|
||||||
|
"call-me-maybe": "^1.0.1",
|
||||||
|
"z-schema": "^5.0.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"openapi-types": ">=7"
|
||||||
|
}
|
||||||
|
}
|
||||||
122
node_modules/@jsdevtools/ono/CHANGELOG.md
generated
vendored
Normal file
122
node_modules/@jsdevtools/ono/CHANGELOG.md
generated
vendored
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
Change Log
|
||||||
|
=======================================
|
||||||
|
All notable changes will be documented in this file.
|
||||||
|
`ono` adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v7.1.0](https://github.com/JS-DevTools/ono/tree/v7.1.0) (2020-03-03)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Added a static `Ono.extend()` method that allows Ono to extend errors that were created outside of Ono. The extended error gets all the Ono functionality, including nested stack traces, custom properties, improved support for `JSON.stringify()`, etc.
|
||||||
|
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v7.0.1...v7.1.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v7.0.0](https://github.com/JS-DevTools/ono/tree/v7.0.0) (2020-02-16)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Moved Ono to the [@JSDevTools scope](https://www.npmjs.com/org/jsdevtools) on NPM
|
||||||
|
|
||||||
|
- The "ono" NPM package is now just a wrapper around the scoped "@jsdevtools/ono" package
|
||||||
|
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v6.0.1...v7.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v6.0.0](https://github.com/JS-DevTools/ono/tree/v6.0.0) (2019-12-28)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
- Dropped support for IE8 and other JavaScript engines that don't support [`Object.getOwnPropertyDescriptor()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
|
||||||
|
|
||||||
|
- Removed `ono.formatter`. It has been replaced with [the `format` option](https://github.com/JS-DevTools/ono#format-option)
|
||||||
|
|
||||||
|
- When using the default `ono()` function to wrap an error, it will now try to match the error's type, rather than simply using the base `Error` class.
|
||||||
|
|
||||||
|
### New Features
|
||||||
|
|
||||||
|
- The [`Ono` constructor](https://github.com/JS-DevTools/ono#onoerror-options) now accepts an optional [options parameter](https://github.com/JS-DevTools/ono#options), which lets you customize the behavior of Ono
|
||||||
|
|
||||||
|
- The [`concatMessages` option](https://github.com/JS-DevTools/ono#concatmessages-option) lets you control whether the original error's message is appended to your error message
|
||||||
|
|
||||||
|
- The [`format` option](https://github.com/JS-DevTools/ono#format-option) lets you provide a custom function for replacing placeholders in error messages
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v5.1.0...v6.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v5.1.0](https://github.com/JS-DevTools/ono/tree/v5.1.0) (2019-09-10)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Added a static `Ono.toJSON()` method that accepts any `Error` (even a non-Ono error) and returns a POJO that can be used with `JSON.stringify()`. Ono errors already have a built-in `toJSON()` method, but this exposes that enhanced functionality in a way that can be used with _any_ error.
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v5.0.2...v5.1.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v5.0.0](https://github.com/JS-DevTools/ono/tree/v5.0.0) (2019-02-18)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
#### in Node.js
|
||||||
|
|
||||||
|
- Ono errors previously included an `inspect()` method to support Node's [`util.inspect()` function](https://nodejs.org/api/util.html#util_util_inspect_object_options). As of Node v6.6.0, the `inspect()` method is deprecated in favor of a [`util.inspect.custom`](https://nodejs.org/api/util.html#util_util_inspect_custom). Ono has updated accordingly, so errors no longer have an `inspect()` method.
|
||||||
|
|
||||||
|
#### in Web Browsers
|
||||||
|
|
||||||
|
- We no longer automatically include a polyfill for [Node's `util.format()` function](https://nodejs.org/api/util.html#util_util_format_format_args). We recommend using [ES6 template strings](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) instead. Or you can import [a polyfill](https://github.com/tmpfs/format-util) yourself and assign it to [the `ono.formatter` property](https://jstools.dev/ono/#onoformatter).
|
||||||
|
|
||||||
|
### New Features
|
||||||
|
|
||||||
|
- Completely rewritten in TypeScript.
|
||||||
|
|
||||||
|
- Ono is now completely dependency free.
|
||||||
|
|
||||||
|
- You can now create your own Ono functions for custom error classes. See [the docs](https://jstools.dev/ono/#custom-error-classes) for details.
|
||||||
|
|
||||||
|
- Symbol-keyed properties are now supported. If the `originalError` and/or `props` objects has Symbol-keyed properties, they will be copied to the Ono error.
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v4.0.11...v5.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v4.0.0](https://github.com/JS-DevTools/ono/tree/v4.0.0) (2017-07-07)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
The `err` parameter (see [the API docs](https://github.com/JS-DevTools/ono#api)) can now be any type of object, not just an `instanceof Error`. This allows for errors that don't extend from the `Error` class, such as [`DOMError`](https://developer.mozilla.org/en-US/docs/Web/API/DOMError), [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException), and custom error types.
|
||||||
|
|
||||||
|
> **NOTE:** This should **not** be a breaking change, but I'm bumping the major version number out of an abundance of caution.
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v3.1.0...v4.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v3.1.0](https://github.com/JS-DevTools/ono/tree/v3.1.0) (2017-06-01)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
We removed the direct dependency on [Node's `util.format()`](https://nodejs.org/api/util.html#util_util_format_format_args), which was needlessly bloating the browser bundle. Instead, I now import [`format-util`](https://www.npmjs.com/package/format-util), which a much more [lightweight browser implementation](https://github.com/tmpfs/format-util/blob/f88c550ef10c5aaadc15a7ebab595f891bb385e1/format.js). There's no change when running in Node.js, because `format-util` simply [exports `util.format()`](https://github.com/tmpfs/format-util/blob/392628c5d45e558589f2f19ffb9d79d4b5540010/index.js#L1).
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v3.0.0...v3.1.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v3.0.0](https://github.com/JS-DevTools/ono/tree/v3.0.0) (2017-06-01)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
- Updated all dependencies and verified support for Node 8.0
|
||||||
|
- Ono no longer appears in error stack traces, so errors look like they came directly from your code
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v2.0.0...v3.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[v2.0.0](https://github.com/JS-DevTools/ono/tree/v2.0.0) (2015-12-14)
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
- Did a major refactoring and code cleanup
|
||||||
|
- Support for various browser-specific `Error.prototype` properties (`fileName`, `lineNumber`, `sourceURL`, etc.)
|
||||||
|
- If you define a custom `toJSON()` method on an error object, Ono will no longer overwrite it
|
||||||
|
- Added support for Node's `util.inspect()`
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v1.0.22...v2.0.0)
|
||||||
23
node_modules/@jsdevtools/ono/LICENSE
generated
vendored
Normal file
23
node_modules/@jsdevtools/ono/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 James Messinger
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
.
|
||||||
392
node_modules/@jsdevtools/ono/README.md
generated
vendored
Normal file
392
node_modules/@jsdevtools/ono/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,392 @@
|
||||||
|
ono (Oh No!)
|
||||||
|
============================
|
||||||
|
### Throw better errors.
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/@jsdevtools/ono)
|
||||||
|
[](LICENSE)
|
||||||
|
[](https://plant.treeware.earth/JS-DevTools/ono)
|
||||||
|
|
||||||
|
[](https://github.com/JS-DevTools/ono/actions)
|
||||||
|
[](https://coveralls.io/github/JS-DevTools/ono)
|
||||||
|
[](https://david-dm.org/JS-DevTools/ono)
|
||||||
|
|
||||||
|
[](https://github.com/JS-DevTools/ono/actions)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Features
|
||||||
|
--------------------------
|
||||||
|
- Wrap and re-throw an error _without_ losing the original error's type, message, stack trace, and properties
|
||||||
|
|
||||||
|
- Add custom properties to errors — great for error numbers, status codes, etc.
|
||||||
|
|
||||||
|
- Use [format strings](#format-option) for error messages — great for localization
|
||||||
|
|
||||||
|
- Enhanced support for [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) and [`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options) — great for logging
|
||||||
|
|
||||||
|
- Supports and enhances your own [custom error classes](#custom-error-classes)
|
||||||
|
|
||||||
|
- Tested on Node.js and all modern web browsers on Mac, Windows, and Linux.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Example
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const ono = require("@jsdevtools/ono");
|
||||||
|
|
||||||
|
// Throw an error with custom properties
|
||||||
|
throw ono({ code: "NOT_FOUND", status: 404 }, `Resource not found: ${url}`);
|
||||||
|
|
||||||
|
// Wrap an error without losing the original error's stack and props
|
||||||
|
throw ono(originalError, "An error occurred while saving your changes");
|
||||||
|
|
||||||
|
// Wrap an error and add custom properties
|
||||||
|
throw ono(originalError, { code: 404, status: "NOT_FOUND" });
|
||||||
|
|
||||||
|
// Wrap an error, add custom properties, and change the error message
|
||||||
|
throw ono(originalError, { code: 404, status: "NOT_FOUND" }, `Resource not found: ${url}`);
|
||||||
|
|
||||||
|
// Throw a specific Error subtype instead
|
||||||
|
// (works with any of the above signatures)
|
||||||
|
throw ono.range(...); // RangeError
|
||||||
|
throw ono.syntax(...); // SyntaxError
|
||||||
|
throw ono.reference(...); // ReferenceError
|
||||||
|
|
||||||
|
// Create an Ono method for your own custom error class
|
||||||
|
const { Ono } = require("@jsdevtools/ono");
|
||||||
|
class MyErrorClass extends Error {}
|
||||||
|
ono.myError = new Ono(MyErrorClass);
|
||||||
|
|
||||||
|
// And use it just like any other Ono method
|
||||||
|
throw ono.myError(...); // MyErrorClass
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
--------------------------
|
||||||
|
Install using [npm](https://docs.npmjs.com/about-npm/):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install @jsdevtools/ono
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
--------------------------
|
||||||
|
When using Ono in Node.js apps, you'll probably want to use **CommonJS** syntax:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const ono = require("@jsdevtools/ono");
|
||||||
|
```
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import ono from "@jsdevtools/ono";
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Browser support
|
||||||
|
--------------------------
|
||||||
|
Ono 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).
|
||||||
|
|
||||||
|
To use Ono 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).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
API
|
||||||
|
--------------------------
|
||||||
|
### `ono([originalError], [props], [message, ...])`
|
||||||
|
Creates an [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object with the given properties.
|
||||||
|
|
||||||
|
* `originalError` - _(optional)_ The original error that occurred, if any. This error's message, stack trace, and properties will be copied to the new error. If this error's type is one of the [known error types](#specific-error-types), then the new error will be of the same type.
|
||||||
|
|
||||||
|
* `props` - _(optional)_ An object whose properties will be copied to the new error. Properties can be anything, including objects and functions.
|
||||||
|
|
||||||
|
* `message` - _(optional)_ The error message string. If it contains placeholders, then pass each placeholder's value as an additional parameter. See the [`format` option](#format-option) for more info.
|
||||||
|
|
||||||
|
### Specific error types
|
||||||
|
The default `ono()` function may return an instance of the base [`Error` class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error), or it may return a more specific sub-class, based on the type of the `originalError` argument. If you want to _explicitly_ create a specific type of error, then you can use any of the following methods:
|
||||||
|
|
||||||
|
The method signatures and arguments are exactly the same as [the default `ono()` function](#onooriginalerror-props-message-).
|
||||||
|
|
||||||
|
|Method | Return Type
|
||||||
|
|:---------------------------|:-------------------
|
||||||
|
|`ono.error()` |[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
|
||||||
|
|`ono.eval()` |[`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
|
||||||
|
|`ono.range()` |[`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
|
||||||
|
|`ono.reference()` |[`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
|
||||||
|
|`ono.syntax()` |[`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
|
||||||
|
|`ono.type()` |[`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
|
||||||
|
|`ono.uri()` |[`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
|
||||||
|
|`ono.yourCustomErrorHere()` |Add your own [custom error classes](#custom-error-classes) to ono
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### `Ono(Error, [options])`
|
||||||
|
The `Ono` constructor is used to create your own [custom `ono` methods](#custom-error-classes) for custom error types, or to change the default behavior of the built-in methods.
|
||||||
|
|
||||||
|
> **Warning:** Be sure not to confuse `ono` (lowercase) and `Ono` (capitalized). The latter one is a class.
|
||||||
|
|
||||||
|
* `Error` - The Error sub-class that this Ono method will create instances of
|
||||||
|
|
||||||
|
* `options` - _(optional)_ An [options object](#options), which customizes the behavior of the Ono method
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Options
|
||||||
|
---------------------------------
|
||||||
|
The `Ono` constructor takes an optional options object as a second parameter. The object can have the following properties, all of which are optional:
|
||||||
|
|
||||||
|
|Option |Type |Default |Description
|
||||||
|
|-----------------|------------|-------------|---------------------------------------------------------------
|
||||||
|
|`concatMessages` |boolean |`true` |When Ono is used to wrap an error, this setting determines whether the inner error's message is appended to the new error message.
|
||||||
|
|`format` |function or boolean |[`util.format()`](https://nodejs.org/api/util.html#util_util_format_format_args) in Node.js<br><br>`false` in web browsers|A function that replaces placeholders like in error messages with values.<br><br>If set to `false`, then error messages will be treated as literals and no placeholder replacement will occur.
|
||||||
|
|
||||||
|
|
||||||
|
### `concatMessages` Option
|
||||||
|
When wrapping an error, Ono's default behavior is to append the error's message to your message, with a newline between them. For example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const ono = require("@jsdevtools/ono");
|
||||||
|
|
||||||
|
function createArray(length) {
|
||||||
|
try {
|
||||||
|
return new Array(length);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// Wrap and re-throw the error
|
||||||
|
throw ono(error, "Sorry, I was unable to create the array.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to create an array with a negative length
|
||||||
|
createArray(-5);
|
||||||
|
```
|
||||||
|
|
||||||
|
The above code produces the following error message:
|
||||||
|
|
||||||
|
```
|
||||||
|
Sorry, I was unable to create the array.
|
||||||
|
Invalid array length;
|
||||||
|
```
|
||||||
|
|
||||||
|
If you'd rather not include the original message, then you can set the `concatMessages` option to `false`. For example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { ono, Ono } = require("@jsdevtools/ono");
|
||||||
|
|
||||||
|
// Override the default behavior for the RangeError
|
||||||
|
ono.range = new Ono(RangeError, { concatMessages: false });
|
||||||
|
|
||||||
|
function createArray(length) {
|
||||||
|
try {
|
||||||
|
return new Array(length);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// Wrap and re-throw the error
|
||||||
|
throw ono(error, "Sorry, I was unable to create the array.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to create an array with a negative length
|
||||||
|
createArray(-5);
|
||||||
|
```
|
||||||
|
|
||||||
|
Now the error only includes your message, not the original error message.
|
||||||
|
|
||||||
|
```
|
||||||
|
Sorry, I was unable to create the array.
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### `format` option
|
||||||
|
The `format` option let you set a format function, which replaces placeholders in error messages with values.
|
||||||
|
|
||||||
|
When running in Node.js, Ono uses [the `util.format()` function](https://nodejs.org/api/util.html#util_util_format_format_args) by default, which lets you use placeholders such as %s, %d, and %j. You can provide the values for these placeholders when calling any Ono method:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
throw ono("%s is invalid. Must be at least %d characters.", username, minLength);
|
||||||
|
```
|
||||||
|
|
||||||
|
Of course, the above example could be accomplished using [ES6 template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) instead of format strings:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
throw ono(`${username} is invalid. Must be at least ${minLength} characters.`);
|
||||||
|
```
|
||||||
|
|
||||||
|
Format strings are most useful when you don't alrady know the values at the time that you're writing the string. A common scenario is localization. Here's a simplistic example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const errorMessages {
|
||||||
|
invalidLength: {
|
||||||
|
en: "%s is invalid. Must be at least %d characters.",
|
||||||
|
es: "%s no es válido. Debe tener al menos %d caracteres.",
|
||||||
|
zh: "%s 无效。 必须至少%d个字符。",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let lang = getCurrentUsersLanguage();
|
||||||
|
|
||||||
|
throw ono(errorMessages.invalidLength[lang], username, minLength);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### The `format` option in web browsers
|
||||||
|
Web browsers don't have a built-in equivalent of Node's [`util.format()` function](https://nodejs.org/api/util.html#util_util_format_format_args), so format strings are only supported in Node.js by default. However, you can set the `format` option to any compatible polyfill library to enable this functionality in web browsers too.
|
||||||
|
|
||||||
|
Here are some compatible polyfill libraries:
|
||||||
|
|
||||||
|
- [format](https://www.npmjs.com/package/format)
|
||||||
|
- [format-util](https://github.com/tmpfs/format-util)
|
||||||
|
|
||||||
|
|
||||||
|
#### Custom `format` implementation
|
||||||
|
If the standard [`util.format()`](https://nodejs.org/api/util.html#util_util_format_format_args) functionality isn't sufficient for your needs, then you can set the `format` option to your own custom implementation. Here's a simplistic example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { ono, Ono } = require("@jsdevtools/ono");
|
||||||
|
|
||||||
|
// This is a simple formatter that replaces $0, $1, $2, ... with the corresponding argument
|
||||||
|
let options = {
|
||||||
|
format(message, ...args) {
|
||||||
|
for (let [index, arg] of args.entries()) {
|
||||||
|
message = message.replace("$" + index, arg);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use your custom formatter for all of the built-in error types
|
||||||
|
ono.error = new Ono(Error, options);
|
||||||
|
ono.eval = new Ono(EvalError, options);
|
||||||
|
ono.range = new Ono(RangeError, options);
|
||||||
|
ono.reference = new Ono(ReferenceError, options);
|
||||||
|
ono.syntax = new Ono(SyntaxError, options);
|
||||||
|
ono.type = new Ono(TypeError, options);
|
||||||
|
ono.uri = new Ono(URIError, options);
|
||||||
|
|
||||||
|
// Now all Ono functions support your custom formatter
|
||||||
|
throw ono("$0 is invalid. Must be at least $1 characters.", username, minLength);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Custom Error Classes
|
||||||
|
-----------------------------
|
||||||
|
There are two ways to use Ono with your own custom error classes. Which one you choose depends on what parameters your custom error class accepts, and whether you'd prefer to use `ono.myError()` syntax or `new MyError()` syntax.
|
||||||
|
|
||||||
|
### Option 1: Standard Errors
|
||||||
|
Ono has built-in support for all of [the built-in JavaScript Error types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types). For example, you can use `ono.reference()` to create a `ReferenceError`, or `ono.syntax()` to create a `SyntaxError`.
|
||||||
|
|
||||||
|
All of these built-in JavaScript Error types accept a single parameter: the error message string. If your own error classes also work this way, then you can create Ono methods for your custom error classes. Here's an example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { ono, Ono } = require("@jsdevtools/ono");
|
||||||
|
let counter = 0;
|
||||||
|
|
||||||
|
// A custom Error class that assigns a unique ID and timestamp to each error
|
||||||
|
class MyErrorClass extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.id = ++counter;
|
||||||
|
this.timestamp = new Date();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new Ono method for your custom Error class
|
||||||
|
ono.myError = new Ono(MyErrorClass);
|
||||||
|
|
||||||
|
// You can use this method just like any other Ono method
|
||||||
|
throw ono.myError({ code: 404, status: "NOT_FOUND" }, `Resource not found: ${url}`);
|
||||||
|
```
|
||||||
|
|
||||||
|
The code above throws an instance of `MyErrorClass` that looks like this:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
"name": "MyErrorClass",
|
||||||
|
"message": "Resource not found: xyz.html",
|
||||||
|
"id": 1,
|
||||||
|
"timestamp": "2019-01-01T12:30:00.456Z",
|
||||||
|
"code": 404,
|
||||||
|
"status": "NOT_FOUND",
|
||||||
|
"stack": "MyErrorClass: Resource not found: xyz.html\n at someFunction (index.js:24:5)",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Option 2: Enhanced Error Classes
|
||||||
|
If your custom error classes require more than just an error message string parameter, then you'll need to use Ono differently. Rather than creating a [custom Ono method](#option-1-standard-errors) and using `ono.myError()` syntax, you'll use Ono _inside_ your error class's constructor. This has a few benefits:
|
||||||
|
|
||||||
|
- Your error class can accept whatever parameters you want
|
||||||
|
- Ono is encapsulated within your error class
|
||||||
|
- You can use `new MyError()` syntax rather than `ono.myError()` syntax
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { ono, Ono } = require("@jsdevtools/ono");
|
||||||
|
|
||||||
|
// A custom Error class for 404 Not Found
|
||||||
|
class NotFoundError extends Error {
|
||||||
|
constructor(method, url) {
|
||||||
|
super(`404: ${method} ${url} was not found`);
|
||||||
|
|
||||||
|
// Add custom properties, enhance JSON.stringify() support, etc.
|
||||||
|
Ono.extend(this, { statusCode: 404, method, url });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A custom Error class for 500 Server Error
|
||||||
|
class ServerError extends Error {
|
||||||
|
constructor(originalError, method, url) {
|
||||||
|
super(`500: A server error occurred while responding to ${method} ${url}`);
|
||||||
|
|
||||||
|
// Append the stack trace and custom properties of the original error,
|
||||||
|
// and add new custom properties, enhance JSON.stringify() support, etc.
|
||||||
|
Ono.extend(this, originalError, { statusCode: 500, method, url });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
--------------------------
|
||||||
|
Contributions, enhancements, and bug-fixes are welcome! [Open an issue](https://github.com/JS-DevTools/ono/issues) on GitHub and [submit a pull request](https://github.com/JS-DevTools/ono/pulls).
|
||||||
|
|
||||||
|
#### Building/Testing
|
||||||
|
To build/test the project locally on your computer:
|
||||||
|
|
||||||
|
1. __Clone this repo__<br>
|
||||||
|
`git clone https://github.com/JS-DevTools/ono.git`
|
||||||
|
|
||||||
|
2. __Install dependencies__<br>
|
||||||
|
`npm install`
|
||||||
|
|
||||||
|
3. __Run the build script__<br>
|
||||||
|
`npm run build`
|
||||||
|
|
||||||
|
4. __Run the tests__<br>
|
||||||
|
`npm test`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
License
|
||||||
|
--------------------------
|
||||||
|
Ono 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/JS-DevTools/ono) 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
|
||||||
|
--------------------------
|
||||||
|
Thanks to these awesome companies for their support of Open Source developers ❤
|
||||||
|
|
||||||
|
[](https://travis-ci.com)
|
||||||
|
[](https://saucelabs.com)
|
||||||
|
[](https://coveralls.io)
|
||||||
3
node_modules/@jsdevtools/ono/cjs/constructor.d.ts
generated
vendored
Normal file
3
node_modules/@jsdevtools/ono/cjs/constructor.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { OnoConstructor } from "./types";
|
||||||
|
declare const constructor: OnoConstructor;
|
||||||
|
export { constructor as Ono };
|
||||||
47
node_modules/@jsdevtools/ono/cjs/constructor.js
generated
vendored
Normal file
47
node_modules/@jsdevtools/ono/cjs/constructor.js
generated
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.Ono = void 0;
|
||||||
|
const extend_error_1 = require("./extend-error");
|
||||||
|
const normalize_1 = require("./normalize");
|
||||||
|
const to_json_1 = require("./to-json");
|
||||||
|
const constructor = Ono;
|
||||||
|
exports.Ono = constructor;
|
||||||
|
/**
|
||||||
|
* Creates an `Ono` instance for a specifc error type.
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
function Ono(ErrorConstructor, options) {
|
||||||
|
options = normalize_1.normalizeOptions(options);
|
||||||
|
function ono(...args) {
|
||||||
|
let { originalError, props, message } = normalize_1.normalizeArgs(args, options);
|
||||||
|
// Create a new error of the specified type
|
||||||
|
let newError = new ErrorConstructor(message);
|
||||||
|
// Extend the error with the properties of the original error and the `props` object
|
||||||
|
return extend_error_1.extendError(newError, originalError, props);
|
||||||
|
}
|
||||||
|
ono[Symbol.species] = ErrorConstructor;
|
||||||
|
return ono;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns an object containing all properties of the given Error object,
|
||||||
|
* which can be used with `JSON.stringify()`.
|
||||||
|
*/
|
||||||
|
Ono.toJSON = function toJSON(error) {
|
||||||
|
return to_json_1.toJSON.call(error);
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces,
|
||||||
|
* additional properties, and improved support for `JSON.stringify()`.
|
||||||
|
*/
|
||||||
|
Ono.extend = function extend(error, originalError, props) {
|
||||||
|
if (props || originalError instanceof Error) {
|
||||||
|
return extend_error_1.extendError(error, originalError, props);
|
||||||
|
}
|
||||||
|
else if (originalError) {
|
||||||
|
return extend_error_1.extendError(error, undefined, originalError);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return extend_error_1.extendError(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=constructor.js.map
|
||||||
1
node_modules/@jsdevtools/ono/cjs/constructor.js.map
generated
vendored
Normal file
1
node_modules/@jsdevtools/ono/cjs/constructor.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"constructor.js","sourceRoot":"","sources":["../src/constructor.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAC7C,2CAA8D;AAC9D,uCAAkD;AAGlD,MAAM,WAAW,GAAG,GAAqB,CAAC;AAClB,0BAAG;AAE3B;;GAEG;AACH,gEAAgE;AAChE,SAAS,GAAG,CAAsB,gBAAyC,EAAE,OAAoB;IAC/F,OAAO,GAAG,4BAAgB,CAAC,OAAO,CAAC,CAAC;IAEpC,SAAS,GAAG,CAAwC,GAAG,IAAe;QACpE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,yBAAa,CAAO,IAAI,EAAE,OAAQ,CAAC,CAAC;QAE5E,2CAA2C;QAC3C,IAAI,QAAQ,GAAG,IAAK,gBAAiD,CAAC,OAAO,CAAC,CAAC;QAE/E,oFAAoF;QACpF,OAAO,0BAAW,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC;IACvC,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,GAAG,CAAC,MAAM,GAAG,SAAS,MAAM,CAAC,KAAgB;IAC3C,OAAO,gBAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF;;;GAGG;AACH,GAAG,CAAC,MAAM,GAAG,SAAS,MAAM,CAAC,KAAgB,EAAE,aAAyB,EAAE,KAAc;IACtF,IAAI,KAAK,IAAI,aAAa,YAAY,KAAK,EAAE;QAC3C,OAAO,0BAAW,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;KACjD;SACI,IAAI,aAAa,EAAE;QACtB,OAAO,0BAAW,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;KACrD;SACI;QACH,OAAO,0BAAW,CAAC,KAAK,CAAC,CAAC;KAC3B;AACH,CAAC,CAAC"}
|
||||||
9
node_modules/@jsdevtools/ono/cjs/extend-error.d.ts
generated
vendored
Normal file
9
node_modules/@jsdevtools/ono/cjs/extend-error.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { ErrorLike, OnoError } from "./types";
|
||||||
|
/**
|
||||||
|
* Extends the new error with the properties of the original error and the `props` object.
|
||||||
|
*
|
||||||
|
* @param newError - The error object to extend
|
||||||
|
* @param originalError - The original error object, if any
|
||||||
|
* @param props - Additional properties to add, if any
|
||||||
|
*/
|
||||||
|
export declare function extendError<T extends ErrorLike, E extends ErrorLike, P extends object>(error: T, originalError?: E, props?: P): T & E & P & OnoError<T & E & P>;
|
||||||
77
node_modules/@jsdevtools/ono/cjs/extend-error.js
generated
vendored
Normal file
77
node_modules/@jsdevtools/ono/cjs/extend-error.js
generated
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.extendError = void 0;
|
||||||
|
const isomorphic_node_1 = require("./isomorphic.node");
|
||||||
|
const stack_1 = require("./stack");
|
||||||
|
const to_json_1 = require("./to-json");
|
||||||
|
const protectedProps = ["name", "message", "stack"];
|
||||||
|
/**
|
||||||
|
* Extends the new error with the properties of the original error and the `props` object.
|
||||||
|
*
|
||||||
|
* @param newError - The error object to extend
|
||||||
|
* @param originalError - The original error object, if any
|
||||||
|
* @param props - Additional properties to add, if any
|
||||||
|
*/
|
||||||
|
function extendError(error, originalError, props) {
|
||||||
|
let onoError = error;
|
||||||
|
extendStack(onoError, originalError);
|
||||||
|
// Copy properties from the original error
|
||||||
|
if (originalError && typeof originalError === "object") {
|
||||||
|
mergeErrors(onoError, originalError);
|
||||||
|
}
|
||||||
|
// The default `toJSON` method doesn't output props like `name`, `message`, `stack`, etc.
|
||||||
|
// So replace it with one that outputs every property of the error.
|
||||||
|
onoError.toJSON = to_json_1.toJSON;
|
||||||
|
// On Node.js, add support for the `util.inspect()` method
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
|
if (isomorphic_node_1.addInspectMethod) {
|
||||||
|
isomorphic_node_1.addInspectMethod(onoError);
|
||||||
|
}
|
||||||
|
// Finally, copy custom properties that were specified by the user.
|
||||||
|
// These props OVERWRITE any previous props
|
||||||
|
if (props && typeof props === "object") {
|
||||||
|
Object.assign(onoError, props);
|
||||||
|
}
|
||||||
|
return onoError;
|
||||||
|
}
|
||||||
|
exports.extendError = extendError;
|
||||||
|
/**
|
||||||
|
* Extend the error stack to include its cause
|
||||||
|
*/
|
||||||
|
function extendStack(newError, originalError) {
|
||||||
|
let stackProp = Object.getOwnPropertyDescriptor(newError, "stack");
|
||||||
|
if (stack_1.isLazyStack(stackProp)) {
|
||||||
|
stack_1.lazyJoinStacks(stackProp, newError, originalError);
|
||||||
|
}
|
||||||
|
else if (stack_1.isWritableStack(stackProp)) {
|
||||||
|
newError.stack = stack_1.joinStacks(newError, originalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Merges properties of the original error with the new error.
|
||||||
|
*
|
||||||
|
* @param newError - The error object to extend
|
||||||
|
* @param originalError - The original error object, if any
|
||||||
|
*/
|
||||||
|
function mergeErrors(newError, originalError) {
|
||||||
|
// Get the original error's keys
|
||||||
|
// NOTE: We specifically exclude properties that we have already set on the new error.
|
||||||
|
// This is _especially_ important for the `stack` property, because this property has
|
||||||
|
// a lazy getter in some environments
|
||||||
|
let keys = to_json_1.getDeepKeys(originalError, protectedProps);
|
||||||
|
// HACK: We have to cast the errors to `any` so we can use symbol indexers.
|
||||||
|
// see https://github.com/Microsoft/TypeScript/issues/1863
|
||||||
|
let _newError = newError;
|
||||||
|
let _originalError = originalError;
|
||||||
|
for (let key of keys) {
|
||||||
|
if (_newError[key] === undefined) {
|
||||||
|
try {
|
||||||
|
_newError[key] = _originalError[key];
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// This property is read-only, so it can't be copied
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=extend-error.js.map
|
||||||
1
node_modules/@jsdevtools/ono/cjs/extend-error.js.map
generated
vendored
Normal file
1
node_modules/@jsdevtools/ono/cjs/extend-error.js.map
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"extend-error.js","sourceRoot":"","sources":["../src/extend-error.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AACrD,mCAAmF;AACnF,uCAAgD;AAGhD,MAAM,cAAc,GAA2B,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAE5E;;;;;;GAMG;AACH,SAAgB,WAAW,CAA6D,KAAQ,EAAE,aAAiB,EAAE,KAAS;IAC5H,IAAI,QAAQ,GAAG,KAAmD,CAAC;IAEnE,WAAW,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAErC,0CAA0C;IAC1C,IAAI,aAAa,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;QACtD,WAAW,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;KACtC;IAED,yFAAyF;IACzF,mEAAmE;IACnE,QAAQ,CAAC,MAAM,GAAG,gBAAM,CAAC;IAEzB,0DAA0D;IAC1D,uEAAuE;IACvE,IAAI,kCAAgB,EAAE;QACpB,kCAAgB,CAAC,QAAQ,CAAC,CAAC;KAC5B;IAED,mEAAmE;IACnE,2CAA2C;IAC3C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACtC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;KAChC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AA3BD,kCA2BC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,QAAmB,EAAE,aAAyB;IACjE,IAAI,SAAS,GAAG,MAAM,CAAC,wBAAwB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEnE,IAAI,mBAAW,CAAC,SAAS,CAAC,EAAE;QAC1B,sBAAc,CAAC,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;KACpD;SACI,IAAI,uBAAe,CAAC,SAAS,CAAC,EAAE;QACnC,QAAQ,CAAC,KAAK,GAAG,kBAAU,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;KACtD;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,QAAmB,EAAE,aAAwB;IAChE,gCAAgC;IAChC,sFAAsF;IACtF,qFAAqF;IACrF,qCAAqC;IACrC,IAAI,IAAI,GAAG,qBAAW,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAEtD,2EAA2E;IAC3E,0DAA0D;IAC1D,IAAI,SAAS,GAAG,QAAe,CAAC;IAChC,IAAI,cAAc,GAAG,aAAoB,CAAC;IAE1C,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE;QACpB,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;YAChC,IAAI;gBACF,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;aACtC;YACD,OAAO,CAAC,EAAE;gBACR,oDAAoD;aACrD;SACF;KACF;AACH,CAAC"}
|
||||||
5
node_modules/@jsdevtools/ono/cjs/index.d.ts
generated
vendored
Normal file
5
node_modules/@jsdevtools/ono/cjs/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { ono } from "./singleton";
|
||||||
|
export { Ono } from "./constructor";
|
||||||
|
export * from "./types";
|
||||||
|
export { ono };
|
||||||
|
export default ono;
|
||||||
25
node_modules/@jsdevtools/ono/cjs/index.js
generated
vendored
Normal file
25
node_modules/@jsdevtools/ono/cjs/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||||
|
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.ono = void 0;
|
||||||
|
/* eslint-env commonjs */
|
||||||
|
const singleton_1 = require("./singleton");
|
||||||
|
Object.defineProperty(exports, "ono", { enumerable: true, get: function () { return singleton_1.ono; } });
|
||||||
|
var constructor_1 = require("./constructor");
|
||||||
|
Object.defineProperty(exports, "Ono", { enumerable: true, get: function () { return constructor_1.Ono; } });
|
||||||
|
__exportStar(require("./types"), exports);
|
||||||
|
exports.default = singleton_1.ono;
|
||||||
|
// CommonJS default export hack
|
||||||
|
if (typeof module === "object" && typeof module.exports === "object") {
|
||||||
|
module.exports = Object.assign(module.exports.default, module.exports);
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=index.js.map
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue