mirror of
https://github.com/LukeHagar/OpenAPI.gg.git
synced 2025-12-06 04:20:29 +00:00
Working towards a unified storage medium
This commit is contained in:
3869
pnpm-lock.yaml
generated
3869
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,12 @@
|
||||
|
||||
export let schema: OpenAPIV3_1.SecuritySchemeObject;
|
||||
|
||||
let availableFlows: string[] = ['implicit', 'password', 'clientCredentials', 'authorizationCode'];
|
||||
let availableFlows: ('implicit' | 'password' | 'clientCredentials' | 'authorizationCode')[] = [
|
||||
'implicit',
|
||||
'password',
|
||||
'clientCredentials',
|
||||
'authorizationCode'
|
||||
];
|
||||
|
||||
// remove flows that are already in Object.keys(schema.flows)
|
||||
availableFlows = availableFlows.filter((flow) => {
|
||||
@@ -18,7 +23,7 @@
|
||||
return !Object.keys(schema.flows).includes(flow);
|
||||
});
|
||||
|
||||
let flowType: string;
|
||||
let flowType: 'implicit' | 'password' | 'clientCredentials' | 'authorizationCode';
|
||||
const addOauthFlow = () => {
|
||||
if (!flowType) return;
|
||||
// @ts-expect-error - security schema definition is lacking a bit
|
||||
@@ -27,7 +32,7 @@
|
||||
availableFlows = availableFlows.filter((flow) => flow !== flowType);
|
||||
};
|
||||
|
||||
const removeOauthFlow = (flow: string) => {
|
||||
const removeOauthFlow = (flow: 'implicit' | 'password' | 'clientCredentials' | 'authorizationCode') => {
|
||||
// @ts-expect-error - security schema definition is lacking a bit
|
||||
let tempFlows = schema.flows;
|
||||
delete tempFlows[flow];
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import type { OpenAPIV3 } from '$lib/openAPITypes';
|
||||
import type { OpenAPIV3_1 } from '$lib/openAPITypes';
|
||||
import { SlideToggle } from '@skeletonlabs/skeleton';
|
||||
|
||||
export let example: OpenAPIV3.ExampleObject;
|
||||
export let example: OpenAPIV3_1.ExampleObject | OpenAPIV3_1.ReferenceObject;
|
||||
export let name: string;
|
||||
|
||||
let schema = false;
|
||||
@@ -24,13 +24,17 @@
|
||||
<p>Description</p>
|
||||
<textarea class="textarea" name="description" bind:value={example.description} />
|
||||
</label>
|
||||
<label>
|
||||
<p>Value</p>
|
||||
<input type="text" class="input" name="value" bind:value={example.value} />
|
||||
</label>
|
||||
<label>
|
||||
<p>External Value</p>
|
||||
<input type="text" class="input" name="externalValue" bind:value={example.externalValue} />
|
||||
</label>
|
||||
{#if 'value' in example}
|
||||
<label>
|
||||
<p>Value</p>
|
||||
<input type="text" class="input" name="value" bind:value={example.value} />
|
||||
</label>
|
||||
{/if}
|
||||
{#if 'externalValue' in example}
|
||||
<label>
|
||||
<p>External Value</p>
|
||||
<input type="text" class="input" name="externalValue" bind:value={example.externalValue} />
|
||||
</label>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { openApiStore } from '$lib';
|
||||
import { selectedSpec } from '$lib/db';
|
||||
import spdxLicenseList from 'spdx-license-list';
|
||||
|
||||
const popularLicenses = ['MIT', 'Apache-2.0', 'GPL-3.0', 'Unlicense'];
|
||||
@@ -8,15 +8,15 @@
|
||||
<div class="border-token rounded-container-token space-y-1 p-4">
|
||||
<div class="flex flex-row justify-between">
|
||||
<h4 class="h4">License</h4>
|
||||
{#if $openApiStore.info.license}
|
||||
{#if $selectedSpec.spec.info.license}
|
||||
<label class="text-sm space-x-2">
|
||||
<span>Pick a license</span>
|
||||
<select
|
||||
class="select w-56 text-sm"
|
||||
bind:value={$openApiStore.info.license.identifier}
|
||||
bind:value={$selectedSpec.spec.info.license.identifier}
|
||||
on:change={() => {
|
||||
$openApiStore.info.license.name =
|
||||
spdxLicenseList[$openApiStore.info.license.identifier].name;
|
||||
$selectedSpec.spec.info.license.name =
|
||||
spdxLicenseList[$selectedSpec.spec.info.license.identifier].name;
|
||||
}}
|
||||
>
|
||||
<optgroup label="Popular Licenses">
|
||||
@@ -34,7 +34,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if $openApiStore.info.license}
|
||||
{#if $selectedSpec.spec.info.license}
|
||||
<label class="text-sm space-y-1">
|
||||
<span>Name (required)</span>
|
||||
<input
|
||||
@@ -42,7 +42,7 @@
|
||||
name="licenseName"
|
||||
placeholder="Apache 2.0"
|
||||
type="text"
|
||||
bind:value={$openApiStore.info.license.name}
|
||||
bind:value={$selectedSpec.spec.info.license.name}
|
||||
/>
|
||||
</label>
|
||||
<label class="text-sm space-y-1">
|
||||
@@ -52,7 +52,7 @@
|
||||
name="licenseIdentifier"
|
||||
placeholder="Apache-2.0"
|
||||
type="text"
|
||||
bind:value={$openApiStore.info.license.identifier}
|
||||
bind:value={$selectedSpec.spec.info.license.identifier}
|
||||
/>
|
||||
</label>
|
||||
<label class="text-sm space-y-1">
|
||||
@@ -62,7 +62,7 @@
|
||||
name="licenseUrl"
|
||||
placeholder="https://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
type="url"
|
||||
bind:value={$openApiStore.info.license.url}
|
||||
bind:value={$selectedSpec.spec.info.license.url}
|
||||
/>
|
||||
</label>
|
||||
{:else}
|
||||
@@ -70,7 +70,7 @@
|
||||
type="button"
|
||||
class="btn variant-filled-primary"
|
||||
on:click={() => {
|
||||
$openApiStore.info.license = {
|
||||
$selectedSpec.spec.info.license = {
|
||||
name: '',
|
||||
identifier: '',
|
||||
url: ''
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<script lang="ts">
|
||||
import type { OpenAPIV3 } from '$lib/openAPITypes';
|
||||
import type { OpenAPIV3_1 } from '$lib/openAPITypes';
|
||||
import { SlideToggle } from '@skeletonlabs/skeleton';
|
||||
import ExampleInput from '$lib/components/atoms/ExampleInput.svelte';
|
||||
|
||||
export let variableName: string;
|
||||
export let value: OpenAPIV3.ParameterObject;
|
||||
export let value: OpenAPIV3_1.ParameterObject;
|
||||
export let location: 'path' | 'query' | 'header' | 'cookie';
|
||||
|
||||
value.name = variableName;
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { pathTemplate } from '$lib/pathTemplate';
|
||||
import {
|
||||
addPath,
|
||||
deletePath,
|
||||
openApiStore,
|
||||
pathRegex,
|
||||
renamePath,
|
||||
sortPathsAlphabetically
|
||||
renamePath
|
||||
} from '$lib';
|
||||
import { getModalStore } from '@skeletonlabs/skeleton';
|
||||
const modalStore = getModalStore();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { blankSpec, openApiStore } from "$lib";
|
||||
import { blankSpec } from "$lib";
|
||||
import type { OpenAPIV3_1 } from "$lib/openAPITypes";
|
||||
import Dexie, { type Table } from 'dexie';
|
||||
import { writable, type Writable } from "svelte/store";
|
||||
@@ -8,12 +8,7 @@ export const newSpec: APISpec = {
|
||||
spec: blankSpec
|
||||
}
|
||||
|
||||
export const selectedSpec: Writable<APISpec | undefined> = writable(newSpec)
|
||||
|
||||
export const setSpec = (spec: APISpec) => {
|
||||
selectedSpec.set(spec);
|
||||
openApiStore.set(spec.spec);
|
||||
}
|
||||
export const selectedSpec: Writable<APISpec> = writable(newSpec)
|
||||
|
||||
export interface APISpec {
|
||||
id?: string;
|
||||
|
||||
@@ -61,8 +61,6 @@ export const pathCount = (openApiDoc: OpenAPIV3_1.Document) => {
|
||||
return count;
|
||||
};
|
||||
|
||||
export const openApiStore: Writable<OpenAPIV3_1.Document> = writable(blankSpec);
|
||||
|
||||
export enum HttpMethods {
|
||||
GET = 'get',
|
||||
PUT = 'put',
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { get } from 'svelte/store';
|
||||
import type { ModalSettings, ModalStore } from '@skeletonlabs/skeleton';
|
||||
import { pathTemplate } from './pathTemplate';
|
||||
import { openApiStore } from '$lib';
|
||||
import type { OpenAPIV3 } from './openAPITypes';
|
||||
import type { OpenAPIV3_1 } from './openAPITypes';
|
||||
import { selectedSpec } from './db';
|
||||
|
||||
export const pathVariables = /\{([^}]+)\}/gm;
|
||||
|
||||
@@ -39,9 +39,9 @@ export const addPath = (modalStore: ModalStore, startingPoint: string = '/') =>
|
||||
}
|
||||
|
||||
// create path object
|
||||
const store = get(openApiStore);
|
||||
if (!store.paths) store.paths = {};
|
||||
store.paths[userPath] = pathTemplate;
|
||||
const store = get(selectedSpec);
|
||||
if (!store.spec.paths) store.spec.paths = {};
|
||||
store.spec.paths[userPath] = pathTemplate;
|
||||
|
||||
// sort paths alphabetically
|
||||
sortPathsAlphabetically();
|
||||
@@ -80,16 +80,16 @@ export const renamePath = (modalStore: ModalStore, oldPath: string) => {
|
||||
}
|
||||
|
||||
// create path object
|
||||
const store = get(openApiStore);
|
||||
if (!store.paths) store.paths = {};
|
||||
const store = get(selectedSpec);
|
||||
if (!store.spec.paths) store.spec.paths = {};
|
||||
|
||||
// copy old path object to new path object
|
||||
store.paths[userPath] = store.paths[oldPath];
|
||||
store.spec.paths[userPath] = store.spec.paths[oldPath];
|
||||
// delete old path object
|
||||
delete store.paths[oldPath];
|
||||
delete store.spec.paths[oldPath];
|
||||
|
||||
// add path to store
|
||||
openApiStore.set(store);
|
||||
selectedSpec.set(store);
|
||||
|
||||
// sort paths alphabetically
|
||||
sortPathsAlphabetically();
|
||||
@@ -109,12 +109,12 @@ export const deletePath = (modalStore: ModalStore, path: string) => {
|
||||
// TRUE if confirm pressed, FALSE if cancel pressed
|
||||
response: (r: boolean) => {
|
||||
if (r === false) return;
|
||||
const store = get(openApiStore);
|
||||
const store = get(selectedSpec);
|
||||
// check if path exists
|
||||
if (!store.paths) return;
|
||||
if (!(path in store.paths)) return;
|
||||
delete store.paths[path];
|
||||
openApiStore.set(store);
|
||||
if (!store.spec.paths) return;
|
||||
if (!(path in store.spec.paths)) return;
|
||||
delete store.spec.paths[path];
|
||||
selectedSpec.set(store);
|
||||
}
|
||||
};
|
||||
modalStore.trigger(modal);
|
||||
@@ -122,8 +122,8 @@ export const deletePath = (modalStore: ModalStore, path: string) => {
|
||||
|
||||
/// checks if a given path already exists
|
||||
export const pathExists = (path: string) => {
|
||||
const store = get(openApiStore);
|
||||
return !(path in store.paths!);
|
||||
const store = get(selectedSpec);
|
||||
return !(path in store.spec.paths!);
|
||||
};
|
||||
|
||||
/// checks if a given path is valid
|
||||
@@ -148,7 +148,7 @@ export const isValidPath = (path: string) => {
|
||||
/// sorts the paths in the OpenAPI document alphabetically
|
||||
export const sortPathsAlphabetically = () => {
|
||||
const tempPathObject = {};
|
||||
const store = get(openApiStore);
|
||||
const store = get(selectedSpec);
|
||||
// @ts-expect-error - we are working with an initially empty object
|
||||
Object.keys(store.paths)
|
||||
.sort()
|
||||
@@ -158,8 +158,8 @@ export const sortPathsAlphabetically = () => {
|
||||
});
|
||||
|
||||
// update path object
|
||||
openApiStore.update((data) => {
|
||||
data.paths = tempPathObject;
|
||||
selectedSpec.update((data) => {
|
||||
data.spec.paths = tempPathObject;
|
||||
return data;
|
||||
});
|
||||
};
|
||||
@@ -171,7 +171,7 @@ export const getPathVariables = (path: string) => {
|
||||
return variables.map((variable) => variable.replace('{', '').replace('}', ''));
|
||||
};
|
||||
|
||||
export const sortPathParameters = (parameters: OpenAPIV3.ParameterObject[]) => {
|
||||
export const sortPathParameters = (parameters: OpenAPIV3_1.ParameterObject[]) => {
|
||||
const tempParameters = parameters;
|
||||
tempParameters.sort((a, b) => {
|
||||
if (a.in < b.in) return -1;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import { blankSpec } from '$lib';
|
||||
import type { OpenAPIV3_1 } from 'openapi-types';
|
||||
import { type Writable, writable, get } from 'svelte/store';
|
||||
|
||||
const store: Writable<OpenAPIV3_1.Document> = writable(blankSpec);
|
||||
|
||||
/// A store that also persists to the indexedDB
|
||||
export const openApiStore: Writable<OpenAPIV3_1.Document> = {
|
||||
...store,
|
||||
set: (value: OpenAPIV3_1.Document) => {
|
||||
// TODO: update the database with the new value
|
||||
store.set(value);
|
||||
},
|
||||
update: (updater: (value: OpenAPIV3_1.Document) => OpenAPIV3_1.Document) => {
|
||||
store.update(updater);
|
||||
const updatedValue = get(store);
|
||||
// TODO: update the database with the updated value
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user