httpsnippet-client-api 6.0.0 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -116,6 +116,7 @@ var client = {
116
116
  }
117
117
  var operationSlugs = foundOperation.url.slugs;
118
118
  var operation = oas.operation(foundOperation.url.nonNormalizedPath, method);
119
+ var operationPathParameters = operation.getParameters().filter(function (param) { return param["in"] === 'path'; });
119
120
  var path = operation.path;
120
121
  var authData = [];
121
122
  var authSources = getAuthSources(operation);
@@ -162,7 +163,19 @@ var client = {
162
163
  var param = _a[0], value = _a[1];
163
164
  // The keys in `operationSlugs` will always be prefixed with a `:` in the `oas` library so
164
165
  // we can safely do this substring here without asserting this context.
165
- metadata[param.substring(1)] = value;
166
+ var cleanedParam = param.substring(1);
167
+ // If our incoming path slug out of `oas.findOperation()` has been sanitized and is missing
168
+ // a hyphen, but there is a parameter in the OpenAPI definition that matches what our
169
+ // hyphen-less slug is then we should use that for the snippet.
170
+ var unsanitizedParam = operationPathParameters.find(function (p) {
171
+ return p.name.includes('-') && p.name.replace(/-/g, '') === cleanedParam ? p.name : false;
172
+ });
173
+ if (unsanitizedParam) {
174
+ metadata[unsanitizedParam.name] = value;
175
+ }
176
+ else {
177
+ metadata[cleanedParam] = value;
178
+ }
166
179
  });
167
180
  if (Object.keys(headersObj).length) {
168
181
  var headers_1 = headersObj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "httpsnippet-client-api",
3
- "version": "6.0.0",
3
+ "version": "6.0.1",
4
4
  "description": "An HTTPSnippet client for generating snippets for the `api` module.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -53,5 +53,5 @@
53
53
  "test/"
54
54
  ]
55
55
  },
56
- "gitHead": "9759db4c067baf3928ad3a9d76b4965658955d78"
56
+ "gitHead": "5fe262d794d82935f08863341b0d95b9eb8ac39b"
57
57
  }
package/src/index.ts CHANGED
@@ -113,6 +113,7 @@ const client: Client<APIOptions> = {
113
113
 
114
114
  const operationSlugs = foundOperation.url.slugs;
115
115
  const operation = oas.operation(foundOperation.url.nonNormalizedPath, method);
116
+ const operationPathParameters = operation.getParameters().filter(param => param.in === 'path');
116
117
  const path = operation.path;
117
118
  const authData: string[] = [];
118
119
  const authSources = getAuthSources(operation);
@@ -169,7 +170,20 @@ const client: Client<APIOptions> = {
169
170
  Array.from(Object.entries(operationSlugs)).forEach(([param, value]) => {
170
171
  // The keys in `operationSlugs` will always be prefixed with a `:` in the `oas` library so
171
172
  // we can safely do this substring here without asserting this context.
172
- metadata[param.substring(1)] = value;
173
+ const cleanedParam = param.substring(1);
174
+
175
+ // If our incoming path slug out of `oas.findOperation()` has been sanitized and is missing
176
+ // a hyphen, but there is a parameter in the OpenAPI definition that matches what our
177
+ // hyphen-less slug is then we should use that for the snippet.
178
+ const unsanitizedParam = operationPathParameters.find(p => {
179
+ return p.name.includes('-') && p.name.replace(/-/g, '') === cleanedParam ? p.name : false;
180
+ });
181
+
182
+ if (unsanitizedParam) {
183
+ metadata[unsanitizedParam.name] = value;
184
+ } else {
185
+ metadata[cleanedParam] = value;
186
+ }
173
187
  });
174
188
 
175
189
  if (Object.keys(headersObj).length) {