Socket
Socket
Sign inDemoInstall

swagger-parser

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-parser - npm Package Compare versions

Comparing version 2.2.2 to 2.2.3

2

bower.json
{
"name": "swagger-parser",
"version": "2.2.2",
"version": "2.2.3",
"description": "Parses a JSON or YAML Swagger spec, validates it against the Swagger schema, and dereferences all $ref pointers",

@@ -5,0 +5,0 @@ "keywords": [

@@ -154,17 +154,14 @@ 'use strict';

function resolveSwaggerPath(pathOrUrl, state) {
// Coerce String objects to string primitives
pathOrUrl = pathOrUrl.toString();
// Resolve the file path or url, relative to the CWD
var cwd = util.cwd();
util.debug('Resolving Swagger path "%s", relative to "%s"', pathOrUrl, cwd);
pathOrUrl = url.resolve(cwd, pathOrUrl);
util.debug(' Resolved to %s', pathOrUrl);
var resolvedPath = util.resolvePath(cwd, pathOrUrl + '');
state.swaggerPath = resolvedPath;
// Update the state
state.swaggerPath = pathOrUrl;
state.baseDir = path.dirname(pathOrUrl) + '/';
// Get the directory of the Swagger file.
// Always append a path separator, since this is a directory path, not a file path;
// otherwise, {@link url#resolve} will treat it as a file path, which won't work.
state.baseDir = path.dirname(resolvedPath) + (util.isBrowser() ? '/' : path.sep);
util.debug('Swagger base directory: %s', state.baseDir);
return pathOrUrl;
return resolvedPath;
}

@@ -171,0 +168,0 @@

@@ -26,5 +26,5 @@ 'use strict';

var parsedUrl = url.parse(pathOrUrl);
if (isLocalFile(parsedUrl)) {
state.files.push(parsedUrl.href);
readFile(parsedUrl.href, state, callback);
if (isLocalFile(pathOrUrl)) {
state.files.push(pathOrUrl);
readFile(pathOrUrl, state, callback);
}

@@ -173,5 +173,3 @@ else {

// If all else fails, then determine based on the protocol
// NOTE: The following are all considered local files: "file://path/to/file", "/path/to/file", "c:\path\to\file"
return parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:';
return util.isLocalPath(parsedUrl);
}

@@ -178,0 +176,0 @@

@@ -5,4 +5,3 @@ 'use strict';

var url = require('url'),
read = require('./read'),
var read = require('./read'),
util = require('./util'),

@@ -245,3 +244,3 @@ _last = require('lodash/array/last'),

// Normalize the pointer value by resolving the path/URL relative to the Swagger file.
return url.resolve(state.baseDir, $ref);
return util.resolvePath(state.baseDir, $ref);
}

@@ -248,0 +247,0 @@ else {

'use strict';
var fs = require('fs'),
Path = require('path'),
url = require('url'),

@@ -175,2 +176,53 @@ format = require('util').format,

/**
* Determines whether the given path is a local path (as opposed to a remote path or URL).
* NOTE: This does NOT verify that the path exists or is valid.
*
* @param {string} path A path or URL (e.g. "/path/to/file", "c:\path\to\file", "http://company.com/path/to/file")
* @returns {boolean}
*/
isLocalPath: function(path) {
// NOTE: The following are all considered local files: "file://path/to/file", "/path/to/file", "c:\path\to\file"
var pathAsUrl = url.parse(path);
return pathAsUrl.protocol !== 'http:' && pathAsUrl.protocol !== 'https:';
},
/**
* Resolves the given paths to an absolute path.
* NOTE: This does NOT verify that the path exists or is valid.
*
* @param {string} basePath
* The base path, which must be absolute (e.g. "/base/path", "c:\base\path", "http://company.com/base/path")
*
* @param {string} path
* The path to be resolved, which may be relative or absolute. (e.g. "path/to/file", "path\to\file")
*
* @returns {string}
* The resolved, absolute path. (e.g. "/full/path/to/file", "c:\full\path\to\file", "http://company.com/full/path/to/file")
*/
resolvePath: function(basePath, path) {
util.debug('Resolving path "%s", relative to "%s"', path, basePath);
if (!util.isBrowser() && util.isLocalPath(basePath)) {
// Convert local paths to URLs first, so they play nice with url.resolve().
basePath = url.format({pathname: encodeURI(basePath)});
path = url.format({pathname: encodeURI(path)});
}
// url.resolve() works across all environments (Linux, Mac, Windows, browsers),
// even if basePath and path are different types (e.g. one is a URL, the other is a local path)
var resolvedUrl = url.resolve(basePath, path);
if (!util.isBrowser() && util.isLocalPath(resolvedUrl)) {
// Convert the URL string back to a local path
resolvedUrl = decodeURIComponent(resolvedUrl);
resolvedUrl = Path.normalize(resolvedUrl);
}
util.debug(' Resolved to %s', resolvedUrl);
return resolvedUrl;
},
/**
* Normalizes the current working directory across environments (Linux, Mac, Windows, browsers).

@@ -177,0 +229,0 @@ * The returned path will use forward slashes ("/"), even on Windows,

{
"name": "swagger-parser",
"version": "2.2.2",
"version": "2.2.3",
"description": "Swagger JSON/YAML parser and validator for Node and browsers",

@@ -38,2 +38,6 @@ "keywords": [

},
"engines": {
"node": ">=0.10.36",
"npm": ">=2.0"
},
"dependencies": {

@@ -48,3 +52,3 @@ "debug": "^2.1.2",

"browserify": "^9.0.3",
"chai": "^2.1.0",
"chai": "^2.1.1",
"coveralls": "^2.11.2",

@@ -55,3 +59,3 @@ "gulp": "^3.8.11",

"gulp-uglify": "^1.1.0",
"istanbul": "^0.3.6",
"istanbul": "^0.3.7",
"jquery": "^2.1.3",

@@ -70,5 +74,5 @@ "karma": "^0.12.31",

"mocha": "^2.1.0",
"nock": "^0.59",
"nock": "^1.1",
"npm-check-updates": "^1.5.1",
"sinon": "^1.12.2",
"sinon": "^1.13.0",
"version-bump-prompt": "^1.0.1",

@@ -75,0 +79,0 @@ "vinyl-buffer": "^1.0.0",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc