Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/lib/utils/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function getExamples(version: string) {
import: 'default'
});
case '1.7.x':
case 'latest':
return import.meta.glob('$appwrite/docs/examples/1.7.x/**/*.md', {
query: '?raw',
import: 'default'
Expand Down Expand Up @@ -248,6 +249,21 @@ export async function getDescription(service: string) {
return descriptions[target]() as unknown as string;
}

function getContentTypeDescription(content: Record<string, any>): string {
const contentType = Object.keys(content)[0];

if (contentType === '*/*') {
const mediaTypeObject = content[contentType];
const schema = mediaTypeObject?.schema as OpenAPIV3.SchemaObject;

if (schema?.type === 'string' && schema?.format === 'binary') {
return 'application/gzip';
}
}

return contentType;
}

export async function getService(
version: string,
platform: string,
Expand Down Expand Up @@ -319,17 +335,18 @@ export async function getService(

return {
code: Number(code),
contentType: response?.content ? Object.keys(response.content)[0] : undefined,
contentType: response?.content ? getContentTypeDescription(response.content) : undefined,
models
};
}
);

const exampleVersion = version === 'latest' ? '1.7.x' : version;
const path = isAndroid
? `/node_modules/@appwrite.io/repo/docs/examples/${version}/${
? `/node_modules/@appwrite.io/repo/docs/examples/${exampleVersion}/${
isAndroidServer ? 'server-kotlin' : 'client-android'
}/${isAndroidJava ? 'java' : 'kotlin'}/${operation['x-appwrite'].demo}`
: `/node_modules/@appwrite.io/repo/docs/examples/${version}/${platform}/examples/${operation['x-appwrite'].demo}`;
: `/node_modules/@appwrite.io/repo/docs/examples/${exampleVersion}/${platform}/examples/${operation['x-appwrite'].demo}`;
if (!(path in examples)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export const entries: EntryGenerator = () => {

export const load: PageServerLoad = async ({ params }) => {
const { platform, service } = params;
const version = params.version === 'cloud' ? '1.7.x' : params.version;

if (!versions.includes(version)) error(404, 'Invalid version');

// Validate original params.version
if (params.version !== 'cloud' && !versions.includes(params.version)) error(404, 'Invalid version');
if (!platforms.includes(platform as Platform)) error(404, 'Invalid platform');
if (!services.includes(service as ServiceValue)) error(404, 'Invalid service');

// Convert cloud to latest after validation
const version = params.version === 'cloud' ? 'latest' : params.version;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

latest alias will 404 with current validation.

Validation rejects anything not in versions unless it’s cloud. If links now resolve to /latest/… (see models route), this will 404. Either allow latest as an alias here or keep URLs on /cloud/.

🔧 Example fix (accept `latest`)
-    if (params.version !== 'cloud' && !versions.includes(params.version)) error(404, 'Invalid version');
+    const isAlias = params.version === 'cloud' || params.version === 'latest';
+    if (!isAlias && !versions.includes(params.version)) error(404, 'Invalid version');
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Validate original params.version
if (params.version !== 'cloud' && !versions.includes(params.version)) error(404, 'Invalid version');
if (!platforms.includes(platform as Platform)) error(404, 'Invalid platform');
if (!services.includes(service as ServiceValue)) error(404, 'Invalid service');
// Convert cloud to latest after validation
const version = params.version === 'cloud' ? 'latest' : params.version;
// Validate original params.version
const isAlias = params.version === 'cloud' || params.version === 'latest';
if (!isAlias && !versions.includes(params.version)) error(404, 'Invalid version');
if (!platforms.includes(platform as Platform)) error(404, 'Invalid platform');
if (!services.includes(service as ServiceValue)) error(404, 'Invalid service');
// Convert cloud to latest after validation
const version = params.version === 'cloud' ? 'latest' : params.version;
🤖 Prompt for AI Agents
In `@src/routes/docs/references/`[version]/[platform]/[service]/+page.server.ts
around lines 22 - 28, The validation currently rejects params.version values not
in versions unless it's 'cloud', so requests using the 'latest' alias will 404;
update the guard in +page.server.ts to accept 'latest' as valid by allowing
params.version === 'latest' (or treat it the same as 'cloud') when checking
against versions before converting params.version into the local const version
(used later), i.e., adjust the first validation that references params.version
and versions so it permits 'cloud' OR 'latest' (while keeping subsequent
conversion: const version = params.version === 'cloud' ? 'latest' :
params.version).

return getService(version, platform, service);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Model = {
};

export const load: PageServerLoad = async ({ params }) => {
const version = params.version === 'cloud' ? '1.7.x' : params.version;
const version = params.version === 'cloud' ? 'latest' : params.version;
const api = await getApi(version, 'console-web');
const schema = getSchema(params.model, api);
const props = Object.entries(schema.properties ?? {});
Expand Down