2023-03-10 05:22:37 +00:00
|
|
|
import type { Schema } from '@/misc/json-schema.js';
|
|
|
|
import { refs } from '@/misc/json-schema.js';
|
2019-04-23 13:35:26 +00:00
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
export function convertSchemaToOpenApiSchema(schema: Schema) {
|
2019-04-23 13:35:26 +00:00
|
|
|
const res: any = schema;
|
|
|
|
|
|
|
|
if (schema.type === 'object' && schema.properties) {
|
2019-05-05 00:27:55 +00:00
|
|
|
res.required = Object.entries(schema.properties).filter(([k, v]) => !v.optional).map(([k]) => k);
|
2019-04-23 13:35:26 +00: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 13:27:10 +00: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 13:35:26 +00:00
|
|
|
if (schema.ref) {
|
|
|
|
res.$ref = `#/components/schemas/${schema.ref}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-02-23 19:08:08 +00:00
|
|
|
export const schemas = {
|
|
|
|
Error: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
error: {
|
|
|
|
type: 'object',
|
|
|
|
description: 'An error object.',
|
|
|
|
properties: {
|
|
|
|
code: {
|
|
|
|
type: 'string',
|
2019-02-23 19:27:09 +00:00
|
|
|
description: 'An error code. Unique within the endpoint.',
|
2019-02-23 19:08:08 +00:00
|
|
|
},
|
|
|
|
message: {
|
|
|
|
type: 'string',
|
|
|
|
description: 'An error message.',
|
|
|
|
},
|
|
|
|
id: {
|
|
|
|
type: 'string',
|
|
|
|
format: 'uuid',
|
|
|
|
description: 'An error ID. This ID is static.',
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2019-02-23 19:08:08 +00:00
|
|
|
},
|
2021-12-09 14:58:30 +00:00
|
|
|
required: ['code', 'id', 'message'],
|
2019-02-23 19:08:08 +00:00
|
|
|
},
|
|
|
|
},
|
2021-12-09 14:58:30 +00:00
|
|
|
required: ['error'],
|
2019-02-23 19:08:08 +00:00
|
|
|
},
|
|
|
|
|
2021-09-11 16:12:23 +00:00
|
|
|
...Object.fromEntries(
|
2022-09-19 20:32:18 +00:00
|
|
|
Object.entries(refs).map(([key, schema]) => [key, convertSchemaToOpenApiSchema(schema)]),
|
2021-09-11 16:12:23 +00:00
|
|
|
),
|
2019-02-23 19:08:08 +00:00
|
|
|
};
|