@scalar/openapi-parser
Advanced tools
Comparing version 0.8.10 to 0.9.0
# @scalar/openapi-parser | ||
## 0.9.0 | ||
### Minor Changes | ||
- 6fef2f3: feat(openapi-parser): support `onDereference` option on `dereference` | ||
## 0.8.10 | ||
@@ -4,0 +10,0 @@ |
@@ -1,3 +0,4 @@ | ||
import type { AnyApiDefinitionFormat, DereferenceResult, Filesystem, ThrowOnErrorOption } from '../types'; | ||
export type DereferenceOptions = ThrowOnErrorOption; | ||
import type { AnyApiDefinitionFormat, DereferenceResult, Filesystem } from '../types'; | ||
import { type ResolveReferencesOptions } from './resolveReferences.js'; | ||
export type DereferenceOptions = ResolveReferencesOptions; | ||
/** | ||
@@ -4,0 +5,0 @@ * Resolves all references in an OpenAPI document |
@@ -8,6 +8,12 @@ import type { OpenAPI } from '@scalar/openapi-types'; | ||
}; | ||
export type ResolveReferencesOptions = ThrowOnErrorOption & { | ||
onDereference?: (data: { | ||
schema: AnyObject; | ||
ref: string; | ||
}) => void; | ||
}; | ||
/** | ||
* Takes a specification and resolves all references. | ||
*/ | ||
export declare function resolveReferences(input: AnyObject | Filesystem, options?: ThrowOnErrorOption, file?: FilesystemEntry, errors?: ErrorObject[]): ResolveReferencesResult; | ||
export declare function resolveReferences(input: AnyObject | Filesystem, options?: ResolveReferencesOptions, file?: FilesystemEntry, errors?: ErrorObject[]): ResolveReferencesResult; | ||
//# sourceMappingURL=resolveReferences.d.ts.map |
@@ -29,6 +29,6 @@ import { ERRORS } from '../configuration/index.js'; | ||
// Recursively resolve all references | ||
resolve(file?.specification ?? entrypoint.specification, filesystem, file ?? entrypoint); | ||
resolve(file?.specification ?? entrypoint.specification, filesystem, file ?? entrypoint, options?.onDereference); | ||
// If we replace references with content, that includes a reference, we can’t deal with that right-away. | ||
// That’s why we need a second run. | ||
resolve(file?.specification ?? entrypoint.specification, filesystem, file ?? entrypoint); | ||
resolve(file?.specification ?? entrypoint.specification, filesystem, file ?? entrypoint, options?.onDereference); | ||
// Remove duplicats (according to message) from errors | ||
@@ -47,3 +47,3 @@ errors = errors.filter((error, index, self) => index === | ||
*/ | ||
function resolve(schema, resolveFilesystem, resolveFile) { | ||
function resolve(schema, resolveFilesystem, resolveFile, onResolve) { | ||
let result; | ||
@@ -59,2 +59,3 @@ // Iterate over the whole objecct | ||
} | ||
onResolve?.({ schema, ref: schema.$ref }); | ||
// Get rid of the reference | ||
@@ -71,3 +72,3 @@ delete schema.$ref; | ||
if (typeof value === 'object' && !isCircular(value)) { | ||
result = resolve(value, resolveFilesystem, resolveFile); | ||
result = resolve(value, resolveFilesystem, resolveFile, onResolve); | ||
} | ||
@@ -74,0 +75,0 @@ }); |
@@ -20,3 +20,3 @@ { | ||
], | ||
"version": "0.8.10", | ||
"version": "0.9.0", | ||
"engines": { | ||
@@ -23,0 +23,0 @@ "node": ">=18" |
@@ -66,2 +66,16 @@ # Scalar OpenAPI Parser | ||
### Track references | ||
The `dereference` function accepts an `onDereference` callback option that gets called whenever a reference is resolved. This can be useful for tracking which schemas are being dereferenced: | ||
```ts | ||
import { dereference } from '@scalar/openapi-parser' | ||
const { schema, errors } = await dereference(specification, { | ||
onDereference: ({ schema, ref }) => { | ||
// | ||
}, | ||
}) | ||
``` | ||
### Modify an OpenAPI document | ||
@@ -68,0 +82,0 @@ |
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
1959876
28241
283