mirror of
https://github.com/LukeHagar/OpenAPI.gg.git
synced 2025-12-07 12:37:46 +00:00
a few small changes, fixed a bug.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { localStoragePrefix } from '$lib';
|
import { localStoragePrefix, newSpec } from '$lib';
|
||||||
|
import { setSpec } from '$lib/db';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -10,10 +11,9 @@
|
|||||||
'This operation clears all the current values, unsaved data will be lost, are you sure?'
|
'This operation clears all the current values, unsaved data will be lost, are you sure?'
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// remove `openApi` from localStorage
|
setSpec(newSpec);
|
||||||
localStorage.removeItem(`${localStoragePrefix}openApi`);
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Create New
|
New
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { db, type APISpec } from '$lib/db';
|
import { newSpec } from '$lib';
|
||||||
|
import { db, setSpec, type APISpec } from '$lib/db';
|
||||||
|
|
||||||
export let spec: APISpec;
|
export let spec: APISpec;
|
||||||
</script>
|
</script>
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
if (confirm(`Are you sure you want to delete '${spec.name}'?`)) {
|
if (confirm(`Are you sure you want to delete '${spec.name}'?`)) {
|
||||||
await db.apiSpecs.delete(spec.id);
|
await db.apiSpecs.delete(spec.id);
|
||||||
|
setSpec(newSpec);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -11,8 +11,9 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log($selectedSpec);
|
console.log($selectedSpec);
|
||||||
$selectedSpec.id = undefined;
|
const newSpec = structuredClone($selectedSpec);
|
||||||
db.apiSpecs.put($selectedSpec);
|
newSpec.id = undefined;
|
||||||
|
db.apiSpecs.put(newSpec);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,10 @@
|
|||||||
|
import type { APISpec } from './db';
|
||||||
import type { OpenAPIV3_1 } from './openAPITypes';
|
import type { OpenAPIV3_1 } from './openAPITypes';
|
||||||
import { writable, type Writable } from 'svelte/store';
|
import { writable, type Writable } from 'svelte/store';
|
||||||
|
|
||||||
export const localStoragePrefix = 'openapigen-';
|
export const localStoragePrefix = 'openapigen-';
|
||||||
|
|
||||||
export const operationCount = (openApiDoc: OpenAPIV3_1.Document) => {
|
export const blankSpec: OpenAPIV3_1.Document = {
|
||||||
let count = 0;
|
|
||||||
for (const path in openApiDoc.paths) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
for (const method in openApiDoc.paths[path]) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const pathCount = (openApiDoc: OpenAPIV3_1.Document) => {
|
|
||||||
let count = 0;
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
for (const path in openApiDoc.paths) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const openApiStore: Writable<OpenAPIV3_1.Document> = writable({
|
|
||||||
openapi: '3.1.0', // OpenAPI version
|
openapi: '3.1.0', // OpenAPI version
|
||||||
info: {
|
info: {
|
||||||
/** Title of the API (required) */
|
/** Title of the API (required) */
|
||||||
@@ -58,7 +38,35 @@ export const openApiStore: Writable<OpenAPIV3_1.Document> = writable({
|
|||||||
description: '',
|
description: '',
|
||||||
url: ''
|
url: ''
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
export const newSpec: APISpec = {
|
||||||
|
name: 'OpenAPI',
|
||||||
|
spec: blankSpec
|
||||||
|
}
|
||||||
|
|
||||||
|
export const operationCount = (openApiDoc: OpenAPIV3_1.Document) => {
|
||||||
|
let count = 0;
|
||||||
|
for (const path in openApiDoc.paths) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
for (const method in openApiDoc.paths[path]) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const pathCount = (openApiDoc: OpenAPIV3_1.Document) => {
|
||||||
|
let count = 0;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
for (const path in openApiDoc.paths) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const openApiStore: Writable<OpenAPIV3_1.Document> = writable(blankSpec);
|
||||||
|
|
||||||
export enum HttpMethods {
|
export enum HttpMethods {
|
||||||
GET = 'get',
|
GET = 'get',
|
||||||
|
|||||||
Reference in New Issue
Block a user