diff --git a/src/parser.js b/src/parser.js index 013608c..ec6a734 100644 --- a/src/parser.js +++ b/src/parser.js @@ -174,6 +174,7 @@ export default class Parser { this.handleSwaggerInfo(); this.handleSwaggerHost(); this.handleSwaggerAuth(); + this.handleSwaggerVendorExtensions(this.api, this.swagger, 'root'); this.handleExternalDocs(this.api, swagger.externalDocs); @@ -181,7 +182,7 @@ export default class Parser { this.validateConsumes(this.swagger.consumes); const complete = () => { - this.handleSwaggerVendorExtensions(this.api, swagger.paths); + this.handleSwaggerVendorExtensions(this.api, swagger.paths, 'paths'); return done(null, this.result); }; @@ -341,7 +342,7 @@ export default class Parser { }); } - this.handleSwaggerVendorExtensions(this.api, this.swagger.info); + this.handleSwaggerVendorExtensions(this.api, this.swagger.info, 'info'); }); } } @@ -687,7 +688,7 @@ export default class Parser { } // Converts all unknown Swagger vendor extensions from an object into a API Element extension - handleSwaggerVendorExtensions(element, object) { + handleSwaggerVendorExtensions(element, object, fragment) { const extensions = _.chain(object) .pickBy(isExtension) .omit('x-description', 'x-summary', 'x-group-name') @@ -698,7 +699,12 @@ export default class Parser { const profileLink = new Link(); profileLink.relation = 'profile'; - profileLink.href = 'https://help.apiary.io/profiles/api-elements/vendor-extensions/'; + + if (fragment) { + profileLink.href = `https://help.apiary.io/profiles/api-elements/vendor-extensions/#${fragment}`; + } else { + profileLink.href = 'https://help.apiary.io/profiles/api-elements/vendor-extensions/'; + } const extension = new Extension(extensions); extension.links = [profileLink]; diff --git a/test/fixtures/root-extensions.json b/test/fixtures/root-extensions.json new file mode 100644 index 0000000..c3bde75 --- /dev/null +++ b/test/fixtures/root-extensions.json @@ -0,0 +1,103 @@ +{ + "element": "parseResult", + "content": [ + { + "element": "category", + "meta": { + "classes": { + "element": "array", + "content": [ + { + "element": "string", + "content": "api" + } + ] + }, + "title": { + "element": "string", + "content": "Root Extensions" + } + }, + "content": [ + { + "element": "extension", + "meta": { + "links": { + "element": "array", + "content": [ + { + "element": "link", + "attributes": { + "relation": { + "element": "string", + "content": "profile" + }, + "href": { + "element": "string", + "content": "https://help.apiary.io/profiles/api-elements/vendor-extensions/#info" + } + } + } + ] + } + }, + "content": { + "x-info-extension": "Info Extension" + } + }, + { + "element": "extension", + "meta": { + "links": { + "element": "array", + "content": [ + { + "element": "link", + "attributes": { + "relation": { + "element": "string", + "content": "profile" + }, + "href": { + "element": "string", + "content": "https://help.apiary.io/profiles/api-elements/vendor-extensions/#root" + } + } + } + ] + } + }, + "content": { + "x-root-extension": "Root Extension" + } + }, + { + "element": "extension", + "meta": { + "links": { + "element": "array", + "content": [ + { + "element": "link", + "attributes": { + "relation": { + "element": "string", + "content": "profile" + }, + "href": { + "element": "string", + "content": "https://help.apiary.io/profiles/api-elements/vendor-extensions/#paths" + } + } + } + ] + } + }, + "content": { + "x-paths-extension": "Paths Extension" + } + } + ] + } + ] +} diff --git a/test/fixtures/root-extensions.yaml b/test/fixtures/root-extensions.yaml new file mode 100644 index 0000000..5791da2 --- /dev/null +++ b/test/fixtures/root-extensions.yaml @@ -0,0 +1,8 @@ +swagger: '2.0' +info: + version: 1.0.0 + title: Root Extensions + x-info-extension: Info Extension +x-root-extension: Root Extension +paths: + x-paths-extension: Paths Extension