mirror of
https://github.com/LukeHagar/OpenAPI.gg.git
synced 2025-12-07 20:47:47 +00:00
feature/add route parameters (#18)
* add package manager field to package json * Remove TODO * design rework and path basics * update packagemanager * remove package manager
This commit is contained in:
@@ -1,59 +1,41 @@
|
||||
<script lang="ts">
|
||||
import { addPath } from '$lib';
|
||||
import { openApiStore, pathRegex, sortPathsAlphabetically } from '$lib';
|
||||
import { pathTemplate } from '$lib/pathTemplate';
|
||||
import { openApiStore, sortPathsAlphabetically } from '$lib';
|
||||
import type { OpenAPIV3 } from '$lib/openAPITypes';
|
||||
import PathListItem from '../atoms/PathListItem.svelte';
|
||||
import PathButtons from '../atoms/PathButtons.svelte';
|
||||
import { getModalStore } from '@skeletonlabs/skeleton';
|
||||
|
||||
let paths: OpenAPIV3.PathsObject = {};
|
||||
// @ts-expect-error - working with a potentially empty object
|
||||
openApiStore.subscribe((store) => (paths = store.paths));
|
||||
|
||||
const modalStore = getModalStore();
|
||||
|
||||
// match path with parameters
|
||||
|
||||
// add path
|
||||
// const addPath = () => {
|
||||
// // prompt user to enter path
|
||||
// const path = prompt(
|
||||
// 'Enter path. Wrap path parameters in curly braces. Example: /users/{userId}'
|
||||
// );
|
||||
// if (!path) return;
|
||||
// // check if path is valid
|
||||
// if (!pathRegex.test(path)) {
|
||||
// alert('Invalid path');
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // check if path already exists
|
||||
// // @ts-expect-error - we are working with an initially empty object
|
||||
// if ($openApiStore.paths[path]) {
|
||||
// alert('Path already exists');
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // create a temporary object to store paths
|
||||
// // add path to paths object
|
||||
// $openApiStore.paths = {
|
||||
// ...$openApiStore.paths,
|
||||
// [path]: pathTemplate
|
||||
// };
|
||||
|
||||
// // sort paths alphabetically
|
||||
// sortPathsAlphabetically();
|
||||
// };
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="container mx-auto border-token rounded-container-token bg-surface-backdrop-token px-6 py-4 min-h-20 space-y-3"
|
||||
class="container mx-auto border-token rounded-container-token bg-surface-backdrop-token px-6 py-4 space-y-4"
|
||||
>
|
||||
{#if Object.keys($openApiStore.paths).length > 0}
|
||||
<PathButtons />
|
||||
<hr />
|
||||
{#each Object.keys($openApiStore.paths) as pathName, index}
|
||||
<PathListItem {pathName} id={index} />
|
||||
{/each}
|
||||
|
||||
<PathButtons />
|
||||
{:else}
|
||||
<PathButtons justify="justify-center" sort={false} />
|
||||
{/if}
|
||||
{#each Object.keys(paths) as pathName, index}
|
||||
<PathListItem {pathName} id={index} />
|
||||
{/each}
|
||||
<span class="w-full flex justify-center">
|
||||
<button
|
||||
type="button"
|
||||
class="btn variant-filled-primary"
|
||||
on:click={() => {
|
||||
addPath(modalStore);
|
||||
}}
|
||||
>
|
||||
Add Path
|
||||
</button>
|
||||
</span>
|
||||
<span class="w-full flex justify-center">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm variant-filled-secondary"
|
||||
on:click={sortPathsAlphabetically}
|
||||
>
|
||||
Sort paths
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user