2022-01-18 15:27:10 +02:00
|
|
|
import { refs, MinimumSchema } from '@/misc/schema';
|
2019-04-23 16:35:26 +03:00
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
export function convertSchemaToOpenApiSchema(schema: MinimumSchema) {
|
2019-04-23 16:35:26 +03:00
|
|
|
const res: any = schema;
|
|
|
|
|
|
|
|
if (schema.type === 'object' && schema.properties) {
|
2019-05-05 03:27:55 +03:00
|
|
|
res.required = Object.entries(schema.properties).filter(([k, v]) => !v.optional).map(([k]) => k);
|
2019-04-23 16:35:26 +03:00
|
|
|
|
|
|
|
for (const k of Object.keys(schema.properties)) {
|
|
|
|
res.properties[k] = convertSchemaToOpenApiSchema(schema.properties[k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (schema.type === 'array' && schema.items) {
|
|
|
|
res.items = convertSchemaToOpenApiSchema(schema.items);
|
|
|
|
}
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
if (schema.anyOf) res.anyOf = schema.anyOf.map(convertSchemaToOpenApiSchema);
|
|
|
|
if (schema.oneOf) res.oneOf = schema.oneOf.map(convertSchemaToOpenApiSchema);
|
|
|
|
if (schema.allOf) res.allOf = schema.allOf.map(convertSchemaToOpenApiSchema);
|
|
|
|
|
2019-04-23 16:35:26 +03:00
|
|
|
if (schema.ref) {
|
|
|
|
res.$ref = `#/components/schemas/${schema.ref}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-02-23 21:08:08 +02:00
|
|
|
export const schemas = {
|
|
|
|
Error: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
error: {
|
|
|
|
type: 'object',
|
|
|
|
description: 'An error object.',
|
|
|
|
properties: {
|
|
|
|
code: {
|
|
|
|
type: 'string',
|
2019-02-23 21:27:09 +02:00
|
|
|
description: 'An error code. Unique within the endpoint.',
|
2019-02-23 21:08:08 +02:00
|
|
|
},
|
|
|
|
message: {
|
|
|
|
type: 'string',
|
|
|
|
description: 'An error message.',
|
|
|
|
},
|
|
|
|
id: {
|
|
|
|
type: 'string',
|
|
|
|
format: 'uuid',
|
|
|
|
description: 'An error ID. This ID is static.',
|
2021-12-09 16:58:30 +02:00
|
|
|
},
|
2019-02-23 21:08:08 +02:00
|
|
|
},
|
2021-12-09 16:58:30 +02:00
|
|
|
required: ['code', 'id', 'message'],
|
2019-02-23 21:08:08 +02:00
|
|
|
},
|
|
|
|
},
|
2021-12-09 16:58:30 +02:00
|
|
|
required: ['error'],
|
2019-02-23 21:08:08 +02:00
|
|
|
},
|
|
|
|
|
2021-09-11 19:12:23 +03:00
|
|
|
...Object.fromEntries(
|
|
|
|
Object.entries(refs).map(([key, schema]) => [key, convertSchemaToOpenApiSchema(schema)])
|
|
|
|
),
|
2019-02-23 21:08:08 +02:00
|
|
|
};
|