Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: various OpenAPI plugin fixes #1371

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apify-api/openapi/components/tags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
x-parent-tag-name: Actors
x-legacy-doc-urls:
- '#/reference/actors/run-collection'
- '#tag/ActorsRun-collection'
x-trait: 'true'
- name: Actors/Run actor synchronously
x-displayName: Run actor synchronously
Expand Down
3 changes: 1 addition & 2 deletions apify-api/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ info:

To use your token in a request, either:

- Add the token to your request's `Authorization` header as `Bearer
<token>`.
- Add the token to your request's `Authorization` header as `Bearer <token>`.
E.g., `Authorization: Bearer xxxxxxx`.
[More info](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization).
(Recommended).
Expand Down
38 changes: 10 additions & 28 deletions apify-api/openapi/paths/actors/acts@{actorId}@run-sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,22 @@ post:
description: |
Runs a specific Actor and returns its output.


The POST payload including its `Content-Type` header is passed as `INPUT` to
the Actor (usually <code>application/json</code>).

The HTTP response contains Actors `OUTPUT` record from its default
key-value store.


The Actor is started with the default options; you can override them using
various URL query parameters.

If the Actor run exceeds 300<!-- MAX_ACTOR_JOB_SYNC_WAIT_SECS --> seconds,
the HTTP response will have status 408 (Request Timeout).


Beware that it might be impossible to maintain an idle HTTP connection for a
long period of time, due to client timeout or network conditions. Make sure your HTTP client is
configured to have a long enough connection timeout.

If the connection breaks, you will not receive any information about the run
and its status.


To run the Actor asynchronously, use the [Run
Actor](#/reference/actors/run-collection/run-actor) API endpoint instead.
operationId: act_runSync_post
Expand All @@ -42,9 +35,9 @@ post:
example: janedoe~my-actor
- name: outputRecordKey
in: query
description: |-
description: |
Key of the record from run's default key-value store to be returned
in the response. By default, it is `OUTPUT`.
in the response. By default, it is `OUTPUT`.
style: form
explode: true
schema:
Expand Down Expand Up @@ -103,12 +96,9 @@ post:
description: |
Specifies optional webhooks associated with the Actor run, which can be
used to receive a notification

e.g. when the Actor finished or failed. The value is a Base64-encoded
JSON array of objects defining the webhooks. For more information, see

[Webhooks
documentation](https://docs.apify.com/platform/integrations/webhooks).
[Webhooks documentation](https://docs.apify.com/platform/integrations/webhooks).
style: form
explode: true
schema:
Expand Down Expand Up @@ -143,9 +133,8 @@ post:
example:
error:
type: run-failed
message: >-
Actor run did not succeed (run ID: 55uatRrZib4xbZs, status:
FAILED)
message: |
Actor run did not succeed (run ID: 55uatRrZib4xbZs, status: FAILED)
'408':
description: ''
headers: {}
Expand All @@ -161,29 +150,24 @@ post:
x-legacy-doc-urls:
- https://docs.apify.com/api/v2#/reference/actors/run-actor-synchronously/with-input
- https://docs.apify.com/api/v2#/reference/actors/with-input
- https://docs.apify.com/api/v2#tag/ActorsRun-actor-synchronously/operation/act_runSync_post
get:
tags:
- Actors/Run actor synchronously
summary: Without input
description: |
Runs a specific Actor and returns its output.

The run must finish in 300<!-- MAX_ACTOR_JOB_SYNC_WAIT_SECS --> seconds
otherwise the API endpoint returns a timeout error.

The Actor is not passed any input.


Beware that it might be impossible to maintain an idle HTTP connection for a
long period of time,

due to client timeout or network conditions. Make sure your HTTP client is
configured to have a long enough connection timeout.

If the connection breaks, you will not receive any information about the run
and its status.


To run the Actor asynchronously, use the [Run
Actor](#/reference/actors/run-collection/run-actor) API endpoint instead.
operationId: act_runSync_get
Expand All @@ -198,9 +182,9 @@ get:
example: janedoe~my-actor
- name: outputRecordKey
in: query
description: |-
description: |
Key of the record from run's default key-value store to be returned
in the response. By default, it is `OUTPUT`.
in the response. By default, it is `OUTPUT`.
style: form
explode: true
schema:
Expand Down Expand Up @@ -259,12 +243,9 @@ get:
description: |
Specifies optional webhooks associated with the Actor run, which can be
used to receive a notification

e.g. when the Actor finished or failed. The value is a Base64-encoded
JSON array of objects defining the webhooks. For more information, see

[Webhooks
documentation](https://docs.apify.com/platform/integrations/webhooks).
[Webhooks documentation](https://docs.apify.com/platform/integrations/webhooks).
style: form
explode: true
schema:
Expand Down Expand Up @@ -308,3 +289,4 @@ get:
x-legacy-doc-urls:
- https://docs.apify.com/api/v2#/reference/actors/run-actor-synchronously/without-input
- https://docs.apify.com/api/v2#/reference/actors/without-input
- https://docs.apify.com/api/v2#tag/ActorsRun-actor-synchronously/operation/act_runSync_get
12 changes: 11 additions & 1 deletion apify-docs-theme/src/theme/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -990,14 +990,19 @@ html[data-theme='dark'] .actionLink:hover::after {
}
}

aside li.section-header > div > .menu__link {
aside li.section-header > div > .menu__link,
aside li.section-header > ul > li > div > .menu__link {
text-transform: uppercase;
opacity: 0.8;
font-size: 16px;
font-weight: 700;
margin: 0;
}

aside li.section-header > div > .menu__link {
font-size: 20px;
}

aside li.section-header.menu__list-item {
margin-top: 15px;
margin-bottom: 5px;
Expand All @@ -1011,6 +1016,11 @@ aside li.section-header > .menu__list {
padding-left: 0;
}

.theme-doc-sidebar-menu li.section-header > ul > li .menu__list-item-collapsible:hover,
.theme-doc-sidebar-menu li.section-header > ul > li .menu__list-item-collapsible--active {
background: inherit !important;
}

.beta-chip {
display: inline-block;
border: 1px solid #ccc;
Expand Down
14 changes: 5 additions & 9 deletions apify-docs-theme/static/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function scrollSidebarItemIntoView() {

// handles automatic scrolling of the API reference sidebar (openapi-docs)
function scrollOpenApiSidebarItemIntoView() {
const $li = document.querySelector(`li > a.menu__link--active[href]`);
const $li = document.querySelector(`ul.theme-doc-sidebar-menu a.menu__link--active[href]`);

if (!$li) {
return;
Expand All @@ -83,21 +83,17 @@ function redirectOpenApiDocs() {
return;
}

if (hash.startsWith('#/reference/')) {
const sidebarItems = document.querySelectorAll('[data-altids]');
const sidebarItems = document.querySelectorAll('[data-altids]');

if (hash.startsWith('#/reference/') || hash.startsWith('#tag/')) {
for (const item of sidebarItems) {
const ids = item.getAttribute('data-altids').split(',');
if (ids.find((variant) => variant === hash)) {
item.click();
setTimeout(() => scrollOpenApiSidebarItemIntoView(), 200);
}
}
}

if (hash.startsWith('#tag/')) {
const id = hash.substring('#tag/'.length);
console.log('redirect', { id, hash });
}
}

let ticking = false;
Expand All @@ -121,7 +117,7 @@ window.addEventListener('load', () => {
setTimeout(() => scrollSidebarItemIntoView(), 1000);

// docusaurus-openapi-docs plugin: scroll sidebar into viewport, no need for a large timeout here
setTimeout(() => scrollOpenApiSidebarItemIntoView(), 100);
setTimeout(() => scrollOpenApiSidebarItemIntoView(), 200);
});

window.addEventListener('popstate', () => {
Expand Down
20 changes: 17 additions & 3 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { join } = require('node:path');

const clsx = require('clsx');
const { createApiPageMD } = require('docusaurus-plugin-openapi-docs/lib/markdown');

const { config } = require('./apify-docs-theme');
const { collectSlugs } = require('./tools/utils/collectSlugs');
Expand Down Expand Up @@ -195,15 +196,28 @@ module.exports = {
v2: {
specPath: 'apify-api.yaml',
outputDir: './sources/api',
markdownGenerators: {
createApiPageMD: (pageData) => {
let md = createApiPageMD(pageData);

// HTML comments are wrongly escaped, we need to undo that
if (md.includes('&lt;!--')) {
md = md.replace('&lt;!--', '<!--');
md = md.replace('--&gt;', '-->');
}

return md;
},
},
sidebarOptions: {
groupPathsBy: 'tag',
groupPathsBy: 'tagGroup',
categoryLinkSource: 'tag',
sidebarCollapsed: false,
sidebarCollapsible: false,
sidebarGenerators: {
createDocItem: (item, context) => {
const legacyUrls = item.api?.['x-legacy-doc-urls'] ?? [];
const altIds = legacyUrls.map((url) => {
const altids = legacyUrls.map((url) => {
const { hash } = new URL(url);
return hash;
});
Expand All @@ -223,7 +237,7 @@ module.exports = {
type: 'doc',
id: context.basePath === '' ? `${id}` : `${context.basePath}/${id}`,
label: sidebarLabel ?? title ?? id,
customProps: { altIds },
customProps: { altids },
className,
};
},
Expand Down
36 changes: 36 additions & 0 deletions patches/docusaurus-plugin-openapi-docs+0.0.0-961.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js b/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js
index 5802904..576c3ed 100644
--- a/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js
+++ b/node_modules/docusaurus-plugin-openapi-docs/lib/sidebars/index.js
@@ -139,9 +139,16 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
}
const taggedApiItems = apiItems.filter((item) => { var _a; return !!((_a = item.api.tags) === null || _a === void 0 ? void 0 : _a.includes(tag)); });
const taggedSchemaItems = schemaItems.filter((item) => { var _a; return !!((_a = item.schema["x-tags"]) === null || _a === void 0 ? void 0 : _a.includes(tag)); });
+ const altids = [];
+
+ if (tagObject?.['x-legacy-doc-urls']) {
+ altids.push(...tagObject['x-legacy-doc-urls']);
+ }
+
return {
type: "category",
label: (_a = tagObject === null || tagObject === void 0 ? void 0 : tagObject["x-displayName"]) !== null && _a !== void 0 ? _a : tag,
+ customProps: { altids },
link: linkConfig,
collapsible: sidebarCollapsible,
collapsed: sidebarCollapsed,
@@ -201,11 +208,12 @@ function generateSidebarSlice(sidebarOptions, options, api, tags, docPath, tagGr
filteredTags.push(tag);
}
});
+ const { sidebarCollapsed, sidebarCollapsible } = sidebarOptions;
const groupCategory = {
type: "category",
label: tagGroup.name,
- collapsible: true,
- collapsed: true,
+ collapsible: sidebarCollapsible,
+ collapsed: sidebarCollapsed,
items: groupByTags(api, sidebarOptions, options, [filteredTags], docPath),
};
if (options.showSchemas) {
14 changes: 12 additions & 2 deletions sources/api/sidebars.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
// eslint-disable-next-line global-require
const items = require('./sidebar.ts');

for (const item of items) {
// this is wrongly rendered in each category (openapi group tag)
if (item.items[0].id === 'apify-api') {
item.items.shift();
}
}

module.exports = {
api: [
{
type: 'category',
label: 'Apify API',
collapsible: false,
className: 'section-header',
// eslint-disable-next-line global-require
items: require('./sidebar.ts'),
link: { type: 'doc', id: 'apify-api' },
items,
},
],
};
Loading
Loading