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 diff --git a/src/lib/utils/specs.ts b/src/lib/utils/specs.ts index 32a5db42e7..99b4184641 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.properties)) { 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 { @@ -228,7 +230,7 @@ export async function getService( 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];