@scalar/oas-utils
Advanced tools
Comparing version 0.2.2 to 0.2.3
# @scalar/oas-utils | ||
## 0.2.3 | ||
### Patch Changes | ||
- 362d47a: chore: less @ts-ignore comments | ||
## 0.2.2 | ||
@@ -4,0 +10,0 @@ |
@@ -6,3 +6,8 @@ import type { AxiosResponse } from 'axios'; | ||
/** A single set of populated values for a sent request */ | ||
export type ResponseInstance = AxiosResponse; | ||
export type ResponseInstance = AxiosResponse & { | ||
/** | ||
* Time in ms the request took | ||
**/ | ||
duration: number; | ||
}; | ||
/** A single request/response set to save to the history stack */ | ||
@@ -9,0 +14,0 @@ export type RequestEvent = { |
@@ -11,4 +11,4 @@ export { createHash } from './createHash.js'; | ||
export { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse.js'; | ||
export { prettyPrintJson } from './prettyPrintJson.js'; | ||
export { prettyPrintJson, replaceCircularDependencies } from './prettyPrintJson.js'; | ||
export { schemaModel } from './schema-model.js'; | ||
export { defaultStateFactory, ssrState } from './ssrState.js'; |
/** | ||
* Takes JSON and formats it. | ||
**/ | ||
export declare const prettyPrintJson: (value: any) => any; | ||
export declare const prettyPrintJson: (value: string | number | any[] | Record<any, any>) => string; | ||
/** | ||
* JSON.stringify, but with circular dependencies replaced with '[Circular]' | ||
*/ | ||
export declare function replaceCircularDependencies(content: any): string; | ||
//# sourceMappingURL=prettyPrintJson.d.ts.map |
@@ -0,1 +1,3 @@ | ||
import { isJsonString } from './parse.js'; | ||
/** | ||
@@ -5,16 +7,37 @@ * Takes JSON and formats it. | ||
const prettyPrintJson = (value) => { | ||
try { | ||
if (typeof value === 'string') { | ||
if (typeof value === 'string') { | ||
// JSON string | ||
if (isJsonString(value)) { | ||
return JSON.stringify(JSON.parse(value), null, 2); | ||
} | ||
else { | ||
// Regular string | ||
return value; | ||
} | ||
// Object | ||
if (typeof value === 'object') { | ||
try { | ||
return JSON.stringify(value, null, 2); | ||
} | ||
catch { | ||
return replaceCircularDependencies(value); | ||
} | ||
} | ||
catch { | ||
console.log('[prettyPrintJson] Error parsing JSON', value); | ||
return value.toString(); | ||
}; | ||
/** | ||
* JSON.stringify, but with circular dependencies replaced with '[Circular]' | ||
*/ | ||
function replaceCircularDependencies(content) { | ||
const cache = new Set(); | ||
return JSON.stringify(content, (key, value) => { | ||
if (typeof value === 'object' && value !== null) { | ||
if (cache.has(value)) { | ||
return '[Circular]'; | ||
} | ||
cache.add(value); | ||
} | ||
return value; | ||
} | ||
}; | ||
}, 2); | ||
} | ||
export { prettyPrintJson }; | ||
export { prettyPrintJson, replaceCircularDependencies }; |
@@ -8,3 +8,3 @@ import type { ContentType, TransformedOperation } from '../types'; | ||
mimeType: string; | ||
text: any; | ||
text: string; | ||
params?: undefined; | ||
@@ -11,0 +11,0 @@ }; |
@@ -121,3 +121,3 @@ import type { ExternalDocumentation } from './entities/workspace/collection/index.js'; | ||
preferredSecurityScheme: string | null; | ||
securitySchemes?: OpenAPIV3.ComponentsObject['securitySchemes'] | OpenAPIV3_1.ComponentsObject['securitySchemes']; | ||
securitySchemes?: OpenAPIV2.SecurityDefinitionsObject | OpenAPIV3.ComponentsObject['securitySchemes'] | OpenAPIV3_1.ComponentsObject['securitySchemes']; | ||
http: { | ||
@@ -124,0 +124,0 @@ basic: { |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"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
169804
3693