httpsnippet-client-api 6.1.0 → 6.1.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
@@ -10,6 +10,29 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
13
36
  var __rest = (this && this.__rest) || function (s, e) {
14
37
  var t = {};
15
38
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -27,8 +50,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
50
  exports.__esModule = true;
28
51
  var code_builder_1 = require("@readme/httpsnippet/dist/helpers/code-builder");
29
52
  var content_type_1 = __importDefault(require("content-type"));
30
- var oas_1 = __importDefault(require("oas"));
53
+ var oas_1 = __importStar(require("oas"));
31
54
  var stringify_object_1 = __importDefault(require("stringify-object"));
55
+ var matchesMimeType = oas_1.utils.matchesMimeType;
32
56
  function stringify(obj, opts) {
33
57
  if (opts === void 0) { opts = {}; }
34
58
  return (0, stringify_object_1["default"])(obj, __assign({ indent: ' ' }, opts));
@@ -214,10 +238,9 @@ var client = {
214
238
  }
215
239
  }
216
240
  else if (headerLower === 'accept') {
217
- // If the `Accept` header here is not the default or first `Accept` header for the
218
- // operations' request body then we should add it otherwise we can let the SDK handle it
219
- // itself.
220
- if (headers_1[header] === operation.getContentType()) {
241
+ // If the `Accept` header here is JSON-like header then we can remove it from the code
242
+ // snippet because `api` natively supports and prioritizes JSON over any other mime type.
243
+ if (matchesMimeType.json(headers_1[header])) {
221
244
  delete headers_1[header];
222
245
  return;
223
246
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "httpsnippet-client-api",
3
- "version": "6.1.0",
3
+ "version": "6.1.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",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
+ "lint:types": "tsc --noEmit",
9
10
  "prebuild": "rm -rf dist/",
10
11
  "prepack": "npm run build",
11
- "test": "jest --coverage"
12
+ "test": "vitest --coverage"
12
13
  },
13
14
  "repository": {
14
15
  "type": "git",
@@ -35,15 +36,14 @@
35
36
  "@readme/oas-examples": "^5.9.0",
36
37
  "@readme/openapi-parser": "^2.4.0",
37
38
  "@types/content-type": "^1.1.5",
38
- "@types/jest": "^29.5.2",
39
39
  "@types/stringify-object": "^4.0.2",
40
- "api": "^6.1.0",
40
+ "@vitest/coverage-v8": "^0.34.1",
41
+ "api": "^6.1.1",
41
42
  "fetch-mock": "^9.11.0",
42
43
  "isomorphic-fetch": "^3.0.0",
43
- "jest": "^29.6.1",
44
- "ts-jest": "^29.1.1",
45
- "typescript": "^4.9.5"
44
+ "typescript": "^4.9.5",
45
+ "vitest": "^0.34.1"
46
46
  },
47
47
  "prettier": "@readme/eslint-config/prettier",
48
- "gitHead": "244093f2ad00e5ea527420f49bdb541bc2095806"
48
+ "gitHead": "e440a28841e753895bfb5315b4d31f679824fa39"
49
49
  }
package/src/index.ts CHANGED
@@ -5,9 +5,11 @@ import type { HttpMethods, OASDocument } from 'oas/dist/rmoas.types';
5
5
 
6
6
  import { CodeBuilder } from '@readme/httpsnippet/dist/helpers/code-builder';
7
7
  import contentType from 'content-type';
8
- import Oas from 'oas';
8
+ import Oas, { utils } from 'oas';
9
9
  import stringifyObject from 'stringify-object';
10
10
 
11
+ const { matchesMimeType } = utils;
12
+
11
13
  // This should really be an exported type in `oas`.
12
14
  type SecurityType = 'Basic' | 'Bearer' | 'Query' | 'Header' | 'Cookie' | 'OAuth2' | 'http' | 'apiKey';
13
15
 
@@ -107,7 +109,7 @@ const client: Client<APIOptions> = {
107
109
  const foundOperation = oas.findOperation(url, method);
108
110
  if (!foundOperation) {
109
111
  throw new Error(
110
- `Unable to locate a matching operation in the supplied \`apiDefinition\` for: ${source.method} ${url}`
112
+ `Unable to locate a matching operation in the supplied \`apiDefinition\` for: ${source.method} ${url}`,
111
113
  );
112
114
  }
113
115
 
@@ -224,10 +226,9 @@ const client: Client<APIOptions> = {
224
226
  return;
225
227
  }
226
228
  } else if (headerLower === 'accept') {
227
- // If the `Accept` header here is not the default or first `Accept` header for the
228
- // operations' request body then we should add it otherwise we can let the SDK handle it
229
- // itself.
230
- if (headers[header] === operation.getContentType()) {
229
+ // If the `Accept` header here is JSON-like header then we can remove it from the code
230
+ // snippet because `api` natively supports and prioritizes JSON over any other mime type.
231
+ if (matchesMimeType.json(headers[header] as string)) {
231
232
  delete headers[header];
232
233
  return;
233
234
  }