From d7e054dd481e0e8eb2e6dc1c7cbdca941c836476 Mon Sep 17 00:00:00 2001 From: Malte Teichert Date: Mon, 10 Jun 2024 00:54:08 +0200 Subject: [PATCH] improve path editing --- src/lib/components/atoms/ExampleInput.svelte | 77 +++++++-- .../components/atoms/ParameterInput.svelte | 152 +++++++++++++++++- .../components/atoms/paths/PathEditing.svelte | 41 +++-- src/routes/paths/[index]/+page.svelte | 7 +- 4 files changed, 250 insertions(+), 27 deletions(-) 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}