Skip to content

Commit 8beca86

Browse files
Merge pull request #193 from appwrite/fix-references-params-order
fix: param orders in references
2 parents 1aad981 + 74668ca commit 8beca86

3 files changed

Lines changed: 20 additions & 18 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"sharp": "^0.32.6",
3838
"svelte": "^4.2.0",
3939
"svelte-check": "^3.5.1",
40-
"svelte-markdoc-preprocess": "^1.0.0",
40+
"svelte-markdoc-preprocess": "^1.1.0",
4141
"svelte-sequential-preprocessor": "^2.0.1",
4242
"svgo": "^3.0.2",
4343
"svgtofont": "^4.0.0",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/utils/specs.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ function* iterateAllMethods(
100100
}
101101

102102
function getParameters(
103-
method: OpenAPIV3.HttpMethods,
104103
operation: AppwriteOperationObject
105104
): SDKMethod['parameters'] {
106105
const parameters: ReturnType<typeof getParameters> = [];
107-
if (method === OpenAPIV3.HttpMethods.GET) {
108-
for (const parameter of (operation?.parameters as OpenAPIV3.ParameterObject[]) ?? []) {
106+
const requestBody = operation?.requestBody as OpenAPIV3.RequestBodyObject;
107+
const schemaJson = requestBody?.content['application/json']?.schema as OpenAPIV3.SchemaObject;
108+
const schemaMultipart = requestBody?.content['multipart/form-data']?.schema as OpenAPIV3.SchemaObject;
109+
if (operation?.parameters) {
110+
for (const parameter of (operation?.parameters as OpenAPIV3.ParameterObject[])) {
109111
const schema = parameter.schema as OpenAPIV3.SchemaObject;
110112

111113
parameters.push({
@@ -116,13 +118,9 @@ function getParameters(
116118
example: schema?.example
117119
});
118120
}
119-
} else {
120-
const requestBody = operation?.requestBody as OpenAPIV3.RequestBodyObject;
121-
const schemaJson = requestBody?.content['application/json']?.schema as OpenAPIV3.SchemaObject;
122-
const schemaMultipart = requestBody?.content['multipart/form-data']?.schema as OpenAPIV3.SchemaObject;
123-
124-
// TODO: make this pretty
125-
for (const [key, value] of Object.entries(schemaJson?.properties ?? {})) {
121+
}
122+
if (schemaJson?.properties) {
123+
for (const [key, value] of Object.entries(schemaJson.properties)) {
126124
const property = value as AppwriteSchemaObject;
127125
parameters.push({
128126
name: key,
@@ -132,7 +130,9 @@ function getParameters(
132130
example: property['x-example'] ?? ''
133131
});
134132
}
135-
for (const [key, value] of Object.entries(schemaMultipart?.properties ?? {})) {
133+
}
134+
if (schemaMultipart?.properties) {
135+
for (const [key, value] of Object.entries(schemaMultipart.properties)) {
136136
const property = value as AppwriteSchemaObject;
137137
parameters.push({
138138
name: key,
@@ -144,7 +144,9 @@ function getParameters(
144144
}
145145
}
146146

147-
return parameters;
147+
return parameters.sort((a, b) => {
148+
return (a.required === b.required) ? 0 : a.required ? -1 : 1;
149+
});
148150
}
149151

150152
export function getSchema(id: string, api: OpenAPIV3.Document): OpenAPIV3.SchemaObject {
@@ -228,7 +230,7 @@ export async function getService(
228230

229231
for (const [method, value] of iterateAllMethods(api, service)) {
230232
const operation = value as AppwriteOperationObject;
231-
const parameters = getParameters(method, operation);
233+
const parameters = getParameters(operation);
232234
const responses: SDKMethod['responses'] = Object.entries(operation.responses ?? {}).map(
233235
(tuple) => {
234236
const [code, response] = tuple as [string, OpenAPIV3.ResponseObject];

0 commit comments

Comments
 (0)