From b09f2dff5b8ec8faec78a24c853a3621cd1a0a48 Mon Sep 17 00:00:00 2001 From: Malte Teichert Date: Sun, 9 Jun 2024 02:16:27 +0200 Subject: [PATCH 1/2] Rework path handling --- .../components/atoms/ParameterInput.svelte | 157 ++++---------- src/lib/components/atoms/ServerInput.svelte | 94 ++++---- .../components/atoms/paths/PathEditing.svelte | 116 ++++++++++ src/routes/paths/+page.svelte | 1 + src/routes/paths/[index]/+page.svelte | 200 +++++------------- 5 files changed, 269 insertions(+), 299 deletions(-) create mode 100644 src/lib/components/atoms/paths/PathEditing.svelte diff --git a/src/lib/components/atoms/ParameterInput.svelte b/src/lib/components/atoms/ParameterInput.svelte index 1c68df7..369cfbb 100644 --- a/src/lib/components/atoms/ParameterInput.svelte +++ b/src/lib/components/atoms/ParameterInput.svelte @@ -3,122 +3,57 @@ import { SlideToggle } from '@skeletonlabs/skeleton'; import ExampleInput from '$lib/components/atoms/ExampleInput.svelte'; - export let variableName: string; - export let value: OpenAPIV3.ParameterObject; - export let location: 'path' | 'query' | 'header' | 'cookie'; + export let parameter: OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject; - value.name = variableName; - value.in = location; - if (location === 'path') value.required = true; - let multipleExamples = value.examples && Object.keys(value.examples).length > 1; + // if the parameter is a reference, we need to link to the reference + let isReference = '$ref' in parameter; - const addParameterExample = () => { - const exampleName = prompt('Enter a name for the example'); - if (!exampleName) return; - // @ts-expect-error - working we are setting a new key - value.examples[exampleName] = { - $ref: '', - summary: '', - description: '', - value: '', - externalValue: '' - }; - }; + parameter = isReference + ? (parameter as OpenAPIV3.ReferenceObject) + : (parameter as OpenAPIV3.ParameterObject); + + // if the parameter is a path parameter, we need to limit the editing options + // @ts-expect-error parameter.in has to exist if the parameter is not a reference + let isPathParameter = !isReference && parameter.in === 'path';
-

{{variableName}}

- - -

Location:

- -
- -