swagger-parser
Advanced tools
Comparing version 1.0.0 to 1.0.1
27
index.js
@@ -279,5 +279,7 @@ (function() { | ||
else { | ||
resolvePointer(pointerPath, pointerValue, function(err, reference, alreadyResolved) { | ||
resolvePointer(pointerPath, pointerValue, function(err, resolved, alreadyResolved) { | ||
if (err || alreadyResolved) { | ||
obj[key] = reference; | ||
// The pointer had already been resolved, so REPLACE the original object with the resolved object. | ||
// This ensures that all references are replaced with the SAME object instance | ||
obj[key] = resolved; | ||
dereferenceNextItem(err); | ||
@@ -287,4 +289,8 @@ } | ||
// Recursively dereference the resolved reference | ||
dereference(reference, pointerPath, function(err, reference) { | ||
obj[key] = reference; | ||
dereference(resolved, pointerPath, function(err, resolved) { | ||
// This is the first time this object has been resolved, so MERGE the resolved value with | ||
// the original object (instead of replacing the original object). This ensures that any | ||
// other references that have already resolved to this object will be pointing at the | ||
// correct object instance. | ||
mergeResolvedReference(obj[key], resolved); | ||
dereferenceNextItem(err); | ||
@@ -319,2 +325,15 @@ }); | ||
/** | ||
* Merges the resolved reference object with the original placeholder object that contains the `$ref` pointer. | ||
* By merging the object rather than overwriting it, other pointers to the object will now correctly point to the dereferenced value. | ||
* @param {object} source the original placeholder object that contains the `$ref` pointer | ||
* @param {object} resolved the resolved value of the `$ref` pointer | ||
*/ | ||
function mergeResolvedReference(source, resolved) { | ||
// Delete the $ref property FIRST, since the resolved value may also be a reference object | ||
delete source.$ref; | ||
_.merge(source, resolved); | ||
} | ||
/** | ||
* Resolves a "$ref" pointer. | ||
@@ -321,0 +340,0 @@ * @param {string} pointerPath |
{ | ||
"name": "swagger-parser", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Parses a Swagger spec (in JSON or YAML format), validates it against the Swagger schema, and dereferences all $ref pointers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -18,3 +18,5 @@ Swagger-Parser | ||
parser.parse("path/to/my/swagger.yaml", function(err, swaggerObject) { | ||
// This callback will be invoked once the Swagger spec is parsed, validated, and dereferenced. | ||
// This callback will be invoked once the Swagger spec is | ||
// parsed, validated, and dereferenced. | ||
if (err) { | ||
@@ -25,7 +27,9 @@ console.error("Swagger Spec could not be parsed because: " + err.message); | ||
// If there's no error, then `swaggerObject` is a reference to the parsed SwaggerObject | ||
// If there's no error, then `swaggerObject` is the parsed SwaggerObject | ||
// (see https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#swagger-object-) | ||
console.log( | ||
"Your API title is " + swaggerObject.info.title + ", version " + swaggerObject.info.version | ||
"Your API title is " + swaggerObject.info.title + | ||
", version " + swaggerObject.info.version | ||
); | ||
}); | ||
@@ -32,0 +36,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22614
460
86