From afc7e36cf8b224a12c78cd2a1174581d00cc3561 Mon Sep 17 00:00:00 2001 From: Anna Stasiuk Date: Mon, 15 Jul 2019 11:14:48 +0300 Subject: [PATCH] feat: Add option for skipping quotes in enums `enumSkipQuotes` (#968) * feat: add option for skipping enum quotes * chore: move enumSkipQuotes --- src/components/Fields/EnumValues.tsx | 16 +++++++++++----- src/components/Fields/FieldDetails.tsx | 5 ++++- src/services/RedocNormalizedOptions.ts | 3 +++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/Fields/EnumValues.tsx b/src/components/Fields/EnumValues.tsx index ca39ddb4..e0e9a81f 100644 --- a/src/components/Fields/EnumValues.tsx +++ b/src/components/Fields/EnumValues.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { ExampleValue, FieldLabel } from '../../common-elements/fields'; import { l } from '../../services/Labels'; +import { OptionsContext } from '../OptionsProvider'; export interface EnumValuesProps { values: string[]; @@ -9,8 +10,10 @@ export interface EnumValuesProps { } export class EnumValues extends React.PureComponent { + static contextType = OptionsContext; render() { const { values, type } = this.props; + const { enumSkipQuotes } = this.context; if (!values.length) { return null; } @@ -21,11 +24,14 @@ export class EnumValues extends React.PureComponent { {type === 'array' ? l('enumArray') : ''}{' '} {values.length === 1 ? l('enumSingleValue') : l('enum')}: - {values.map((value, idx) => ( - - {JSON.stringify(value)}{' '} - - ))} + {values.map((value, idx) => { + const exampleValue = enumSkipQuotes ? value : JSON.stringify(value); + return ( + + {exampleValue} + + ); + })} ); } diff --git a/src/components/Fields/FieldDetails.tsx b/src/components/Fields/FieldDetails.tsx index 87bb2363..65ce160e 100644 --- a/src/components/Fields/FieldDetails.tsx +++ b/src/components/Fields/FieldDetails.tsx @@ -21,10 +21,13 @@ import { FieldDetail } from './FieldDetail'; import { Badge } from '../../common-elements/'; import { l } from '../../services/Labels'; +import { OptionsContext } from '../OptionsProvider'; export class FieldDetails extends React.PureComponent { + static contextType = OptionsContext; render() { const { showExamples, field, renderDiscriminatorSwitch } = this.props; + const { enumSkipQuotes } = this.context; const { schema, description, example, deprecated } = field; @@ -65,7 +68,7 @@ export class FieldDetails extends React.PureComponent { {l('deprecated')} )} - + {!renderDiscriminatorSwitch && }{' '} {exampleField} {} diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index 7c893f1b..9c7e8452 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -28,6 +28,7 @@ export interface RedocRawOptions { allowedMdComponents?: Dict; labels?: LabelsConfigRaw; + enumSkipQuotes?: boolean | string; } function argValueToBoolean(val?: string | boolean): boolean { @@ -125,6 +126,7 @@ export class RedocNormalizedOptions { onlyRequiredInSamples: boolean; showExtensions: boolean | string[]; hideSingleRequestSampleTab: boolean; + enumSkipQuotes: boolean; /* tslint:disable-next-line */ unstable_ignoreMimeParameters: boolean; @@ -156,6 +158,7 @@ export class RedocNormalizedOptions { this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples); this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions); this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab); + this.enumSkipQuotes = argValueToBoolean(raw.enumSkipQuotes); this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);