@scalar/oas-utils
Advanced tools
Comparing version 0.1.11 to 0.1.12
# @scalar/oas-utils | ||
## 0.1.12 | ||
### Patch Changes | ||
- 61b8ddc: fix: doesn’t render preview for mimetype variations like application/foobar+json | ||
- 165b901: feat: dynamic values for generated examples | ||
## 0.1.11 | ||
@@ -4,0 +11,0 @@ |
@@ -20,3 +20,7 @@ /** | ||
mode?: 'read' | 'write'; | ||
/** | ||
* Dynamic values to add to the example. | ||
*/ | ||
variables?: Record<string, any>; | ||
}, level?: number) => any; | ||
//# sourceMappingURL=getExampleFromSchema.d.ts.map |
export { createHash } from './createHash'; | ||
export { defaultStateFactory, ssrState } from './ssrState'; | ||
export { fetchSpecFromUrl } from './fetch-spec'; | ||
@@ -8,10 +9,10 @@ export { getExampleFromSchema } from './getExampleFromSchema'; | ||
export { getRequestFromOperation } from './getRequestFromOperation'; | ||
export type { HttpStatusCode, HttpStatusCodes } from './httpStatusCodes'; | ||
export { httpStatusCodes } from './httpStatusCodes'; | ||
export { json2xml } from './json2xml'; | ||
export { normalizeMimeTypeObject } from './normalizeMimeTypeObject'; | ||
export { json2xml } from './json2xml'; | ||
export { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml, } from './parse'; | ||
export { prettyPrintJson } from './prettyPrintJson'; | ||
export { defaultStateFactory, ssrState } from './ssrState'; | ||
export * from './normalizeMimeType'; | ||
export * from './types'; | ||
export type { HttpStatusCode, HttpStatusCodes } from './httpStatusCodes'; | ||
export { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml, } from './parse'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -18,2 +18,5 @@ import { parse, stringify } from 'yaml'; | ||
const defaultStateFactory = () => ({}); | ||
const ssrState = typeof window !== "undefined" ? window.__SCALAR__ ?? defaultStateFactory() : defaultStateFactory(); | ||
const yaml = { | ||
@@ -118,2 +121,11 @@ /** Parse and throw if the return value is not an object */ | ||
} | ||
if (schema["x-variable"]) { | ||
const value = options?.variables?.[schema["x-variable"]]; | ||
if (value !== void 0) { | ||
if (schema.type === "number" || schema.type === "integer") { | ||
return parseInt(value, 10); | ||
} | ||
return value; | ||
} | ||
} | ||
if (Array.isArray(schema.examples) && schema.examples.length > 0) { | ||
@@ -369,2 +381,6 @@ return schema.examples[0]; | ||
function normalizeMimeType(contentType) { | ||
return contentType.replace(/;.*$/, "").replace(/\/.+\+/, "/").trim(); | ||
} | ||
function normalizeMimeTypeObject(content) { | ||
@@ -378,3 +394,3 @@ if (!content) { | ||
Object.keys(newContent).forEach((key) => { | ||
const newKey = key.replace(/;.*$/, "").replace(/\/.+\+/, "/").trim(); | ||
const newKey = normalizeMimeType(key); | ||
newContent[newKey] = newContent[key]; | ||
@@ -830,5 +846,2 @@ if (key !== newKey) { | ||
const defaultStateFactory = () => ({}); | ||
const ssrState = typeof window !== "undefined" ? window.__SCALAR__ ?? defaultStateFactory() : defaultStateFactory(); | ||
export { createHash, defaultStateFactory, fetchSpecFromUrl, formatJsonOrYamlString, getExampleFromSchema, getHarRequest, getParametersFromOperation, getRequestBodyFromOperation, getRequestFromOperation, httpStatusCodes, isJsonString, json, json2xml, normalizeMimeTypeObject, parseJsonOrYaml, prettyPrintJson, ssrState, transformToJson, yaml }; | ||
export { createHash, defaultStateFactory, fetchSpecFromUrl, formatJsonOrYamlString, getExampleFromSchema, getHarRequest, getParametersFromOperation, getRequestBodyFromOperation, getRequestFromOperation, httpStatusCodes, isJsonString, json, json2xml, normalizeMimeType, normalizeMimeTypeObject, parseJsonOrYaml, prettyPrintJson, ssrState, transformToJson, yaml }; |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"engines": { | ||
@@ -22,0 +22,0 @@ "node": ">=18" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50171
36
1170