diff --git a/packages/httpsnippet-client-api/__tests__/__fixtures__/output/issue-76.js b/packages/httpsnippet-client-api/__tests__/__fixtures__/output/issue-76.js new file mode 100644 index 00000000..2ffe01f5 --- /dev/null +++ b/packages/httpsnippet-client-api/__tests__/__fixtures__/output/issue-76.js @@ -0,0 +1,7 @@ +const sdk = require('api')('https://example.com/openapi.json'); + +sdk.auth('a5a220e').get('/pet/findByStatus', {status: 'available', accept: 'application/xml'}) + .then(res => res.json()) + .then(res => { + console.log(res); + }); diff --git a/packages/httpsnippet-client-api/__tests__/__fixtures__/request/issue-76/definition.json b/packages/httpsnippet-client-api/__tests__/__fixtures__/request/issue-76/definition.json new file mode 100644 index 00000000..3e2f17fa --- /dev/null +++ b/packages/httpsnippet-client-api/__tests__/__fixtures__/request/issue-76/definition.json @@ -0,0 +1,57 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "issue-76" + }, + "servers": [ + { + "url": "http://petstore.swagger.io/v2" + } + ], + "paths": { + "/pet/findByStatus": { + "get": { + "parameters": [ + { + "name": "status", + "in": "query", + "required": true, + "explode": true, + "schema": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "available", + "pending", + "sold" + ], + "default": "available" + } + } + } + ], + "responses": { + "200": { + "description": "OK" + } + }, + "security": [ + { + "api_key": [] + } + ] + } + } + }, + "components": { + "securitySchemes": { + "api_key": { + "type": "apiKey", + "name": "api_key", + "in": "query" + } + } + } +} diff --git a/packages/httpsnippet-client-api/__tests__/__fixtures__/request/issue-76/har.json b/packages/httpsnippet-client-api/__tests__/__fixtures__/request/issue-76/har.json new file mode 100644 index 00000000..9a22ecf2 --- /dev/null +++ b/packages/httpsnippet-client-api/__tests__/__fixtures__/request/issue-76/har.json @@ -0,0 +1,31 @@ +{ + "log": { + "entries": [ + { + "request": { + "allHeaders": { + "accept": "application/xml", + "authorization": "Bearer 123" + }, + "cookies": [], + "headers": [ + {"name": "Accept", "value": "application/xml"} + ], + "httpVersion": "HTTP/1.1", + "method": "GET", + "postData": { + "jsonObj": false, + "mimeType": "application/octet-stream", + "paramsObj": false, + "size": 0 + }, + "queryString": [ + {"name": "status", "value": "available"}, + {"name": "api_key", "value": "a5a220e"} + ], + "url": "http://petstore.swagger.io/v2/pet/findByStatus" + } + } + ] + } +} diff --git a/packages/httpsnippet-client-api/__tests__/index.test.js b/packages/httpsnippet-client-api/__tests__/index.test.js index 5aab54f1..52132366 100644 --- a/packages/httpsnippet-client-api/__tests__/index.test.js +++ b/packages/httpsnippet-client-api/__tests__/index.test.js @@ -57,6 +57,7 @@ describe('snippets', () => { ['full'], ['headers'], ['https'], + ['issue-76'], ['jsonObj-multiline'], ['jsonObj-null-value'], diff --git a/packages/httpsnippet-client-api/src/index.js b/packages/httpsnippet-client-api/src/index.js index 306a883c..6749c20c 100644 --- a/packages/httpsnippet-client-api/src/index.js +++ b/packages/httpsnippet-client-api/src/index.js @@ -175,7 +175,7 @@ module.exports = function (source, options) { if ('operationId' in operation && operation.operationId.length > 0) { accessor = operation.operationId; } else { - args.push(`'${source.uriObj.pathname}'`); + args.push(`'${operation.path}'`); } if (typeof body !== 'undefined') {