summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/openapi
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-02-19 14:05:32 +0900
committerGitHub <noreply@github.com>2022-02-19 14:05:32 +0900
commit510de87607283d4d49239b1d14026a577299c99e (patch)
treed56933864d6cf07751e2e2a11a373ee752338c80 /packages/backend/src/server/api/openapi
parentupdate deps (diff)
downloadsharkey-510de87607283d4d49239b1d14026a577299c99e.tar.gz
sharkey-510de87607283d4d49239b1d14026a577299c99e.tar.bz2
sharkey-510de87607283d4d49239b1d14026a577299c99e.zip
refactor: use ajv instead of cafy (#8324)
* wip * wip * Update abuse-user-reports.ts * Update files.ts * Update list-remote.ts * Update list.ts * Update show-users.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * Update search.ts * Update reactions.ts * Update search.ts * wip * wip * wip * wip * Update update.ts * Update relation.ts * Update available.ts * wip * wip * wip * Update packages/backend/src/server/api/define.ts Co-authored-by: Johann150 <johann.galle@protonmail.com> * Update define.ts * Update define.ts * typo * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * wip * Update signup.ts * Update call.ts * minimum for limit * type * remove needless annotation * wip * Update signup.ts * wip * wip * fix * Update create.ts Co-authored-by: Johann150 <johann.galle@protonmail.com>
Diffstat (limited to 'packages/backend/src/server/api/openapi')
-rw-r--r--packages/backend/src/server/api/openapi/gen-spec.ts61
-rw-r--r--packages/backend/src/server/api/openapi/schemas.ts4
2 files changed, 4 insertions, 61 deletions
diff --git a/packages/backend/src/server/api/openapi/gen-spec.ts b/packages/backend/src/server/api/openapi/gen-spec.ts
index 1efef8d26d..fe5a4715e8 100644
--- a/packages/backend/src/server/api/openapi/gen-spec.ts
+++ b/packages/backend/src/server/api/openapi/gen-spec.ts
@@ -1,5 +1,4 @@
import endpoints from '../endpoints';
-import { Context } from 'cafy';
import config from '@/config/index';
import { errors as basicErrors } from './errors';
import { schemas, convertSchemaToOpenApiSchema } from './schemas';
@@ -38,47 +37,7 @@ export function genOpenapiSpec(lang = 'ja-JP') {
},
};
- function genProps(props: { [key: string]: Context; }) {
- const properties = {} as any;
-
- for (const [k, v] of Object.entries(props)) {
- properties[k] = genProp(v);
- }
-
- return properties;
- }
-
- function genProp(param: Context): any {
- const required = param.name === 'Object' ? (param as any).props ? Object.entries((param as any).props).filter(([k, v]: any) => !v.isOptional).map(([k, v]) => k) : [] : [];
- return {
- description: (param.data || {}).desc,
- default: (param.data || {}).default,
- deprecated: (param.data || {}).deprecated,
- ...((param.data || {}).default ? { default: (param.data || {}).default } : {}),
- type: param.name === 'ID' ? 'string' : param.name.toLowerCase(),
- ...(param.name === 'ID' ? { example: 'xxxxxxxxxx', format: 'id' } : {}),
- nullable: param.isNullable,
- ...(param.name === 'String' ? {
- ...((param as any).enum ? { enum: (param as any).enum } : {}),
- ...((param as any).minLength ? { minLength: (param as any).minLength } : {}),
- ...((param as any).maxLength ? { maxLength: (param as any).maxLength } : {}),
- } : {}),
- ...(param.name === 'Number' ? {
- ...((param as any).minimum ? { minimum: (param as any).minimum } : {}),
- ...((param as any).maximum ? { maximum: (param as any).maximum } : {}),
- } : {}),
- ...(param.name === 'Object' ? {
- ...(required.length > 0 ? { required } : {}),
- properties: (param as any).props ? genProps((param as any).props) : {},
- } : {}),
- ...(param.name === 'Array' ? {
- items: (param as any).ctx ? genProp((param as any).ctx) : {},
- } : {}),
- };
- }
-
for (const endpoint of endpoints.filter(ep => !ep.meta.secure)) {
- const porops = {} as any;
const errors = {} as any;
if (endpoint.meta.errors) {
@@ -91,21 +50,9 @@ export function genOpenapiSpec(lang = 'ja-JP') {
}
}
- if (endpoint.meta.params) {
- for (const [k, v] of Object.entries(endpoint.meta.params)) {
- if (v.validator.data == null) v.validator.data = {};
- if (v.desc) v.validator.data.desc = v.desc[lang];
- if (v.deprecated) v.validator.data.deprecated = v.deprecated;
- if (v.default) v.validator.data.default = v.default;
- porops[k] = v.validator;
- }
- }
-
- const required = endpoint.meta.params ? Object.entries(endpoint.meta.params).filter(([k, v]) => !v.validator.isOptional).map(([k, v]) => k) : [];
-
const resSchema = endpoint.meta.res ? convertSchemaToOpenApiSchema(endpoint.meta.res) : {};
- let desc = (endpoint.meta.desc ? endpoint.meta.desc[lang] : 'No description provided.') + '\n\n';
+ let desc = (endpoint.meta.description ? endpoint.meta.description : 'No description provided.') + '\n\n';
desc += `**Credential required**: *${endpoint.meta.requireCredential ? 'Yes' : 'No'}*`;
if (endpoint.meta.kind) {
const kind = endpoint.meta.kind;
@@ -132,11 +79,7 @@ export function genOpenapiSpec(lang = 'ja-JP') {
required: true,
content: {
'application/json': {
- schema: {
- type: 'object',
- ...(required.length > 0 ? { required } : {}),
- properties: endpoint.meta.params ? genProps(porops) : {},
- },
+ schema: endpoint.params,
},
},
},
diff --git a/packages/backend/src/server/api/openapi/schemas.ts b/packages/backend/src/server/api/openapi/schemas.ts
index eb42667fd5..5d062168e7 100644
--- a/packages/backend/src/server/api/openapi/schemas.ts
+++ b/packages/backend/src/server/api/openapi/schemas.ts
@@ -1,6 +1,6 @@
-import { refs, MinimumSchema } from '@/misc/schema';
+import { refs, Schema } from '@/misc/schema';
-export function convertSchemaToOpenApiSchema(schema: MinimumSchema) {
+export function convertSchemaToOpenApiSchema(schema: Schema) {
const res: any = schema;
if (schema.type === 'object' && schema.properties) {