Skip to content

Commit

Permalink
feat: added getOpenApiSpecification() to BuildClient (#626)
Browse files Browse the repository at this point in the history
Recently we've introduced new endpoint:
- `/v2/actor-builds/:buildId/openapi-specification`

**This PR adds this endpoint to BuildClient**

P.S. The link to the documentation is correct, but docs are not yet
merged into production. I'll merge this PR after the docs are merged.

---------

Co-authored-by: Martin Adámek <[email protected]>
  • Loading branch information
danpoletaev and B4nan authored Jan 27, 2025
1 parent c254c71 commit 6248b28
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/resource_clients/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ export class BuildClient extends ResourceClient {
return this._delete();
}

/**
* https://docs.apify.com/api/v2/actor-build-openapi-specification-get
*/
async getOpenApiSpecification(): Promise<OpenApiSpecification> {
const response = await this.httpClient.call({
url: this._url('openapi-specification'),
method: 'GET',
params: this._params(),
});

return response.data;
}

/**
* Returns a promise that resolves with the finished Build object when the provided actor build finishes
* or with the unfinished Build object when the `waitSecs` timeout lapses. The promise is NOT rejected
Expand Down Expand Up @@ -142,3 +155,58 @@ export interface BuildOptions {
memoryMbytes?: number;
diskMbytes?: number;
}

export interface OpenApiSpecification {
openapi: string;
info: {
title: string
description?: string;
version?: string
'x-build-id': string
};
servers: { url: string }[]
paths: { [key: string]: { post: OpenApiOperation } };
components: {
schemas: {
[key: string]: object
}
}
}

interface OpenApiOperation {
operationId: string
'x-openai-isConsequential': boolean
summary: string
tags: string[]
requestBody: {
required: boolean;
content: {
'application/json': {
schema: {
'$ref': string
}
}
}
}
parameters: {
name: string
in: string
required: boolean
schema: {
type: string;
}
description: string
}[]
responses: {
'200': {
description: string
content?: {
'application/json': {
schema: {
'$ref': string
}
}
}
}
}
}
12 changes: 12 additions & 0 deletions test/builds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ describe('Build methods', () => {
validateRequest({}, { buildId });
});

test('getOpenApiSpecification() works', async () => {
const buildId = 'some-build-id';

const res = await client.build(buildId).getOpenApiSpecification();
expect(res.data.id).toEqual('build-openapi-specification');
validateRequest({}, { buildId });

const browserRes = await page.evaluate((bId) => client.build(bId).getOpenApiSpecification(), buildId);
expect(browserRes).toEqual(res);
validateRequest({}, { buildId });
});

test('waitForFinish() works', async () => {
const buildId = 'some-build-id';
const waitSecs = 0.1;
Expand Down
1 change: 1 addition & 0 deletions test/mock_server/routes/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ROUTES = [
{ id: 'get-build', method: 'GET', path: '/:buildId', type: 'responseJsonMock' },
{ id: 'abort-build', method: 'POST', path: '/:buildId/abort' },
{ id: 'build-log', method: 'GET', path: '/:buildId/log', type: 'text' },
{ id: 'build-openapi-specification', method: 'GET', path: '/:buildId/openapi-specification', type: 'responseJsonMock' },
];

addRoutes(builds, ROUTES);
Expand Down

0 comments on commit 6248b28

Please sign in to comment.