From bb4594ee58d89819c975bdb575083c0667e3d940 Mon Sep 17 00:00:00 2001 From: Anna Stasiuk Date: Mon, 30 Nov 2020 11:54:46 +0200 Subject: [PATCH] feat: add new option hideSchemaPattern (#1475) * feat: add new option hideSchemaPattern * chore: add hideSchemaPattern option to readme --- README.md | 1 + src/components/Fields/FieldDetails.tsx | 4 ++-- src/services/RedocNormalizedOptions.ts | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ef6c1610..60dbc2fc 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,7 @@ You can use all of the following options with standalone version on tag * `hideDownloadButton` - do not show "Download" spec button. **THIS DOESN'T MAKE YOUR SPEC PRIVATE**, it just hides the button. * `hideHostname` - if set, the protocol and hostname is not shown in the operation definition. * `hideLoading` - do not show loading animation. Useful for small docs. +* `hideSchemaPattern` - if set, the pattern is not shown in the schema. * `hideSingleRequestSampleTab` - do not show the request sample tab for requests with only one sample. * `expandSingleSchemaField` - automatically expand single field in a schema * `jsonSampleExpandLevel` - set the default expand level for JSON payload samples (responses and request body). Special value 'all' expands all levels. The default value is `2`. diff --git a/src/components/Fields/FieldDetails.tsx b/src/components/Fields/FieldDetails.tsx index 839595a3..980eff4f 100644 --- a/src/components/Fields/FieldDetails.tsx +++ b/src/components/Fields/FieldDetails.tsx @@ -46,7 +46,7 @@ export class FieldDetails extends React.PureComponent ({schema.title}) } {schema.nullable && {l('nullable')} } - {schema.pattern && ( + {schema.pattern && !hideSchemaPattern && ( <> {patternShown || schema.pattern.length < MAX_PATTERN_LENGTH diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index 126e313a..58d4b8b0 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -41,6 +41,7 @@ export interface RedocRawOptions { expandDefaultServerVariables?: boolean; maxDisplayedEnumValues?: number; ignoreNamedSchemas?: string[] | string; + hideSchemaPattern?: boolean; } function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean { @@ -194,6 +195,7 @@ export class RedocNormalizedOptions { maxDisplayedEnumValues?: number; ignoreNamedSchemas: Set; + hideSchemaPattern: boolean; constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) { raw = { ...defaults, ...raw }; @@ -250,7 +252,10 @@ export class RedocNormalizedOptions { this.expandDefaultServerVariables = argValueToBoolean(raw.expandDefaultServerVariables); this.maxDisplayedEnumValues = argValueToNumber(raw.maxDisplayedEnumValues); - const ignoreNamedSchemas = Array.isArray(raw.ignoreNamedSchemas) ? raw.ignoreNamedSchemas : raw.ignoreNamedSchemas?.split(',').map(s => s.trim()); + const ignoreNamedSchemas = Array.isArray(raw.ignoreNamedSchemas) + ? raw.ignoreNamedSchemas + : raw.ignoreNamedSchemas?.split(',').map((s) => s.trim()); this.ignoreNamedSchemas = new Set(ignoreNamedSchemas); + this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern); } }