Skip to content

Commit 081ccdb

Browse files
committed
fix: correct response_schema handling and remove deprecated responce_schema
1 parent cfdfaf4 commit 081ccdb

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

adminforth/servers/express.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function normalizeExpressRuntimeSchema(schema: unknown): AnySchemaObject | undef
109109
}
110110

111111
if (isZodSchemaLike(schema)) {
112-
return z.toJSONSchema(schema as any, { target: 'openapi-3.0' }) as AnySchemaObject;
112+
return z.toJSONSchema(schema as any, { target: 'draft-07' }) as AnySchemaObject;
113113
}
114114

115115
return schema as AnySchemaObject;
@@ -595,22 +595,22 @@ class ExpressServer implements IExpressHttpServer {
595595
description,
596596
request_schema,
597597
response_schema,
598-
responce_schema,
599598
agent,
600599
target='json'
601600
} = options;
602601
if (!path.startsWith('/')) {
603602
throw new Error(`Path must start with /, got: ${path}`);
604603
}
605604
const fullPath = `${this.adminforth.config.baseUrl}/adminapi/v1${path}`;
606-
const normalizedResponseSchema = response_schema ?? responce_schema;
607-
const registeredApiSchema = (request_schema || normalizedResponseSchema)
605+
const normalizedRequestSchema = normalizeExpressRuntimeSchema(request_schema);
606+
const normalizedResponseSchema = normalizeExpressRuntimeSchema(response_schema);
607+
const registeredApiSchema = (normalizedRequestSchema || normalizedResponseSchema)
608608
? this.adminforth.openApi.registerApiSchema({
609609
method,
610610
noAuth,
611611
path: fullPath,
612612
description,
613-
request_schema,
613+
request_schema: normalizedRequestSchema,
614614
response_schema: normalizedResponseSchema,
615615
agent,
616616
handler,

adminforth/servers/openapi.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ class OpenApiRegistry implements IOpenApiRegistry {
5151
}
5252

5353
registerApiSchema(options: IAdminForthEndpointOptions): IRegisteredApiSchema {
54-
const responseSchema = options.response_schema ?? options.responce_schema;
5554
const route: IRegisteredApiSchema = {
5655
method: options.method.toLowerCase(),
5756
path: options.path,
5857
description: options.description,
5958
agent: options.agent,
6059
request_schema: options.request_schema,
61-
response_schema: responseSchema,
60+
response_schema: options.response_schema,
6261
meta: options.meta,
6362
handler: options.handler,
6463
};

adminforth/types/Back.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export interface IAdminForthEndpointOptionsBase {
7373
description?: string,
7474
request_schema?: AnySchemaObject,
7575
response_schema?: AnySchemaObject,
76-
responce_schema?: AnySchemaObject,
7776
agent?: AgentToolMeta,
7877
meta?: Record<string, unknown>,
7978
target?: 'json' | 'upload',

0 commit comments

Comments
 (0)