@scalar/openapi-parser
Advanced tools
Comparing version
# @scalar/openapi-parser | ||
## 0.13.0 | ||
### Minor Changes | ||
- 1e87feb: fix: normalize doesn’t handle empty documents well | ||
## 0.12.0 | ||
@@ -4,0 +10,0 @@ |
@@ -11,5 +11,5 @@ import Swagger20 from "../schemas/v2.0/schema.js"; | ||
const ERRORS = { | ||
EMPTY_OR_INVALID: "Can\u2019t find JSON, YAML or filename in data", | ||
EMPTY_OR_INVALID: "Can\u2019t find JSON, YAML or filename in data.", | ||
// URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string', | ||
OPENAPI_VERSION_NOT_SUPPORTED: "Can\u2019t find supported Swagger/OpenAPI version in specification, version must be a string.", | ||
OPENAPI_VERSION_NOT_SUPPORTED: "Can\u2019t find supported Swagger/OpenAPI version in the provided document, version must be a string.", | ||
INVALID_REFERENCE: "Can\u2019t resolve reference: %s", | ||
@@ -16,0 +16,0 @@ EXTERNAL_REFERENCE_NOT_FOUND: "Can\u2019t resolve external reference: %s", |
@@ -1,2 +0,1 @@ | ||
import type { UnknownObject } from '@scalar/types/utils'; | ||
import type { DetailsResult } from '../types/index.js'; | ||
@@ -6,3 +5,3 @@ /** | ||
*/ | ||
export declare function details(specification: UnknownObject): DetailsResult; | ||
export declare function details(specification: unknown): DetailsResult; | ||
//# sourceMappingURL=details.d.ts.map |
import { OpenApiVersions } from "../configuration/index.js"; | ||
import { isObject } from "./is-object.js"; | ||
function details(specification) { | ||
@@ -10,11 +11,13 @@ if (specification === null) { | ||
} | ||
for (const version of new Set(OpenApiVersions)) { | ||
const specificationType = version === "2.0" ? "swagger" : "openapi"; | ||
const value = specification[specificationType]; | ||
if (typeof value === "string" && value.startsWith(version)) { | ||
return { | ||
version, | ||
specificationType, | ||
specificationVersion: value | ||
}; | ||
if (isObject(specification)) { | ||
for (const version of new Set(OpenApiVersions)) { | ||
const specificationType = version === "2.0" ? "swagger" : "openapi"; | ||
const value = specification[specificationType]; | ||
if (typeof value === "string" && value.startsWith(version)) { | ||
return { | ||
version, | ||
specificationType, | ||
specificationVersion: value | ||
}; | ||
} | ||
} | ||
@@ -21,0 +24,0 @@ } |
@@ -8,3 +8,3 @@ import type { UnknownObject } from '@scalar/types/utils'; | ||
*/ | ||
export declare function normalize(specification: string | UnknownObject | Filesystem): UnknownObject | Filesystem; | ||
export declare function normalize(content: string | UnknownObject | Filesystem): UnknownObject | Filesystem; | ||
//# sourceMappingURL=normalize.d.ts.map |
import { parse } from "yaml"; | ||
import { isFilesystem } from "./is-filesystem.js"; | ||
function normalize(specification) { | ||
if (specification === null) { | ||
return {}; | ||
function normalize(content) { | ||
if (content === null) { | ||
return void 0; | ||
} | ||
if (typeof specification === "string") { | ||
if (specification.trim() === "") { | ||
return {}; | ||
if (typeof content === "string") { | ||
if (content.trim() === "") { | ||
return void 0; | ||
} | ||
try { | ||
return JSON.parse(specification); | ||
return JSON.parse(content); | ||
} catch (_error) { | ||
return parse(specification, { | ||
const hasColon = /^[^:]+:/.test(content); | ||
const isMultiLine = content.includes("\n"); | ||
if (!hasColon || !isMultiLine) { | ||
return void 0; | ||
} | ||
return parse(content, { | ||
maxAliasCount: 1e4 | ||
@@ -19,6 +24,6 @@ }); | ||
} | ||
if (isFilesystem(specification)) { | ||
return specification; | ||
if (isFilesystem(content)) { | ||
return content; | ||
} | ||
return specification; | ||
return content; | ||
} | ||
@@ -25,0 +30,0 @@ export { |
import { ERRORS } from "../configuration/index.js"; | ||
import { getEntrypoint } from "./get-entrypoint.js"; | ||
import { getSegmentsFromPath } from "./get-segments-from-path.js"; | ||
import { isObject } from "./is-object.js"; | ||
import { makeFilesystem } from "./make-filesystem.js"; | ||
@@ -10,2 +11,12 @@ function resolveReferences(input, options, file, errors = []) { | ||
const finalInput = file?.specification ?? entrypoint.specification; | ||
if (!isObject(finalInput)) { | ||
if (options?.throwOnError) { | ||
throw new Error(ERRORS.NO_CONTENT); | ||
} | ||
return { | ||
valid: false, | ||
errors, | ||
schema: finalInput | ||
}; | ||
} | ||
dereference(finalInput, filesystem, file ?? entrypoint, /* @__PURE__ */ new WeakSet(), errors, options); | ||
@@ -12,0 +23,0 @@ errors = errors.filter( |
@@ -20,3 +20,3 @@ { | ||
], | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"engines": { | ||
@@ -67,4 +67,4 @@ "node": ">=20" | ||
"vite": "5.4.19", | ||
"@scalar/build-tooling": "0.2.0", | ||
"@scalar/openapi-types": "0.3.1", | ||
"@scalar/build-tooling": "0.2.1", | ||
"@scalar/types": "0.2.1" | ||
@@ -71,0 +71,0 @@ }, |
Sorry, the diff of this file is too big to display
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
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
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
755377
-23.07%250
-14.38%14473
-16.83%