diff --git a/packages/fury-adapter-swagger/CHANGELOG.md b/packages/fury-adapter-swagger/CHANGELOG.md index 3bcf2443e..33504e2bd 100644 --- a/packages/fury-adapter-swagger/CHANGELOG.md +++ b/packages/fury-adapter-swagger/CHANGELOG.md @@ -1,5 +1,12 @@ # Fury Swagger Parser Changelog +## Master + +### Bug Fixes + +- Prevents a 'Path Item Object' from being included in a Resource Group created + by an 'Operation Object' in a previously defined 'Path Item Object'. + ## 0.27.1 (2019-06-03) ### Bug Fixes diff --git a/packages/fury-adapter-swagger/lib/parser.js b/packages/fury-adapter-swagger/lib/parser.js index f35f35df7..35f69ca56 100644 --- a/packages/fury-adapter-swagger/lib/parser.js +++ b/packages/fury-adapter-swagger/lib/parser.js @@ -689,12 +689,6 @@ class Parser { }); } - if (this.useResourceGroups()) { - this.updateResourceGroup(pathValue['x-group-name']); - } - - this.group.content.push(resource); - const pathObjectParameters = pathValue.parameters || []; const resourceHrefVariables = this.createHrefVariables(pathObjectParameters); @@ -724,6 +718,17 @@ class Parser { this.handleSwaggerVendorExtensions(resource, pathValue); + const operationsHaveTags = Object.values(relevantMethods).some(method => method.tags !== undefined && method.tags.length > 0); + if (operationsHaveTags) { + if (this.useResourceGroups()) { + this.updateResourceGroup(pathValue['x-group-name']); + } + + this.group.content.push(resource); + } else { + this.api.push(resource); + } + return resource; }); } diff --git a/packages/fury-adapter-swagger/test/fixtures/tags.json b/packages/fury-adapter-swagger/test/fixtures/tags.json new file mode 100644 index 000000000..38c6809ca --- /dev/null +++ b/packages/fury-adapter-swagger/test/fixtures/tags.json @@ -0,0 +1,296 @@ +{ + "element": "parseResult", + "content": [ + { + "element": "category", + "meta": { + "classes": { + "element": "array", + "content": [ + { + "element": "string", + "content": "api" + } + ] + }, + "title": { + "element": "string", + "content": "Tags on some of the operations" + } + }, + "attributes": { + "version": { + "element": "string", + "content": "v1" + } + }, + "content": [ + { + "element": "category", + "meta": { + "title": { + "element": "string", + "content": "MyRG1" + }, + "classes": { + "element": "array", + "content": [ + { + "element": "string", + "content": "resourceGroup" + } + ] + } + }, + "content": [ + { + "element": "resource", + "attributes": { + "href": { + "element": "string", + "content": "/one" + } + }, + "content": [ + { + "element": "transition", + "meta": { + "title": { + "element": "string", + "content": "first resource" + } + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": { + "element": "string", + "content": "GET" + } + } + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": { + "element": "string", + "content": "200" + } + } + } + ] + } + ] + } + ] + }, + { + "element": "resource", + "attributes": { + "href": { + "element": "string", + "content": "/three" + } + }, + "content": [ + { + "element": "transition", + "meta": { + "title": { + "element": "string", + "content": "third resource" + } + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": { + "element": "string", + "content": "GET" + } + } + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": { + "element": "string", + "content": "200" + } + } + } + ] + } + ] + } + ] + } + ] + }, + { + "element": "resource", + "attributes": { + "href": { + "element": "string", + "content": "/two" + } + }, + "content": [ + { + "element": "transition", + "meta": { + "title": { + "element": "string", + "content": "second resource" + } + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": { + "element": "string", + "content": "GET" + } + } + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": { + "element": "string", + "content": "200" + } + } + } + ] + } + ] + } + ] + }, + { + "element": "category", + "meta": { + "title": { + "element": "string", + "content": "MyRG2" + }, + "classes": { + "element": "array", + "content": [ + { + "element": "string", + "content": "resourceGroup" + } + ] + } + }, + "content": [ + { + "element": "resource", + "attributes": { + "href": { + "element": "string", + "content": "/four" + } + }, + "content": [ + { + "element": "transition", + "meta": { + "title": { + "element": "string", + "content": "fourth resource" + } + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": { + "element": "string", + "content": "GET" + } + } + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": { + "element": "string", + "content": "200" + } + } + } + ] + } + ] + } + ] + } + ] + }, + { + "element": "resource", + "attributes": { + "href": { + "element": "string", + "content": "/five" + } + }, + "content": [ + { + "element": "transition", + "meta": { + "title": { + "element": "string", + "content": "fith resource" + } + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": { + "element": "string", + "content": "GET" + } + } + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": { + "element": "string", + "content": "200" + } + } + } + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/packages/fury-adapter-swagger/test/fixtures/tags.yaml b/packages/fury-adapter-swagger/test/fixtures/tags.yaml new file mode 100644 index 000000000..aab806e94 --- /dev/null +++ b/packages/fury-adapter-swagger/test/fixtures/tags.yaml @@ -0,0 +1,42 @@ +swagger: '2.0' +info: + version: v1 + title: Tags on some of the operations +paths: + /one: + get: + summary: first resource + tags: + - MyRG1 + responses: + 200: + description: "" + /two: + get: + summary: second resource + responses: + 200: + description: "" + /three: + get: + summary: third resource + tags: + - MyRG1 + responses: + 200: + description: "" + /four: + get: + summary: fourth resource + tags: + - MyRG2 + responses: + 200: + description: "" + /five: + get: + summary: fith resource + tags: [] + responses: + 200: + description: ""