Skip to content

Commit

Permalink
chore: update @scalar/openapi-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
hanspagel committed May 24, 2024
1 parent 9404aeb commit 86ba536
Show file tree
Hide file tree
Showing 9 changed files with 1,886 additions and 668 deletions.
2 changes: 1 addition & 1 deletion packages/api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@floating-ui/vue": "^1.0.2",
"@headlessui/vue": "^1.7.20",
"@scalar/components": "workspace:*",
"@scalar/openapi-parser": "^0.3.2",
"@scalar/openapi-parser": "^0.4.0",
"@scalar/themes": "workspace:*",
"@scalar/use-codemirror": "workspace:*",
"@scalar/use-modal": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-reference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@scalar/api-client": "workspace:*",
"@scalar/components": "workspace:*",
"@scalar/oas-utils": "workspace:*",
"@scalar/openapi-parser": "^0.3.2",
"@scalar/openapi-parser": "^0.4.0",
"@scalar/snippetz": "^0.1.6",
"@scalar/themes": "workspace:*",
"@scalar/use-modal": "workspace:*",
Expand Down
26 changes: 14 additions & 12 deletions packages/api-reference/src/helpers/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import { type RequestMethod, validRequestMethods } from '@scalar/api-client'
import {
type AnyObject,
type OpenAPI,
type OpenAPIV2,
type OpenAPIV3,
type OpenAPIV3_1,
type ResolvedOpenAPI,
fetchUrlsPlugin,
openapi,
} from '@scalar/openapi-parser'

import { createEmptySpecification } from '../helpers'
// AnyStringOrObject
import type { Spec, Tag } from '../types'
import type { Spec } from '../types'

export const parse = (specification: any): Promise<Spec> => {
// eslint-disable-next-line no-async-promise-executor
Expand All @@ -24,19 +23,22 @@ export const parse = (specification: any): Promise<Spec> => {
// Return an empty resolved specification if the given specification is empty
if (!specification) {
return resolve(
transformResult(
createEmptySpecification() as ResolvedOpenAPI.Document,
),
transformResult(createEmptySpecification() as OpenAPI.Document),
)
}

const start = performance.now()

const { schema, errors } = await openapi()
.load(specification, {
plugins: [fetchUrlsPlugin],
plugins: [fetchUrlsPlugin()],
})
.dereference()
.get()

const end = performance.now()
console.log(`dereference: ${Math.round(end - start)} ms`)

if (errors?.length) {
console.warn(
'Please open an issue on https://github.com/scalar/scalar\n',
Expand All @@ -49,9 +51,7 @@ export const parse = (specification: any): Promise<Spec> => {
reject(errors?.[0]?.error ?? 'Failed to parse the OpenAPI file.')

return resolve(
transformResult(
createEmptySpecification() as ResolvedOpenAPI.Document,
),
transformResult(createEmptySpecification() as OpenAPI.Document),
)
}

Expand All @@ -61,12 +61,12 @@ export const parse = (specification: any): Promise<Spec> => {
}

return resolve(
transformResult(createEmptySpecification() as ResolvedOpenAPI.Document),
transformResult(createEmptySpecification() as OpenAPI.Document),
)
})
}

const transformResult = (originalSchema: ResolvedOpenAPI.Document): Spec => {
const transformResult = (originalSchema: OpenAPI.Document): Spec => {
// Make it an object
let schema = {} as AnyObject

Expand Down Expand Up @@ -176,6 +176,7 @@ const transformResult = (originalSchema: ResolvedOpenAPI.Document): Spec => {
if (
!schema.tags?.find(
(tag: OpenAPIV2.TagObject | OpenAPIV3.TagObject) =>
// @ts-expect-error upstream issue
tag.name === 'default',
)
) {
Expand All @@ -189,6 +190,7 @@ const transformResult = (originalSchema: ResolvedOpenAPI.Document): Spec => {
// find the index of the default tag
const indexOfDefaultTag = schema.tags?.findIndex(
(tag: OpenAPIV2.TagObject | OpenAPIV3.TagObject) =>
// @ts-expect-error upstream issue
tag.name === 'default',
)

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@scalar/api-reference": "workspace:*",
"@scalar/mock-server": "workspace:*",
"@scalar/oas-utils": "workspace:*",
"@scalar/openapi-parser": "^0.3.2",
"@scalar/openapi-parser": "^0.4.0",
"commander": "^12.0.0",
"glob": "^10.3.10",
"hono": "^4.2.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/galaxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
],
"module": "./dist/index.js",
"devDependencies": {
"@scalar/openapi-parser": "^0.3.2",
"@scalar/openapi-parser": "^0.4.0",
"@vitest/coverage-v8": "^1.5.0",
"tsc-alias": "^1.8.8",
"vite": "^5.2.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/mock-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"@hono/node-server": "^1.11.0",
"@scalar/oas-utils": "workspace:*",
"@scalar/openapi-parser": "^0.3.2",
"@scalar/openapi-parser": "^0.4.0",
"hono": "^4.2.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/oas-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"devDependencies": {
"@scalar/build-tooling": "workspace:*",
"@scalar/openapi-parser": "^0.3.2",
"@scalar/openapi-parser": "^0.4.0",
"axios": "^1.6.8",
"httpsnippet-lite": "^3.0.5",
"tsc-alias": "^1.8.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/play-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"dependencies": {
"@scalar/api-client": "workspace:*",
"@scalar/api-reference": "workspace:*",
"@scalar/openapi-parser": "^0.3.2",
"@scalar/openapi-parser": "^0.4.0",
"@scalar/themes": "workspace:*",
"@vueuse/core": "^10.9.0"
},
Expand Down
Loading

0 comments on commit 86ba536

Please sign in to comment.