Skip to content

Commit

Permalink
Inline handleResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Sep 20, 2024
1 parent a881c09 commit 3ad3ebb
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/api/autogen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3ad3ebb

Please sign in to comment.