From b679163d01b0152b38db658fe49d8a57c6aad930 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 24 Feb 2019 09:45:27 +0900 Subject: Improve type definitions --- src/server/api/openapi/gen-spec.ts | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'src/server/api/openapi/gen-spec.ts') diff --git a/src/server/api/openapi/gen-spec.ts b/src/server/api/openapi/gen-spec.ts index ad46eb20a4..7487918231 100644 --- a/src/server/api/openapi/gen-spec.ts +++ b/src/server/api/openapi/gen-spec.ts @@ -4,6 +4,7 @@ import config from '../../../config'; import { errors as basicErrors } from './errors'; import { schemas } from './schemas'; import { description } from './description'; +import { convertOpenApiSchema } from '../../../prelude/schema'; export function genOpenapiSpec(lang = 'ja-JP') { const spec = { @@ -104,33 +105,7 @@ export function genOpenapiSpec(lang = 'ja-JP') { 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 ? renderType(endpoint.meta.res) : {}; - - function renderType(x: any) { - const res = {} as any; - - if (['User', 'Note', 'DriveFile'].includes(x.type)) { - res['$ref'] = `#/components/schemas/${x.type}`; - } else if (x.type === 'object') { - res['type'] = 'object'; - if (x.props) { - const props = {} as any; - for (const kv of Object.entries(x.props)) { - props[kv[0]] = renderType(kv[1]); - } - res['properties'] = props; - } - } else if (x.type === 'array') { - res['type'] = 'array'; - if (x.items) { - res['items'] = renderType(x.items); - } - } else { - res['type'] = x.type; - } - - return res; - } + const resSchema = endpoint.meta.res ? convertOpenApiSchema(endpoint.meta.res) : {}; const info = { operationId: endpoint.name, -- cgit v1.2.3-freya