mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-07 21:07:44 +00:00
fix: less error prone references
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import type { Language } from './code';
|
import type { Language } from './code';
|
||||||
|
|
||||||
export const versions = ['1.4.x', '1.3.x'];
|
export const versions = ['1.4.x', '1.3.x', '1.2.x', '1.1.x', '1.0.x'];
|
||||||
|
|
||||||
export enum Service {
|
export enum Service {
|
||||||
Account = 'account',
|
Account = 'account',
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import SwaggerParser from '@apidevtools/swagger-parser';
|
import SwaggerParser from '@apidevtools/swagger-parser';
|
||||||
import { error } from '@sveltejs/kit';
|
|
||||||
import { OpenAPIV3 } from 'openapi-types';
|
import { OpenAPIV3 } from 'openapi-types';
|
||||||
|
|
||||||
type SDKMethod = {
|
type SDKMethod = {
|
||||||
@@ -47,15 +46,25 @@ type AppwriteSchemaObject = OpenAPIV3.SchemaObject & {
|
|||||||
|
|
||||||
function getExamples(version: string) {
|
function getExamples(version: string) {
|
||||||
switch (version) {
|
switch (version) {
|
||||||
|
case '1.0.x':
|
||||||
|
return import.meta.glob('$appwrite/docs/examples/1.0.x/**/*.md', {
|
||||||
|
as: 'raw'
|
||||||
|
});
|
||||||
|
case '1.1.x':
|
||||||
|
return import.meta.glob('$appwrite/docs/examples/1.1.x/**/*.md', {
|
||||||
|
as: 'raw'
|
||||||
|
});
|
||||||
|
case '1.2.x':
|
||||||
|
return import.meta.glob('$appwrite/docs/examples/1.2.x/**/*.md', {
|
||||||
|
as: 'raw'
|
||||||
|
});
|
||||||
case '1.3.x':
|
case '1.3.x':
|
||||||
return import.meta.glob('$appwrite/docs/examples/1.3.x/**/*.md', {
|
return import.meta.glob('$appwrite/docs/examples/1.3.x/**/*.md', {
|
||||||
as: 'raw',
|
as: 'raw'
|
||||||
eager: true
|
|
||||||
});
|
});
|
||||||
case '1.4.x':
|
case '1.4.x':
|
||||||
return import.meta.glob('$appwrite/docs/examples/1.4.x/**/*.md', {
|
return import.meta.glob('$appwrite/docs/examples/1.4.x/**/*.md', {
|
||||||
as: 'raw',
|
as: 'raw'
|
||||||
eager: true
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,10 +157,6 @@ export async function getService(
|
|||||||
methods: SDKMethod[];
|
methods: SDKMethod[];
|
||||||
}> {
|
}> {
|
||||||
const spec = await getSpec(version, platform);
|
const spec = await getSpec(version, platform);
|
||||||
const examples = getExamples(version);
|
|
||||||
if (!examples) {
|
|
||||||
throw error(404, "Examples doesn't exist");
|
|
||||||
}
|
|
||||||
const data: {
|
const data: {
|
||||||
service: {
|
service: {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -174,6 +179,12 @@ export async function getService(
|
|||||||
description: tag?.description ?? ''
|
description: tag?.description ?? ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const examples = getExamples(version);
|
||||||
|
|
||||||
|
if (!examples) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
for (const [method, value] of iterateAllMethods(api, service)) {
|
for (const [method, value] of iterateAllMethods(api, service)) {
|
||||||
const operation = value as AppwriteOperationObject;
|
const operation = value as AppwriteOperationObject;
|
||||||
const parameters = getParameters(method, operation);
|
const parameters = getParameters(method, operation);
|
||||||
@@ -202,11 +213,11 @@ export async function getService(
|
|||||||
|
|
||||||
const path = `/node_modules/appwrite/docs/examples/${version}/${platform}/examples/${operation['x-appwrite'].demo}`;
|
const path = `/node_modules/appwrite/docs/examples/${version}/${platform}/examples/${operation['x-appwrite'].demo}`;
|
||||||
if (!(path in examples)) {
|
if (!(path in examples)) {
|
||||||
throw error(404, "Example doesn't exist: " + path);
|
continue;
|
||||||
}
|
}
|
||||||
data.methods.push({
|
data.methods.push({
|
||||||
id: operation['x-appwrite'].method,
|
id: operation['x-appwrite'].method,
|
||||||
demo: examples[path],
|
demo: await examples[path](),
|
||||||
title: operation.summary ?? '',
|
title: operation.summary ?? '',
|
||||||
description: operation.description ?? '',
|
description: operation.description ?? '',
|
||||||
parameters: parameters ?? [],
|
parameters: parameters ?? [],
|
||||||
|
|||||||
Reference in New Issue
Block a user