From 2dbdac1d06a9ec441be462e35cd4845c7b0d1504 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 4 Oct 2023 16:05:48 +0200 Subject: [PATCH 1/7] chore: update markdoc preprocessor --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 355580f18e..f403f6aa60 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "sharp": "^0.32.6", "svelte": "^4.2.0", "svelte-check": "^3.5.1", - "svelte-markdoc-preprocess": "^1.0.0", + "svelte-markdoc-preprocess": "^1.1.0", "svelte-sequential-preprocessor": "^2.0.1", "svgo": "^3.0.2", "svgtofont": "^4.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eeb62719d3..1440c26efc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -101,8 +101,8 @@ devDependencies: specifier: ^3.5.1 version: 3.5.1(postcss@8.4.27)(sass@1.66.1)(svelte@4.2.0) svelte-markdoc-preprocess: - specifier: ^1.0.0 - version: 1.0.0 + specifier: ^1.1.0 + version: 1.1.0 svelte-sequential-preprocessor: specifier: ^2.0.1 version: 2.0.1 @@ -4797,8 +4797,8 @@ packages: svelte: 4.2.0 dev: true - /svelte-markdoc-preprocess@1.0.0: - resolution: {integrity: sha512-vFYqUXuX0ONHeZhn0MTplS22CKsidhLAoHfX5OceX8rhmKWyKwg/R579iYNb/RDW7OyLA5UU9UCLdNhEoQ5s/w==} + /svelte-markdoc-preprocess@1.1.0: + resolution: {integrity: sha512-/FSCXZYgWHPLLbekWovwwVLgEoEYdBxCiLKOXu5wVbwK2iR29+Z/qL+u6/ngya0pYoC1l8IO6UUXjYgAWi1kTA==} dependencies: '@markdoc/markdoc': 0.3.2 html-escaper: 3.0.3 From cd307adfb816e625190d7d91ac4dfc1d0acd6ecd Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 4 Oct 2023 16:05:55 +0200 Subject: [PATCH 2/7] fix: sorting of params --- src/lib/utils/specs.ts | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/lib/utils/specs.ts b/src/lib/utils/specs.ts index 32a5db42e7..7e0109ed1f 100644 --- a/src/lib/utils/specs.ts +++ b/src/lib/utils/specs.ts @@ -100,12 +100,14 @@ function* iterateAllMethods( } function getParameters( - method: OpenAPIV3.HttpMethods, operation: AppwriteOperationObject ): SDKMethod['parameters'] { const parameters: ReturnType = []; - if (method === OpenAPIV3.HttpMethods.GET) { - for (const parameter of (operation?.parameters as OpenAPIV3.ParameterObject[]) ?? []) { + const requestBody = operation?.requestBody as OpenAPIV3.RequestBodyObject; + const schemaJson = requestBody?.content['application/json']?.schema as OpenAPIV3.SchemaObject; + const schemaMultipart = requestBody?.content['multipart/form-data']?.schema as OpenAPIV3.SchemaObject; + if (operation?.parameters) { + for (const parameter of (operation?.parameters as OpenAPIV3.ParameterObject[])) { const schema = parameter.schema as OpenAPIV3.SchemaObject; parameters.push({ @@ -116,13 +118,9 @@ function getParameters( example: schema?.example }); } - } else { - const requestBody = operation?.requestBody as OpenAPIV3.RequestBodyObject; - const schemaJson = requestBody?.content['application/json']?.schema as OpenAPIV3.SchemaObject; - const schemaMultipart = requestBody?.content['multipart/form-data']?.schema as OpenAPIV3.SchemaObject; - - // TODO: make this pretty - for (const [key, value] of Object.entries(schemaJson?.properties ?? {})) { + } + if (schemaJson?.properties) { + for (const [key, value] of Object.entries(schemaJson.properties)) { const property = value as AppwriteSchemaObject; parameters.push({ name: key, @@ -132,7 +130,9 @@ function getParameters( example: property['x-example'] ?? '' }); } - for (const [key, value] of Object.entries(schemaMultipart?.properties ?? {})) { + } + if (schemaMultipart?.properties) { + for (const [key, value] of Object.entries(schemaMultipart)) { const property = value as AppwriteSchemaObject; parameters.push({ name: key, @@ -144,7 +144,9 @@ function getParameters( } } - return parameters; + return parameters.sort((a, b) => { + return (a.required === b.required) ? 0 : a.required ? -1 : 1; + }); } export function getSchema(id: string, api: OpenAPIV3.Document): OpenAPIV3.SchemaObject { @@ -164,9 +166,8 @@ const specs = import.meta.glob( async function getSpec(version: string, platform: string) { const isClient = platform.startsWith('client-'); const isServer = platform.startsWith('server-'); - const target = `/node_modules/@appwrite.io/repo/app/config/specs/open-api3-${version}-${ - isServer ? 'server' : isClient ? 'client' : 'console' - }.json`; + const target = `/node_modules/@appwrite.io/repo/app/config/specs/open-api3-${version}-${isServer ? 'server' : isClient ? 'client' : 'console' + }.json`; return specs[target](); } @@ -226,9 +227,9 @@ export async function getService( return data; } - for (const [method, value] of iterateAllMethods(api, service)) { + for (const [_method, value] of iterateAllMethods(api, service)) { const operation = value as AppwriteOperationObject; - const parameters = getParameters(method, operation); + const parameters = getParameters(operation); const responses: SDKMethod['responses'] = Object.entries(operation.responses ?? {}).map( (tuple) => { const [code, response] = tuple as [string, OpenAPIV3.ResponseObject]; @@ -264,13 +265,14 @@ export async function getService( ); const path = isAndroid - ? `/node_modules/@appwrite.io/repo/docs/examples/${version}/client-android/${ - isAndroidJava ? 'java' : 'kotlin' - }/${operation['x-appwrite'].demo}` + ? `/node_modules/@appwrite.io/repo/docs/examples/${version}/client-android/${isAndroidJava ? 'java' : 'kotlin' + }/${operation['x-appwrite'].demo}` : `/node_modules/@appwrite.io/repo/docs/examples/${version}/${platform}/examples/${operation['x-appwrite'].demo}`; + if (!(path in examples)) { continue; } + data.methods.push({ id: operation['x-appwrite'].method, demo: await examples[path](), From 892acff031097d11adfcde9e16569fcad65c36a6 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 4 Oct 2023 16:09:13 +0200 Subject: [PATCH 3/7] chore: revert whitespace changes --- src/lib/utils/specs.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/lib/utils/specs.ts b/src/lib/utils/specs.ts index 7e0109ed1f..d21e1110a3 100644 --- a/src/lib/utils/specs.ts +++ b/src/lib/utils/specs.ts @@ -166,8 +166,9 @@ const specs = import.meta.glob( async function getSpec(version: string, platform: string) { const isClient = platform.startsWith('client-'); const isServer = platform.startsWith('server-'); - const target = `/node_modules/@appwrite.io/repo/app/config/specs/open-api3-${version}-${isServer ? 'server' : isClient ? 'client' : 'console' - }.json`; + const target = `/node_modules/@appwrite.io/repo/app/config/specs/open-api3-${version}-${ + isServer ? 'server' : isClient ? 'client' : 'console' + }.json`; return specs[target](); } @@ -227,7 +228,7 @@ export async function getService( return data; } - for (const [_method, value] of iterateAllMethods(api, service)) { + for (const [method, value] of iterateAllMethods(api, service)) { const operation = value as AppwriteOperationObject; const parameters = getParameters(operation); const responses: SDKMethod['responses'] = Object.entries(operation.responses ?? {}).map( @@ -265,10 +266,10 @@ export async function getService( ); const path = isAndroid - ? `/node_modules/@appwrite.io/repo/docs/examples/${version}/client-android/${isAndroidJava ? 'java' : 'kotlin' - }/${operation['x-appwrite'].demo}` + ? `/node_modules/@appwrite.io/repo/docs/examples/${version}/client-android/${ + isAndroidJava ? 'java' : 'kotlin' + }/${operation['x-appwrite'].demo}` : `/node_modules/@appwrite.io/repo/docs/examples/${version}/${platform}/examples/${operation['x-appwrite'].demo}`; - if (!(path in examples)) { continue; } From 717e6f4d44fe513a8c11d4a1acd0f4bc47c65dda Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 4 Oct 2023 16:10:40 +0200 Subject: [PATCH 4/7] revert: whitespace changes --- src/lib/utils/specs.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/utils/specs.ts b/src/lib/utils/specs.ts index d21e1110a3..a6e3bf3590 100644 --- a/src/lib/utils/specs.ts +++ b/src/lib/utils/specs.ts @@ -166,7 +166,7 @@ const specs = import.meta.glob( async function getSpec(version: string, platform: string) { const isClient = platform.startsWith('client-'); const isServer = platform.startsWith('server-'); - const target = `/node_modules/@appwrite.io/repo/app/config/specs/open-api3-${version}-${ + const target = `/node_modules/@appwrite.io/repo/app/config/specs/open-api3-${version}-${ isServer ? 'server' : isClient ? 'client' : 'console' }.json`; return specs[target](); @@ -273,7 +273,6 @@ export async function getService( if (!(path in examples)) { continue; } - data.methods.push({ id: operation['x-appwrite'].method, demo: await examples[path](), From 5d5c32e1087768e9583a4c4277d10e049e0863f4 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 4 Oct 2023 16:21:09 +0200 Subject: [PATCH 5/7] fix: bug with multipart --- src/lib/utils/specs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/utils/specs.ts b/src/lib/utils/specs.ts index a6e3bf3590..bfb4162eb5 100644 --- a/src/lib/utils/specs.ts +++ b/src/lib/utils/specs.ts @@ -131,7 +131,7 @@ function getParameters( }); } } - if (schemaMultipart?.properties) { + if (schemaMultipart) { for (const [key, value] of Object.entries(schemaMultipart)) { const property = value as AppwriteSchemaObject; parameters.push({ From 60f8437caee995a648907196d368406fd1f6fbd1 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 4 Oct 2023 16:23:21 +0200 Subject: [PATCH 6/7] fix: multipart references --- src/lib/utils/specs.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/utils/specs.ts b/src/lib/utils/specs.ts index bfb4162eb5..ab3ffe709f 100644 --- a/src/lib/utils/specs.ts +++ b/src/lib/utils/specs.ts @@ -106,6 +106,9 @@ function getParameters( const requestBody = operation?.requestBody as OpenAPIV3.RequestBodyObject; const schemaJson = requestBody?.content['application/json']?.schema as OpenAPIV3.SchemaObject; const schemaMultipart = requestBody?.content['multipart/form-data']?.schema as OpenAPIV3.SchemaObject; + if (operation.operationId === 'storageCreateFile') { + console.log(schemaMultipart) + } if (operation?.parameters) { for (const parameter of (operation?.parameters as OpenAPIV3.ParameterObject[])) { const schema = parameter.schema as OpenAPIV3.SchemaObject; @@ -131,8 +134,8 @@ function getParameters( }); } } - if (schemaMultipart) { - for (const [key, value] of Object.entries(schemaMultipart)) { + if (schemaMultipart?.properties) { + for (const [key, value] of Object.entries(schemaMultipart.properties)) { const property = value as AppwriteSchemaObject; parameters.push({ name: key, From 74668cab8454566986491293d27aba007f8e185e Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 4 Oct 2023 16:23:34 +0200 Subject: [PATCH 7/7] revert: console.log --- src/lib/utils/specs.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib/utils/specs.ts b/src/lib/utils/specs.ts index ab3ffe709f..99b4184641 100644 --- a/src/lib/utils/specs.ts +++ b/src/lib/utils/specs.ts @@ -106,9 +106,6 @@ function getParameters( const requestBody = operation?.requestBody as OpenAPIV3.RequestBodyObject; const schemaJson = requestBody?.content['application/json']?.schema as OpenAPIV3.SchemaObject; const schemaMultipart = requestBody?.content['multipart/form-data']?.schema as OpenAPIV3.SchemaObject; - if (operation.operationId === 'storageCreateFile') { - console.log(schemaMultipart) - } if (operation?.parameters) { for (const parameter of (operation?.parameters as OpenAPIV3.ParameterObject[])) { const schema = parameter.schema as OpenAPIV3.SchemaObject;