Skip to content

Commit

Permalink
add openapi specs directly into the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Nov 25, 2024
1 parent 2c013bc commit c19b53b
Show file tree
Hide file tree
Showing 356 changed files with 33,446 additions and 11,463 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/apiary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22

- name: Install apiaryio
run: sudo gem install apiaryio
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lychee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Use Node.js 20
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'npm'
cache-dependency-path: 'package-lock.json'
always-auth: 'true'
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Check OpenAPI specs

on:
push:

#env:
# APIFY_STAGING_TOKEN: ${{ secrets.APIFY_STAGING_TOKEN }}

jobs:
build:
name: Build the specification file
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
cache-dependency-path: 'package-lock.json'
registry-url: 'https://npm.pkg.github.com/'
scope: '@apify-packages'

- name: Enable corepack
run: |
corepack enable
- name: Install Dependencies
run: npm ci --force
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- run: |
npm ci
npm run redoc:test
# - uses: actions/setup-python@v5
# with:
# python-version: '3.10'
# - run: python -m pip install schemathesis==3.35.0
8 changes: 4 additions & 4 deletions .github/workflows/publish-theme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
with:
fetch-depth: 0

- name: Use Node.js 20
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22

- name: Check changes in theme
id: changed-theme-files
Expand All @@ -39,10 +39,10 @@ jobs:
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

- name: Use Node.js 20
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'npm'
cache-dependency-path: 'package-lock.json'
always-auth: 'true'
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ node_modules
*.pid
*.seed
.DS_Store
lib
coverage
.nyc_output
logs
pids
.idea
.vscode
yarn.lock
tmp
jsconfig.json
types
.history
.docusaurus
tsconfig.tsbuildinfo
.turbo
sources/api/*
!sources/api/sidebars.js
openapi/openapi.yaml
28 changes: 17 additions & 11 deletions .redocly.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
# See https://redoc.ly/docs/cli/configuration/ for more information.
apis:
main@v1:
root: openapi/openapi/openapi.yaml

extends:
- recommended

rules:
spec: error
no-unused-components: error

theme:
htmlTemplate: openapi/docs/index.html

openapi:
requiredPropsFirst: true
noAutoAuth: true
hideDownloadButton: true
onlyRequiredInSamples: true
nativeScrollbars: true
scrollYOffset: 68
colors:
primary:
main: '#1f9ec8'
expandDefaultResponse: true
expandDefaultRequest: true
expandResponses: all
schemaExpansionLevel: 2
jsonSampleExpandLevel: 2
schemasExpansionLevel: 2
jsonSamplesExpandLevel: 2

plugins:
- openapi/plugins/apify.js

decorators:
apify/legacy-doc-url-decorator: on
apify/client-references-links-decorator: on
3 changes: 3 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ SER = "SER"

[files]
extend-exclude = ['sources/api/*.mdx']

[files]
extend-exclude = ['sources/api/*.mdx']
2 changes: 1 addition & 1 deletion apify-docs-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"dependencies": {
"@apify/docs-search-modal": "^1.1.1",
"@docusaurus/theme-common": "3.6.2",
"@docusaurus/theme-common": "3.6.3",
"@stackql/docusaurus-plugin-hubspot": "^1.1.0",
"axios": "^1.7.4",
"babel-loader": "^9.1.3",
Expand Down
23 changes: 18 additions & 5 deletions apify-docs-theme/src/roa-loader/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
const { inspect } = require('util');
const { createHash } = require('node:crypto');
const { inspect } = require('node:util');

const { urlToRequest } = require('loader-utils');

const signingUrl = new URL('https://api.apify.com/v2/tools/encode-and-sign');
signingUrl.searchParams.set('token', process.env.APIFY_SIGNING_TOKEN);
const queue = [];
const cache = {};
let working = false;

function hash(source) {
return createHash('sha1').update(source).digest('hex');
}

async function getHash(source) {
const cacheKey = hash(source);

if (cache[cacheKey]) {
return cache[cacheKey];
}

const memory = source.match(/playwright|puppeteer/i) ? 4096 : 1024;
const res = await (await fetch(signingUrl, {
method: 'POST',
Expand All @@ -25,14 +37,15 @@ async function getHash(source) {
},
})).json();

await new Promise((resolve) => setTimeout(resolve, 100));

if (!res.data || !res.data.encoded) {
// eslint-disable-next-line no-console
console.error(`Signing failed:' ${inspect(res.error) || 'Unknown error'}`, res);
return 'invalid-token';
}

cache[cacheKey] = res.data.encoded;
await new Promise((resolve) => setTimeout(resolve, 100));

return res.data.encoded;
}

Expand Down Expand Up @@ -68,7 +81,7 @@ module.exports = async function (code) {

// eslint-disable-next-line no-console
console.log(`Signing ${urlToRequest(this.resourcePath)}...`, { working, queue: queue.length });
const hash = await encodeAndSign(code);
const codeHash = await encodeAndSign(code);

return { code, hash };
return { code, hash: codeHash };
};
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module.exports = {
config: {
/** @type {import('docusaurus-plugin-openapi-docs').Options} */
v2: {
specPath: 'node_modules/@apify/openapi/openapi.yaml',
specPath: 'openapi.yaml',
outputDir: './sources/api',
sidebarOptions: {
groupPathsBy: 'tag',
Expand Down
Loading

0 comments on commit c19b53b

Please sign in to comment.