Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: param orders in references #193

Merged
merged 7 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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