Skip to content

Commit

Permalink
feat: update scalar configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Jul 3, 2024
1 parent 5cb3fa0 commit c6e16c5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 31 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@scalar/api-reference": "^1.12.5",
"@scalar/api-reference": "^1.24.29",
"@types/bun": "^1.0.4",
"@types/lodash.clonedeep": "^4.5.7",
"@types/node": "^20.1.4",
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ScalarRender } from './scalar'
import { filterPaths, registerSchemaPath } from './utils'

import type { OpenAPIV3 } from 'openapi-types'
import type { ReferenceConfiguration } from './scalar/types'
import type { ReferenceConfiguration } from '@scalar/api-reference'
import type { ElysiaSwaggerConfig } from './types'

/**
Expand Down Expand Up @@ -100,6 +100,7 @@ export const swagger =
autoDarkMode
)
: ScalarRender(
info,
scalarVersion,
scalarConfiguration,
scalarCDN
Expand Down
14 changes: 12 additions & 2 deletions src/scalar/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import scalarElysiaTheme from './theme'
import type { ReferenceConfiguration } from './types'
import type { OpenAPIV3 } from 'openapi-types'
import type { ReferenceConfiguration } from '@scalar/api-reference'

export const ScalarRender = (
info: OpenAPIV3.InfoObject,
version: string,
config: ReferenceConfiguration,
cdn: string
) => `<!doctype html>
<html>
<head>
<title>API Reference</title>
<title>${info.title}</title>
<meta
name="description"
content="${info.description}"
/>
<meta
name="og:description"
content="${info.description}"
/>
<meta charset="utf-8" />
<meta
name="viewport"
Expand Down
26 changes: 0 additions & 26 deletions src/scalar/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
import type { MetaFlatInput } from "./unjead";

export type ReferenceConfiguration = {
/** A string to use one of the color presets */
theme?: ThemeId;
/** The layout to use for the references */
layout?: ReferenceLayoutType;
/** The Swagger/OpenAPI spec to render */
spec?: SpecConfiguration;
/** URL to a request proxy for the API client */
proxy?: string;
/** Whether the spec input should show */
isEditable?: boolean;
/** Whether to show the sidebar */
showSidebar?: boolean;
/** Remove the Scalar branding :( */
/** Key used with CNTRL/CMD to open the search modal (defaults to 'k' e.g. CMD+k) */
searchHotKey?: string;
/** If used, passed data will be added to the HTML header. Read more: https://unhead.unjs.io/usage/composables/use-seo-meta */
metaData?: MetaFlatInput;
/** Custom CSS to be added to the page */
customCss?: string;
/** onSpecUpdate is fired on spec/swagger content change */
onSpecUpdate?: (spec: string) => void;
};

export type SpecConfiguration = {
/** URL to a Swagger/OpenAPI file */
url?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OpenAPIV3 } from 'openapi-types'
import type { ReferenceConfiguration } from './scalar/types'
import type { ReferenceConfiguration } from '@scalar/api-reference'
import type { SwaggerUIOptions } from './swagger/types'

export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
Expand Down

0 comments on commit c6e16c5

Please sign in to comment.