From 6ccd9344888a432f959124a54c8afbc33d6148e1 Mon Sep 17 00:00:00 2001 From: Timothy Younger Date: Thu, 10 May 2018 15:37:09 -0700 Subject: [PATCH 1/2] fix(root-extensions): similar to #174, this will parse root extensions per the swagger specification. root extensions are parsed into the same location as the info extensions. --- src/parser.js | 1 + test/fixtures/root-extensions.json | 77 ++++++++++++++++++++++++++++++ test/fixtures/root-extensions.yaml | 6 +++ 3 files changed, 84 insertions(+) create mode 100644 test/fixtures/root-extensions.json create mode 100644 test/fixtures/root-extensions.yaml diff --git a/src/parser.js b/src/parser.js index 013608c..eb31b4f 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); this.handleExternalDocs(this.api, swagger.externalDocs); diff --git a/test/fixtures/root-extensions.json b/test/fixtures/root-extensions.json new file mode 100644 index 0000000..2dd5d60 --- /dev/null +++ b/test/fixtures/root-extensions.json @@ -0,0 +1,77 @@ +{ + "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/" + } + } + } + ] + } + }, + "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/" + } + } + } + ] + } + }, + "content": { + "x-root-extension": "Root Extension" + } + } + ] + } + ] +} diff --git a/test/fixtures/root-extensions.yaml b/test/fixtures/root-extensions.yaml new file mode 100644 index 0000000..8f22192 --- /dev/null +++ b/test/fixtures/root-extensions.yaml @@ -0,0 +1,6 @@ +swagger: '2.0' +info: + version: 1.0.0 + title: Root Extensions + x-info-extension: Info Extension +x-root-extension: Root Extension From ed4c39d8323b592af60c3e7f8bce8130fa8dbd01 Mon Sep 17 00:00:00 2001 From: Timothy Younger Date: Tue, 29 May 2018 10:05:29 -0700 Subject: [PATCH 2/2] fix(root-extensions): per review, added extension source info to the profile link URL fragment and added paths extension assertion as well --- src/parser.js | 15 ++++++++++----- test/fixtures/root-extensions.json | 30 ++++++++++++++++++++++++++++-- test/fixtures/root-extensions.yaml | 2 ++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/parser.js b/src/parser.js index eb31b4f..ec6a734 100644 --- a/src/parser.js +++ b/src/parser.js @@ -174,7 +174,7 @@ export default class Parser { this.handleSwaggerInfo(); this.handleSwaggerHost(); this.handleSwaggerAuth(); - this.handleSwaggerVendorExtensions(this.api, this.swagger); + this.handleSwaggerVendorExtensions(this.api, this.swagger, 'root'); this.handleExternalDocs(this.api, swagger.externalDocs); @@ -182,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); }; @@ -342,7 +342,7 @@ export default class Parser { }); } - this.handleSwaggerVendorExtensions(this.api, this.swagger.info); + this.handleSwaggerVendorExtensions(this.api, this.swagger.info, 'info'); }); } } @@ -688,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') @@ -699,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 index 2dd5d60..c3bde75 100644 --- a/test/fixtures/root-extensions.json +++ b/test/fixtures/root-extensions.json @@ -34,7 +34,7 @@ }, "href": { "element": "string", - "content": "https://help.apiary.io/profiles/api-elements/vendor-extensions/" + "content": "https://help.apiary.io/profiles/api-elements/vendor-extensions/#info" } } } @@ -60,7 +60,7 @@ }, "href": { "element": "string", - "content": "https://help.apiary.io/profiles/api-elements/vendor-extensions/" + "content": "https://help.apiary.io/profiles/api-elements/vendor-extensions/#root" } } } @@ -70,6 +70,32 @@ "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 index 8f22192..5791da2 100644 --- a/test/fixtures/root-extensions.yaml +++ b/test/fixtures/root-extensions.yaml @@ -4,3 +4,5 @@ info: title: Root Extensions x-info-extension: Info Extension x-root-extension: Root Extension +paths: + x-paths-extension: Paths Extension