Skip to content

Commit

Permalink
feat: update scalar configuration
Browse files Browse the repository at this point in the history
zAlweNy26 committed Sep 26, 2024
1 parent 18860ac commit 608ea8a
Showing 6 changed files with 16 additions and 32 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
@@ -66,7 +66,7 @@
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@scalar/api-reference": "^1.12.5",
"@scalar/api-reference": "^1.25.21",
"@types/bun": "1.1.6",
"@types/lodash.clonedeep": "^4.5.9",
"elysia": ">= 1.1.0-rc.2",
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
@@ -97,7 +97,7 @@ export const swagger = async <Path extends string = '/swagger'>(
stringifiedSwaggerOptions,
autoDarkMode
)
: ScalarRender(scalarVersion, scalarConfiguration, scalarCDN),
: ScalarRender(info, scalarVersion, scalarConfiguration, scalarCDN),
{
headers: {
'content-type': 'text/html; charset=utf8'
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"
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;
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'> {

0 comments on commit 608ea8a

Please sign in to comment.