From 3ad3ebb177852ef303de0dba03e70875eeeb446c Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 20 Sep 2024 22:46:38 +0100 Subject: [PATCH] Inline handleResponse --- src/api/autogen/index.ts | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/api/autogen/index.ts b/src/api/autogen/index.ts index 7d62390..e1bbaad 100644 --- a/src/api/autogen/index.ts +++ b/src/api/autogen/index.ts @@ -325,8 +325,23 @@ class DeviceMethod { this.name = name; this.method = method; this.doc = getDoc(schema); - this.returnType = handleResponse(method, device, this.name, schema); this.inBaseDevice = device.isBaseDevice; + const { + responses: { + 200: success, + 400: error400, + 500: error500, + ...otherResponses + } = err('Missing responses') + } = schema; + assertEmpty(otherResponses, 'Unexpected response status codes'); + assert.deepEqual(error400, { $ref: '#/components/responses/400' }); + assert.deepEqual(error500, { $ref: '#/components/responses/500' }); + this.returnType = new TypeContext(method, 'Response', device).handleContent( + name, + 'application/json', + success + ); } private _brand!: never; @@ -591,27 +606,6 @@ class TypeContext { } } -function handleResponse( - method: 'GET' | 'PUT', - device: Device, - canonicalMethodName: string, - { - responses: { - 200: success, - 400: error400, - 500: error500, - ...otherResponses - } = err('Missing responses') - }: OpenAPIV3_1.OperationObject -) { - assertEmpty(otherResponses, 'Unexpected response status codes'); - return new TypeContext(method, 'Response', device).handleContent( - canonicalMethodName, - 'application/json', - success - ); -} - function extractParams( methodSchema: OpenAPIV3_1.OperationObject, device: Device,