mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-06 05:10:20 +03:00
Use enums instead of raw string
This commit is contained in:
parent
006d914c1d
commit
e03f173626
|
@ -5,6 +5,11 @@ import { isNumeric, mergeObjects } from '../utils/helpers';
|
|||
import { LabelsConfigRaw, setRedocLabels } from './Labels';
|
||||
import { MDXComponentMeta } from './MarkdownRenderer';
|
||||
|
||||
export enum SideNavStyleEnum {
|
||||
SummaryOnly = 'summary-only',
|
||||
PathOnly = 'path-only',
|
||||
}
|
||||
|
||||
export interface RedocRawOptions {
|
||||
theme?: ThemeInterface;
|
||||
scrollYOffset?: number | string | (() => number);
|
||||
|
@ -22,7 +27,7 @@ export interface RedocRawOptions {
|
|||
disableSearch?: boolean | string;
|
||||
onlyRequiredInSamples?: boolean | string;
|
||||
showExtensions?: boolean | string | string[];
|
||||
sideNavStyle?: string | 'summary-only';
|
||||
sideNavStyle?: SideNavStyleEnum;
|
||||
hideSingleRequestSampleTab?: boolean | string;
|
||||
menuToggle?: boolean | string;
|
||||
jsonSampleExpandLevel?: number | string | 'all';
|
||||
|
@ -143,8 +148,8 @@ export class RedocNormalizedOptions {
|
|||
}
|
||||
}
|
||||
|
||||
static normalizeSideNavStyle(value: RedocRawOptions['sideNavStyle']): string {
|
||||
const defaultValue = 'summary-only';
|
||||
static normalizeSideNavStyle(value: RedocRawOptions['sideNavStyle']): SideNavStyleEnum {
|
||||
const defaultValue = SideNavStyleEnum.SummaryOnly;
|
||||
if (typeof value !== 'string') {
|
||||
return defaultValue;
|
||||
}
|
||||
|
@ -152,8 +157,8 @@ export class RedocNormalizedOptions {
|
|||
switch (value) {
|
||||
case defaultValue:
|
||||
return value;
|
||||
case 'path-only':
|
||||
return value;
|
||||
case SideNavStyleEnum.PathOnly:
|
||||
return SideNavStyleEnum.PathOnly;
|
||||
default:
|
||||
return defaultValue;
|
||||
}
|
||||
|
@ -206,7 +211,7 @@ export class RedocNormalizedOptions {
|
|||
disableSearch: boolean;
|
||||
onlyRequiredInSamples: boolean;
|
||||
showExtensions: boolean | string[];
|
||||
sideNavStyle: string;
|
||||
sideNavStyle: SideNavStyleEnum;
|
||||
hideSingleRequestSampleTab: boolean;
|
||||
menuToggle: boolean;
|
||||
jsonSampleExpandLevel: number;
|
||||
|
|
|
@ -25,6 +25,7 @@ import { FieldModel } from './Field';
|
|||
import { MediaContentModel } from './MediaContent';
|
||||
import { RequestBodyModel } from './RequestBody';
|
||||
import { ResponseModel } from './Response';
|
||||
import { SideNavStyleEnum } from '../RedocNormalizedOptions';
|
||||
|
||||
export interface XPayloadSample {
|
||||
lang: 'payload';
|
||||
|
@ -105,7 +106,7 @@ export class OperationModel implements IMenuItem {
|
|||
|
||||
this.name = getOperationSummary(operationSpec);
|
||||
|
||||
this.sidebarLabel = options.sideNavStyle === 'path-only' ? this.path : this.name;
|
||||
this.sidebarLabel = options.sideNavStyle === SideNavStyleEnum.PathOnly ? this.path : this.name;
|
||||
|
||||
if (this.isCallback) {
|
||||
// NOTE: Callbacks by default should not inherit the specification's global `security` definition.
|
||||
|
|
Loading…
Reference in New Issue
Block a user