@readme/oas-to-har 19.1.0 → 20.0.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 20.0.0 (2022-10-28)
2
+
3
+ * chore: bumping oas to v20 (#132) ([1477086](https://github.com/readmeio/oas-to-har/commit/1477086)), closes [#132](https://github.com/readmeio/oas-to-har/issues/132)
4
+ * ci: running tests on node 19 ([cdb8df9](https://github.com/readmeio/oas-to-har/commit/cdb8df9))
5
+
6
+
7
+
8
+ ## 19.2.0 (2022-10-25)
9
+
10
+ * feat: ability to manuall specify an `authorization` header in formData (#131) ([9623d38](https://github.com/readmeio/oas-to-har/commit/9623d38)), closes [#131](https://github.com/readmeio/oas-to-har/issues/131)
11
+
12
+
13
+
1
14
  ## 19.1.0 (2022-10-17)
2
15
 
3
16
  * fix: preferring JSON response content accept headers over everything else (#130) ([41fdd11](https://github.com/readmeio/oas-to-har/commit/41fdd11)), closes [#130](https://github.com/readmeio/oas-to-har/issues/130)
package/dist/index.js CHANGED
@@ -339,8 +339,8 @@ function oasToHar(oas, operationSchema, values, auth, opts) {
339
339
  });
340
340
  });
341
341
  }
342
- // Do we have an `accept` header set up in the form, but it hasn't been added yet?
343
342
  if (formData.header) {
343
+ // Do we have an `accept` header set up in the form data, but it hasn't been added yet?
344
344
  var acceptHeader = Object.keys(formData.header).find(function (h) { return h.toLowerCase() === 'accept'; });
345
345
  if (acceptHeader && !har.headers.find(function (hdr) { return hdr.name.toLowerCase() === 'accept'; })) {
346
346
  har.headers.push({
@@ -348,6 +348,14 @@ function oasToHar(oas, operationSchema, values, auth, opts) {
348
348
  value: String(formData.header[acceptHeader])
349
349
  });
350
350
  }
351
+ // Do we have a manually-defined `authorization` header set up in the form data?
352
+ var authorizationHeader = Object.keys(formData.header).find(function (h) { return h.toLowerCase() === 'authorization'; });
353
+ if (authorizationHeader && !har.headers.find(function (hdr) { return hdr.name.toLowerCase() === 'authorization'; })) {
354
+ har.headers.push({
355
+ name: 'authorization',
356
+ value: String(formData.header[authorizationHeader])
357
+ });
358
+ }
351
359
  }
352
360
  var requestBody;
353
361
  if (operation.hasRequestBody()) {
@@ -519,7 +527,14 @@ function oasToHar(oas, operationSchema, values, auth, opts) {
519
527
  if (!securityValue) {
520
528
  return;
521
529
  }
522
- // If we've already added this security value then don't add it again.
530
+ // If this is an `authorization` header and we've already added one (maybe one was manually
531
+ // specified), then we shouldn't add another.
532
+ if (securityValue.value.name === 'authorization') {
533
+ if (har[securityValue.type].find(function (v) { return v.name === securityValue.value.name; })) {
534
+ return;
535
+ }
536
+ }
537
+ // If we've already added this **specific** security value then don't add it again.
523
538
  if (har[securityValue.type].find(function (v) { return v.name === securityValue.value.name && v.value === securityValue.value.value; })) {
524
539
  return;
525
540
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@readme/oas-to-har",
3
3
  "description": "Utility to transform an OAS operation into a HAR representation",
4
- "version": "19.1.0",
4
+ "version": "20.0.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "Jon Ursenbach <jon@ursenba.ch>",
@@ -29,8 +29,8 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@readme/data-urls": "^1.0.1",
32
- "@readme/oas-extensions": "^16.0.0",
33
- "oas": "^19.0.0",
32
+ "@readme/oas-extensions": "^17.0.0",
33
+ "oas": "^20.0.0",
34
34
  "qs": "^6.10.5",
35
35
  "remove-undefined-objects": "^2.0.0"
36
36
  },
@@ -40,16 +40,16 @@
40
40
  "@jsdevtools/host-environment": "^2.1.2",
41
41
  "@jsdevtools/karma-config": "^3.1.7",
42
42
  "@readme/eslint-config": "^10.1.1",
43
- "@readme/oas-examples": "^5.6.0",
43
+ "@readme/oas-examples": "^5.7.1",
44
44
  "@types/chai": "^4.3.1",
45
45
  "@types/har-format": "^1.2.8",
46
46
  "@types/mocha": "^10.0.0",
47
47
  "@types/qs": "^6.9.7",
48
48
  "chai": "^4.3.6",
49
- "eslint": "^8.25.0",
49
+ "eslint": "^8.26.0",
50
50
  "har-validator": "^5.1.5",
51
51
  "husky": "^8.0.1",
52
- "mocha": "^10.0.0",
52
+ "mocha": "^10.1.0",
53
53
  "nyc": "^15.1.0",
54
54
  "prettier": "^2.7.0",
55
55
  "ts-loader": "^8.4.0",
package/src/index.ts CHANGED
@@ -392,8 +392,8 @@ export default function oasToHar(
392
392
  });
393
393
  }
394
394
 
395
- // Do we have an `accept` header set up in the form, but it hasn't been added yet?
396
395
  if (formData.header) {
396
+ // Do we have an `accept` header set up in the form data, but it hasn't been added yet?
397
397
  const acceptHeader = Object.keys(formData.header).find(h => h.toLowerCase() === 'accept');
398
398
  if (acceptHeader && !har.headers.find(hdr => hdr.name.toLowerCase() === 'accept')) {
399
399
  har.headers.push({
@@ -401,6 +401,15 @@ export default function oasToHar(
401
401
  value: String(formData.header[acceptHeader]),
402
402
  });
403
403
  }
404
+
405
+ // Do we have a manually-defined `authorization` header set up in the form data?
406
+ const authorizationHeader = Object.keys(formData.header).find(h => h.toLowerCase() === 'authorization');
407
+ if (authorizationHeader && !har.headers.find(hdr => hdr.name.toLowerCase() === 'authorization')) {
408
+ har.headers.push({
409
+ name: 'authorization',
410
+ value: String(formData.header[authorizationHeader]),
411
+ });
412
+ }
404
413
  }
405
414
 
406
415
  let requestBody: MediaTypeObject;
@@ -594,7 +603,15 @@ export default function oasToHar(
594
603
  return;
595
604
  }
596
605
 
597
- // If we've already added this security value then don't add it again.
606
+ // If this is an `authorization` header and we've already added one (maybe one was manually
607
+ // specified), then we shouldn't add another.
608
+ if (securityValue.value.name === 'authorization') {
609
+ if (har[securityValue.type].find(v => v.name === securityValue.value.name)) {
610
+ return;
611
+ }
612
+ }
613
+
614
+ // If we've already added this **specific** security value then don't add it again.
598
615
  if (
599
616
  har[securityValue.type].find(
600
617
  v => v.name === securityValue.value.name && v.value === securityValue.value.value