From 5297fdf01ae3705b6474a239b1ad5c983f869dec Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 10 May 2019 16:27:09 +0300 Subject: [PATCH] chore: minor refactor of example values --- src/components/PayloadSamples/Example.tsx | 16 ++-------------- src/components/PayloadSamples/ExampleValue.tsx | 4 ++++ src/services/models/Example.ts | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/components/PayloadSamples/Example.tsx b/src/components/PayloadSamples/Example.tsx index 392e2138..acf447eb 100644 --- a/src/components/PayloadSamples/Example.tsx +++ b/src/components/PayloadSamples/Example.tsx @@ -2,9 +2,6 @@ import * as React from 'react'; import { StyledPre } from '../../common-elements/samples'; import { ExampleModel } from '../../services/models'; -import { isJsonLike, langFromMime } from '../../utils'; -import { JsonViewer } from '../JsonViewer/JsonViewer'; -import { SourceCodeWithCopy } from '../SourceCode/SourceCode'; import { ExampleValue } from './ExampleValue'; import { useExternalExample } from './exernalExampleHook'; @@ -22,14 +19,13 @@ export function Example({ example, mimeType }: ExampleProps) { } export function ExternalExample({ example, mimeType }: ExampleProps) { - let value = useExternalExample(example, mimeType); + const value = useExternalExample(example, mimeType); if (value === undefined) { return Loading...; } if (value instanceof Error) { - console.log(value); return ( Error loading external example:
@@ -40,13 +36,5 @@ export function ExternalExample({ example, mimeType }: ExampleProps) { ); } - if (isJsonLike(mimeType)) { - return ; - } else { - if (typeof value === 'object') { - // just in case example was cached as json but used as non-json - value = JSON.stringify(value, null, 2); - } - return ; - } + return ; } diff --git a/src/components/PayloadSamples/ExampleValue.tsx b/src/components/PayloadSamples/ExampleValue.tsx index fa35e842..dddea45e 100644 --- a/src/components/PayloadSamples/ExampleValue.tsx +++ b/src/components/PayloadSamples/ExampleValue.tsx @@ -13,6 +13,10 @@ export function ExampleValue({ value, mimeType }: ExampleValueProps) { if (isJsonLike(mimeType)) { return ; } else { + if (typeof value === 'object') { + // just in case example was cached as json but used as non-json + value = JSON.stringify(value, null, 2); + } return ; } } diff --git a/src/services/models/Example.ts b/src/services/models/Example.ts index 0097ed80..66bb9201 100644 --- a/src/services/models/Example.ts +++ b/src/services/models/Example.ts @@ -15,7 +15,7 @@ export class ExampleModel { constructor( parser: OpenAPIParser, infoOrRef: Referenced, - mime: string, + public mime: string, encoding?: { [field: string]: OpenAPIEncoding }, ) { const example = parser.deref(infoOrRef);