Skip to content

Commit b699937

Browse files
authored
Merge pull request #246 from autonomys/add-api-reference
feat(doc): create api documentation
2 parents e28693c + 8005bdc commit b699937

File tree

13 files changed

+1101
-15
lines changed

13 files changed

+1101
-15
lines changed

.yarn/install-state.gz

2.36 KB
Binary file not shown.

backend/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"start:server": "node --loader ts-node/esm src/server.ts",
1010
"start": "node dist/server.js",
1111
"start:prod": "node dist/server.prod.js",
12+
"start:docs": "node --loader ts-node/esm src/http/controllers/docs.ts",
1213
"test": "node --experimental-vm-modules ../node_modules/jest/bin/jest.js --runInBand --coverage",
1314
"lint": "eslint . "
1415
},
@@ -31,7 +32,7 @@
3132
"dotenv": "^16.4.5",
3233
"express": "^4.19.2",
3334
"jsonwebtoken": "^9.0.2",
34-
"keyv": "^5.2.1",
35+
"keyv": "^5.3.1",
3536
"lru-cache": "^11.0.2",
3637
"multer": "^1.4.5-lts.1",
3738
"multiformats": "^13.2.2",

backend/src/api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { handleAuth } from './services/auth/express.js'
88
import { uploadController } from './http/controllers/upload.js'
99
import { config } from './config.js'
1010
import { logger } from './drivers/logger.js'
11+
import { docsController } from './http/controllers/docs.js'
1112

1213
const createServer = async () => {
1314
const app = express()
@@ -34,6 +35,7 @@ const createServer = async () => {
3435
app.use('/objects', objectController)
3536
app.use('/subscriptions', subscriptionController)
3637
app.use('/uploads', uploadController)
38+
app.use('/docs', docsController)
3739

3840
app.get('/health', (_req, res) => {
3941
res.sendStatus(204)

backend/src/docs/reference/common.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export const common = {
2+
components: {
3+
schemas: {
4+
UploadOptions: {
5+
type: 'object',
6+
properties: {
7+
compression: {
8+
$ref: '#/components/schemas/CompressionOptions',
9+
},
10+
encryption: {
11+
$ref: '#/components/schemas/EncryptionOptions',
12+
},
13+
},
14+
},
15+
CompressionOptions: {
16+
type: 'object',
17+
properties: {
18+
algorithm: { type: 'string', enum: ['ZLIB'] },
19+
level: { type: 'integer', default: 8 },
20+
},
21+
},
22+
EncryptionOptions: {
23+
type: 'object',
24+
properties: {
25+
algorithm: { type: 'string', enum: ['AES_256_GCM'] },
26+
chunkSize: { type: 'integer', default: 1024 },
27+
},
28+
},
29+
},
30+
},
31+
}

backend/src/docs/reference/index.ts

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { common } from './common.js'
2+
import { objects } from './objects.js'
3+
import { subscriptions } from './subscriptions.js'
4+
import { uploads } from './uploads.js'
5+
6+
export const swagger = {
7+
openapi: '3.0.0',
8+
info: {
9+
title: 'Auto Drive API',
10+
version: '1.0.0',
11+
description: 'API for Auto Drive',
12+
},
13+
servers: [
14+
{
15+
url: 'https://mainnet.auto-drive.autonomys.xyz/api',
16+
description: 'Mainnet',
17+
},
18+
{
19+
url: 'https://demo.auto-drive.autonomys.xyz/api',
20+
description: 'Testnet',
21+
},
22+
],
23+
paths: {
24+
...subscriptions.paths,
25+
...uploads.paths,
26+
...objects.paths,
27+
},
28+
security: [
29+
{
30+
apiKey: [],
31+
provider: [],
32+
},
33+
],
34+
components: {
35+
schemas: {
36+
...uploads.components.schemas,
37+
...objects.components.schemas,
38+
...common.components.schemas,
39+
...subscriptions.components.schemas,
40+
},
41+
securitySchemes: {
42+
apiKey: {
43+
type: 'apiKey',
44+
in: 'header',
45+
name: 'Authorization',
46+
description:
47+
'Bearer token for authentication. Example: Bearer <token>. Could be either an API key or a JWT token.',
48+
},
49+
provider: {
50+
type: 'apiKey',
51+
in: 'header',
52+
name: 'X-Auth-Provider',
53+
description:
54+
'Used for differentiating between different auth providers. For most use cases: X-Auth-Provider: apikey',
55+
},
56+
},
57+
},
58+
}

0 commit comments

Comments
 (0)