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