@scalar/oas-utils 0.1.13 → 0.1.14

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,5 +1,12 @@
1
1
  # @scalar/oas-utils
2
2
 
3
+ ## 0.1.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 7205137: fix: response body does not show a preview when the content-type is undefined
8
+ - d369ac4: feat: union types in getExampleFromSchema
9
+
3
10
  ## 0.1.13
4
11
 
5
12
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"fetchSpecFromUrl.d.ts","sourceRoot":"","sources":["../src/fetchSpecFromUrl.ts"],"names":[],"mappings":"AAOA,iEAAiE;AACjE,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAmBjB"}
1
+ {"version":3,"file":"fetchSpecFromUrl.d.ts","sourceRoot":"","sources":["../src/fetchSpecFromUrl.ts"],"names":[],"mappings":"AAYA,iEAAiE;AACjE,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAyBjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"getExampleFromSchema.d.ts","sourceRoot":"","sources":["../src/getExampleFromSchema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,OAAO,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;QAGI;IACJ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC,UACM,MAAM,KACZ,GA8OF,CAAA"}
1
+ {"version":3,"file":"getExampleFromSchema.d.ts","sourceRoot":"","sources":["../src/getExampleFromSchema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,OAAO,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;QAGI;IACJ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC,UACM,MAAM,KACZ,GA2PF,CAAA"}
package/dist/index.js CHANGED
@@ -86,10 +86,15 @@ const parseJsonOrYaml = (value) => {
86
86
  });
87
87
  };
88
88
 
89
+ const OLD_PROXY_URL = "https://api.scalar.com/request-proxy";
90
+ const NEW_PROXY_URL = "https://proxy.scalar.com";
89
91
  function redirectToProxy(proxy, url) {
90
92
  return `${proxy}?scalar_url=${encodeURI(url)}`;
91
93
  }
92
94
  async function fetchSpecFromUrl(url, proxy) {
95
+ if (proxy === OLD_PROXY_URL) {
96
+ proxy = NEW_PROXY_URL;
97
+ }
93
98
  const response = await fetch(proxy ? redirectToProxy(proxy, url) : url);
94
99
  if (response.status !== 200) {
95
100
  console.error(
@@ -260,6 +265,15 @@ const getExampleFromSchema = (schema, options, level = 0) => {
260
265
  });
261
266
  return example;
262
267
  }
268
+ if (Array.isArray(schema.type)) {
269
+ if (schema.type.includes("null")) {
270
+ return null;
271
+ }
272
+ const exampleValue = exampleValues[schema.type[0]];
273
+ if (exampleValue !== void 0) {
274
+ return exampleValue;
275
+ }
276
+ }
263
277
  console.warn(`[getExampleFromSchema] Unknown property type "${schema.type}".`);
264
278
  return null;
265
279
  };
@@ -374,6 +388,9 @@ function json2xml(data, tab) {
374
388
  }
375
389
 
376
390
  function normalizeMimeType(contentType) {
391
+ if (typeof contentType !== "string") {
392
+ return void 0;
393
+ }
377
394
  return contentType.replace(/;.*$/, "").replace(/\/.+\+/, "/").trim();
378
395
  }
379
396
 
@@ -386,6 +403,9 @@ function normalizeMimeTypeObject(content) {
386
403
  };
387
404
  Object.keys(newContent).forEach((key) => {
388
405
  const newKey = normalizeMimeType(key);
406
+ if (newKey === void 0) {
407
+ return;
408
+ }
389
409
  newContent[newKey] = newContent[key];
390
410
  if (key !== newKey) {
391
411
  delete newContent[key];
@@ -1,3 +1,9 @@
1
1
  import type { ContentType } from './types';
2
- export declare function normalizeMimeType(contentType: string): ContentType;
2
+ /**
3
+ * Normalizes a MIME type to a standard format.
4
+ *
5
+ * Input: application/problem+json; charset=utf-8
6
+ * Output: application/json
7
+ */
8
+ export declare function normalizeMimeType(contentType?: string): ContentType | undefined;
3
9
  //# sourceMappingURL=normalizeMimeType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeMimeType.d.ts","sourceRoot":"","sources":["../src/normalizeMimeType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,eAUpD"}
1
+ {"version":3,"file":"normalizeMimeType.d.ts","sourceRoot":"","sources":["../src/normalizeMimeType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,2BAcrD"}
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeMimeTypeObject.d.ts","sourceRoot":"","sources":["../src/normalizeMimeTypeObject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC;;;;;;;;cAuBzE"}
1
+ {"version":3,"file":"normalizeMimeTypeObject.d.ts","sourceRoot":"","sources":["../src/normalizeMimeTypeObject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC;;;;;;;;cA8BzE"}
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.1.13",
19
+ "version": "0.1.14",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },