diff --git a/src/lib/components/atoms/ExampleInput.svelte b/src/lib/components/atoms/ExampleInput.svelte index 4b9c1cb..971abcd 100644 --- a/src/lib/components/atoms/ExampleInput.svelte +++ b/src/lib/components/atoms/ExampleInput.svelte @@ -3,12 +3,39 @@ import { SlideToggle } from '@skeletonlabs/skeleton'; export let example: OpenAPIV3.ExampleObject; - export let name: string; + export let name: string = ''; + + let exampleValue = example.value; + let external = false; + + // initialize the component + (() => { + if ( + 'value'! in example && + 'externalValue' in example && + example.externalValue !== ('' || undefined) + ) { + external = true; + return; + } + external = false; + })(); + + $: { + // make sure the exampleValue is a JSON-compatible string + try { + JSON.parse(exampleValue); + } catch (e) { + exampleValue = JSON.stringify(exampleValue); + } + // apply the changes to the example object + example.value = exampleValue; + } let schema = false; -
+
Schema

{name}

{#if schema} @@ -18,19 +45,45 @@ {:else}