working version
This commit is contained in:
Родитель
408cc03005
Коммит
d4e811c37c
|
@ -16,9 +16,9 @@ var util = require('util'),
|
|||
* Resolves the swagger spec by unifying x-ms-paths, resolving relative file references if any,
|
||||
* resolving the allof is present in any model definition and then setting additionalProperties
|
||||
* to false if it is not previously set to true or an object in that definition.
|
||||
*/
|
||||
*/
|
||||
class SpecResolver {
|
||||
|
||||
|
||||
/*
|
||||
* @constructor
|
||||
* Initializes a new instance of the SpecResolver class.
|
||||
|
@ -96,7 +96,7 @@ class SpecResolver {
|
|||
* If provided the value should be 'all'. This indicates that 'local' references should also be resolved apart from the default ones.
|
||||
*
|
||||
* @return {object} doc fully resolved json document
|
||||
*/
|
||||
*/
|
||||
resolveRelativePaths(doc, docPath, filterType) {
|
||||
let self = this;
|
||||
let docDir;
|
||||
|
@ -168,7 +168,7 @@ class SpecResolver {
|
|||
let reference = node['$ref'];
|
||||
let parsedReference = utils.parseReferenceInSwagger(reference);
|
||||
let docDir = path.dirname(docPath);
|
||||
|
||||
|
||||
if (parsedReference.filePath) {
|
||||
//assuming that everything in the spec is relative to it, let us join the spec directory
|
||||
//and the file path in reference.
|
||||
|
@ -194,7 +194,34 @@ class SpecResolver {
|
|||
referencedObj = utils.getObject(result, slicedLocalReferenceValue);
|
||||
utils.setObject(self.specInJson, slicedLocalReferenceValue, referencedObj);
|
||||
self.visitedEntities[slicedLocalReferenceValue] = referencedObj;
|
||||
return Promise.resolve(self.resolveRelativePaths(referencedObj, docPath, 'all'));
|
||||
return self.resolveRelativePaths(referencedObj, docPath, 'all').then(() => {
|
||||
if (result && result.definitions) {
|
||||
let unresolvedDefinitions = [];
|
||||
for (let defName in result.definitions) {
|
||||
if (result.definitions[defName].allOf) {
|
||||
let matchFound = result.definitions[defName].allOf.some((item) => {
|
||||
return (item['$ref'] === `#${slicedLocalReferenceValue}` && !self.visitedEntities[`/definitions/${defName}`]);
|
||||
});
|
||||
if (matchFound) {
|
||||
unresolvedDefinitions.push(defName);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unresolvedDefinitions.length) {
|
||||
unresolvedDefinitions.forEach((definitionName) => {
|
||||
let slicedDefinitionRef = `/definitions/${definitionName}`;
|
||||
let definitionObj = result.definitions[definitionName];
|
||||
utils.setObject(self.specInJson, slicedDefinitionRef, definitionObj);
|
||||
self.visitedEntities[slicedDefinitionRef] = definitionObj;
|
||||
return self.resolveRelativePaths(definitionObj, docPath, 'all');
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve(doc);
|
||||
}
|
||||
|
@ -295,7 +322,7 @@ class SpecResolver {
|
|||
|
||||
/*
|
||||
* Deletes all the references to allOf from all the model definitions in the swagger spec.
|
||||
*/
|
||||
*/
|
||||
deleteReferencesToAllOf() {
|
||||
let self = this;
|
||||
let spec = self.specInJson;
|
||||
|
|
Загрузка…
Ссылка в новой задаче