mirror of
https://github.com/LukeHagar/OpenAPI.gg.git
synced 2025-12-06 04:20:29 +00:00
update server page
This commit is contained in:
@@ -1,27 +1,43 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { popup, type PopupSettings } from '@skeletonlabs/skeleton';
|
import { InputChip, popup, type PopupSettings } from '@skeletonlabs/skeleton';
|
||||||
import Info from '../icons/Info.svelte';
|
import Info from '../icons/Info.svelte';
|
||||||
|
import type { OpenAPIV3 } from '$lib/openAPITypes';
|
||||||
|
|
||||||
export let id: number;
|
export let id: number;
|
||||||
export let url: string;
|
export let server: OpenAPIV3.ServerObject;
|
||||||
export let description: string = '';
|
|
||||||
|
|
||||||
const descriptionTooltip: PopupSettings = {
|
const descriptionTooltip: PopupSettings = {
|
||||||
event: 'click',
|
event: 'click',
|
||||||
target: `descriptionTooltip${id}`,
|
target: `descriptionTooltip${id}`,
|
||||||
placement: 'top'
|
placement: 'top'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addVariable = () => {
|
||||||
|
// if server has no variables, add a variable-object
|
||||||
|
if (!server.variables) {
|
||||||
|
const variable = prompt('Enter variable name');
|
||||||
|
if (!variable) return;
|
||||||
|
server.variables = {
|
||||||
|
[variable]: {
|
||||||
|
default: '',
|
||||||
|
description: '',
|
||||||
|
enum: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<label class="space-y-2">
|
<label class="space-y-2">
|
||||||
<span>URL (required)</span>
|
<span>URL (required)</span>
|
||||||
|
<p>You can add parameters using curly-braces like so: <code>{id}</code></p>
|
||||||
<input
|
<input
|
||||||
class="input"
|
class="input"
|
||||||
name="url {id}"
|
name="url{id}"
|
||||||
placeholder="https://api.example.com/v1"
|
placeholder="https://{id}.api.example.com/v1"
|
||||||
type="url"
|
type="url"
|
||||||
bind:value={url}
|
bind:value={server.url}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
@@ -35,14 +51,59 @@
|
|||||||
<textarea
|
<textarea
|
||||||
class="textarea"
|
class="textarea"
|
||||||
name="description {id}"
|
name="description {id}"
|
||||||
placeholder="The main API server"
|
placeholder="Optional multiline or single-line description. Supports Markdown."
|
||||||
bind:value={description}
|
bind:value={server.description}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
<div class="border-token rounded-container-token space-y-4 p-4">
|
||||||
|
<div>
|
||||||
<!-- Description Tooltip -->
|
<h4 class="h4">Variables (optional)</h4>
|
||||||
<div class="card px-4 py-2 variant-filled-primary" data-popup="descriptionTooltip{id}">
|
<p>Define variables for the server URL.</p>
|
||||||
<p>Optional multiline or single-line description. Supports Markdown.</p>
|
</div>
|
||||||
<div class="arrow variant-filled-primary" />
|
{#if server.variables}
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
{#each Object.keys(server.variables) as variable}
|
||||||
|
<tr>
|
||||||
|
<td class="text-center">
|
||||||
|
<div class="flex justify-center items-center">
|
||||||
|
<p class="text-xl">{variable}</p>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input
|
||||||
|
class="input"
|
||||||
|
placeholder="default"
|
||||||
|
type="text"
|
||||||
|
bind:value={server.variables[variable].default}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input
|
||||||
|
class="input"
|
||||||
|
placeholder="description"
|
||||||
|
type="text"
|
||||||
|
bind:value={server.variables[variable].description}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td class="!w-1/3">
|
||||||
|
<div >
|
||||||
|
<InputChip
|
||||||
|
bind:value={server.variables[variable].enum}
|
||||||
|
name="enum"
|
||||||
|
placeholder="enum (optional)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{/if}
|
||||||
|
<span class="flex justify-center">
|
||||||
|
<button type="button" class="btn btn-sm variant-filled-primary" on:click={addVariable}>
|
||||||
|
Add Variable
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- <script lang="ts">
|
<script lang="ts">
|
||||||
import { openApiStore } from '$lib';
|
import { openApiStore } from '$lib';
|
||||||
import ServerInput from '../atoms/ServerInput.svelte';
|
import ServerInput from '../atoms/ServerInput.svelte';
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
Remove Server
|
Remove Server
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
<ServerInput id={1} bind:url={server.url} bind:description={server.description} />
|
<ServerInput id={1} bind:server />
|
||||||
</li>
|
</li>
|
||||||
{#if index < $openApiStore.servers.length - 1}
|
{#if index < $openApiStore.servers.length - 1}
|
||||||
<hr />
|
<hr />
|
||||||
@@ -40,4 +40,4 @@
|
|||||||
Add Server
|
Add Server
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
</form> -->
|
</form>
|
||||||
|
|||||||
2
src/lib/openAPITypes.d.ts
vendored
2
src/lib/openAPITypes.d.ts
vendored
@@ -5,7 +5,7 @@ export namespace OpenAPIV3 {
|
|||||||
interface Document<T extends {} = {}> {
|
interface Document<T extends {} = {}> {
|
||||||
openapi: string;
|
openapi: string;
|
||||||
info: InfoObject;
|
info: InfoObject;
|
||||||
servers?: ServerObject[];
|
servers: ServerObject[];
|
||||||
paths: PathsObject<T>;
|
paths: PathsObject<T>;
|
||||||
components?: ComponentsObject;
|
components?: ComponentsObject;
|
||||||
security?: SecurityRequirementObject[];
|
security?: SecurityRequirementObject[];
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
// Floating UI for Popups
|
// Floating UI for Popups
|
||||||
import { computePosition, autoUpdate, flip, shift, offset, arrow } from '@floating-ui/dom';
|
import { computePosition, autoUpdate, flip, shift, offset, arrow } from '@floating-ui/dom';
|
||||||
import { storePopup } from '@skeletonlabs/skeleton';
|
import { storePopup } from '@skeletonlabs/skeleton';
|
||||||
|
import { localStoragePrefix } from '$lib';
|
||||||
storePopup.set({ computePosition, autoUpdate, flip, shift, offset, arrow });
|
storePopup.set({ computePosition, autoUpdate, flip, shift, offset, arrow });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -24,6 +25,18 @@
|
|||||||
>
|
>
|
||||||
Schema Reference
|
Schema Reference
|
||||||
</a>
|
</a>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn variant-ringed-error hover:variant-filled-error"
|
||||||
|
on:click={() => {
|
||||||
|
if (confirm('Are you sure you want to reset ALL current inputs?')) {
|
||||||
|
// remove `openApi` from localStorage
|
||||||
|
localStorage.removeItem(`${localStoragePrefix}openApi`);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reset Inputs
|
||||||
|
</button>
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
<div class="mx-8 my-4">
|
<div class="mx-8 my-4">
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
{:else if $tabSet === 1}
|
{:else if $tabSet === 1}
|
||||||
<!-- <Authentication /> -->
|
<!-- <Authentication /> -->
|
||||||
{:else if $tabSet === 2}
|
{:else if $tabSet === 2}
|
||||||
<!-- <Servers /> -->
|
<Servers />
|
||||||
{:else if $tabSet === 3}
|
{:else if $tabSet === 3}
|
||||||
<p>Paths</p>
|
<p>Paths</p>
|
||||||
{:else if $tabSet === 4}
|
{:else if $tabSet === 4}
|
||||||
|
|||||||
Reference in New Issue
Block a user