Skip to content

Commit

Permalink
Merge pull request #193 from appwrite/fix-references-params-order
Browse files Browse the repository at this point in the history
fix: param orders in references
  • Loading branch information
TorstenDittmann authored Oct 4, 2023
2 parents 1aad981 + 74668ca commit 8beca86
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions src/lib/utils/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ function* iterateAllMethods(
}

function getParameters(
method: OpenAPIV3.HttpMethods,
operation: AppwriteOperationObject
): SDKMethod['parameters'] {
const parameters: ReturnType<typeof getParameters> = [];
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({
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 8beca86

Please sign in to comment.