mirror of
https://github.com/LukeHagar/OpenAPI.gg.git
synced 2025-12-07 04:20:32 +00:00
refactor path handling
This commit is contained in:
@@ -1,40 +1,44 @@
|
||||
<script lang="ts">
|
||||
import { addPath } from '$lib';
|
||||
import { openApiStore, pathRegex, sortPathsAlphabetically } from '$lib';
|
||||
import { pathTemplate } from '$lib/pathTemplate';
|
||||
import PathListItem from '../atoms/PathListItem.svelte';
|
||||
import { getModalStore } from '@skeletonlabs/skeleton';
|
||||
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
// // 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
|
||||
};
|
||||
// // create a temporary object to store paths
|
||||
// // add path to paths object
|
||||
// $openApiStore.paths = {
|
||||
// ...$openApiStore.paths,
|
||||
// [path]: pathTemplate
|
||||
// };
|
||||
|
||||
// sort paths alphabetically
|
||||
sortPathsAlphabetically();
|
||||
};
|
||||
// // sort paths alphabetically
|
||||
// sortPathsAlphabetically();
|
||||
// };
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -44,7 +48,13 @@
|
||||
<PathListItem {pathName} id={index} />
|
||||
{/each}
|
||||
<span class="w-full flex justify-center">
|
||||
<button type="button" class="btn variant-filled-primary" on:click={addPath}>Add Path</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn variant-filled-primary"
|
||||
on:click={() => {
|
||||
addPath(modalStore);
|
||||
}}>Add Path</button
|
||||
>
|
||||
</span>
|
||||
<span class="w-full flex justify-center">
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user