@redocly/portal-plugin-async-api 0.0.0-react18-20231120182601
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +972 -0
- package/LICENSE +3 -0
- package/README.md +1 -0
- package/lib/.tsbuildinfo +1 -0
- package/lib/config.d.ts +158 -0
- package/lib/config.js +32 -0
- package/lib/config.js.map +1 -0
- package/lib/plugin.d.ts +2 -0
- package/lib/plugin.js +99 -0
- package/lib/plugin.js.map +1 -0
- package/lib/styles.d.ts +1 -0
- package/lib/styles.js +646 -0
- package/lib/styles.js.map +1 -0
- package/lib/template.d.ts +11 -0
- package/lib/template.js +38 -0
- package/lib/template.js.map +1 -0
- package/package.json +47 -0
- package/src/config.ts +37 -0
- package/src/plugin.ts +115 -0
- package/src/styles.tsx +646 -0
- package/src/template.tsx +81 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +12 -0
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@redocly/portal-plugin-async-api",
|
|
3
|
+
"version": "0.0.0-react18-20231120182601",
|
|
4
|
+
"description": "Async API plugin for @redocly/portal",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./lib/plugin.js",
|
|
8
|
+
"./package.json": "./package.json",
|
|
9
|
+
"./plugin.js": "./lib/plugin.js",
|
|
10
|
+
"./template": "./lib/template.js",
|
|
11
|
+
"./template.js": "./lib/template.js",
|
|
12
|
+
"./config.js": "./lib/config.js",
|
|
13
|
+
"./config": "./lib/config.js"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"redocly",
|
|
17
|
+
"theme",
|
|
18
|
+
"AsyncAPI"
|
|
19
|
+
],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^18.11.18",
|
|
24
|
+
"@types/react": "^18.2.31",
|
|
25
|
+
"@types/styled-components": "^5.1.30",
|
|
26
|
+
"typescript": "^5.2.2"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@asyncapi/bundler": "^0.3.11",
|
|
30
|
+
"@asyncapi/react-component": "1.0.0-next.47",
|
|
31
|
+
"json-schema-to-ts": "^2.9.1",
|
|
32
|
+
"styled-components": "^5.3.11"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": "^18.0.0",
|
|
36
|
+
"@redocly/portal": "0.0.0-react18-20231120182601"
|
|
37
|
+
},
|
|
38
|
+
"overrides": {
|
|
39
|
+
"react": "^18.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"clean": "rm -rf lib",
|
|
43
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
44
|
+
"build": "npm run clean && npm run compile",
|
|
45
|
+
"watch": "tsc -w -p tsconfig.build.json"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { FromSchema } from 'json-schema-to-ts';
|
|
2
|
+
|
|
3
|
+
const expandSectionSchema = {
|
|
4
|
+
type: 'object',
|
|
5
|
+
properties: {
|
|
6
|
+
root: { type: 'boolean' },
|
|
7
|
+
elements: { type: 'boolean' },
|
|
8
|
+
},
|
|
9
|
+
additionalProperties: false,
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
const asyncApiDocsSchema = {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
schemaId: { type: 'string' },
|
|
16
|
+
hideErrors: { type: 'boolean' },
|
|
17
|
+
hideInfo: { type: 'boolean' },
|
|
18
|
+
hideChannels: { type: 'boolean' },
|
|
19
|
+
hideServers: { type: 'boolean' },
|
|
20
|
+
hideMessages: { type: 'boolean' },
|
|
21
|
+
hideSchemas: { type: 'boolean' },
|
|
22
|
+
expandChannels: expandSectionSchema,
|
|
23
|
+
expandServers: expandSectionSchema,
|
|
24
|
+
expandMessages: expandSectionSchema,
|
|
25
|
+
expandSchemas: expandSectionSchema,
|
|
26
|
+
},
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
export const themeConfigSchema = {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
asyncapi: asyncApiDocsSchema,
|
|
34
|
+
},
|
|
35
|
+
} as const;
|
|
36
|
+
|
|
37
|
+
export type AsyncApiDocsSettings = FromSchema<typeof asyncApiDocsSchema>;
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// FIXME: think of a way to make these imports shorter?
|
|
2
|
+
|
|
3
|
+
import { getAllowedTeamsForRoute } from '@redocly/portal/dist/server/utils/rbac.js';
|
|
4
|
+
import { REDOCLY_TEAMS_RBAC } from '@redocly/portal/dist/shared/constants.js';
|
|
5
|
+
import { withPathPrefix } from '@redocly/portal/dist/shared/urls.js';
|
|
6
|
+
import bundle from '@asyncapi/bundler';
|
|
7
|
+
|
|
8
|
+
import type { PageStaticData } from '@redocly/portal/dist/shared/types';
|
|
9
|
+
import type { AsyncApiDocsSettings } from './config';
|
|
10
|
+
import type {
|
|
11
|
+
GetStaticDataFn,
|
|
12
|
+
PageRouteDetails,
|
|
13
|
+
PluginInstance,
|
|
14
|
+
} from '@redocly/portal/dist/server/plugins/types';
|
|
15
|
+
|
|
16
|
+
const ASYNCAPI_TEMPLATE_ID = 'asyncapi-docs';
|
|
17
|
+
const ASYNCAPI_SHARED_DATA_PREFIX = 'asyncapi-docs-';
|
|
18
|
+
|
|
19
|
+
export default async function asyncAPIDocsPlugin(): Promise<PluginInstance> {
|
|
20
|
+
return {
|
|
21
|
+
processContent: async (contentProvider, actions) => {
|
|
22
|
+
const asyncAPITemplateId = actions.createTemplate(
|
|
23
|
+
ASYNCAPI_TEMPLATE_ID,
|
|
24
|
+
'@redocly/portal-plugin-async-api/template.js',
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const config = actions.getConfig<{ asyncapi?: AsyncApiDocsSettings }>();
|
|
28
|
+
const globalSettings = config.theme?.asyncapi || {};
|
|
29
|
+
|
|
30
|
+
const definitions = loadDefinitions();
|
|
31
|
+
const currentScriptLocation = process.cwd();
|
|
32
|
+
|
|
33
|
+
for (const [relativePath, parsedDefinition] of definitions) {
|
|
34
|
+
const pageSlug = contentProvider.slugFromRelativePath(relativePath);
|
|
35
|
+
|
|
36
|
+
const sharedDataKey = `${ASYNCAPI_SHARED_DATA_PREFIX}${relativePath}`;
|
|
37
|
+
const isLocatedInRoot = relativePath.lastIndexOf('/') === -1;
|
|
38
|
+
try {
|
|
39
|
+
const fileLocation = relativePath.substring(
|
|
40
|
+
0,
|
|
41
|
+
isLocatedInRoot ? undefined : relativePath.lastIndexOf('/'),
|
|
42
|
+
);
|
|
43
|
+
// todo: workaround for $ref resolving until following issue is resolved: https://github.com/asyncapi/bundler/issues/136
|
|
44
|
+
process.chdir(fileLocation);
|
|
45
|
+
const bundledContent = await bundle([parsedDefinition as string]);
|
|
46
|
+
await actions.createSharedData(sharedDataKey, bundledContent.string());
|
|
47
|
+
|
|
48
|
+
const route = {
|
|
49
|
+
slug: pageSlug,
|
|
50
|
+
fsPath: relativePath,
|
|
51
|
+
templateId: asyncAPITemplateId,
|
|
52
|
+
getStaticData: buildGetStaticDataFn(globalSettings, pageSlug),
|
|
53
|
+
versions: contentProvider.versions.getPageVersions(relativePath, pageSlug),
|
|
54
|
+
[REDOCLY_TEAMS_RBAC]: getAllowedTeamsForRoute(config.rbac, {
|
|
55
|
+
slug: pageSlug,
|
|
56
|
+
fsPath: relativePath,
|
|
57
|
+
}),
|
|
58
|
+
metadata: {
|
|
59
|
+
type: 'asyncapi',
|
|
60
|
+
title: 'AsyncAPI',
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
actions.addRoute(route);
|
|
65
|
+
actions.addRouteSharedData(route.slug, 'AsyncApiDefinition', sharedDataKey);
|
|
66
|
+
process.chdir(currentScriptLocation);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
process.chdir(currentScriptLocation);
|
|
69
|
+
console.error(e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function loadDefinitions() {
|
|
74
|
+
const definitions: Map<string, unknown> = new Map();
|
|
75
|
+
for (const relativePath of contentProvider.filesList.values()) {
|
|
76
|
+
if (!relativePath.match(/(\.ya?ml|\.json)$/)) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const contentRecord = contentProvider.loadContent<any>(relativePath, 'yaml');
|
|
82
|
+
if (contentRecord.isIgnored) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!contentRecord.parsed?.asyncapi) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
definitions.set(relativePath, contentRecord.content);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return definitions;
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
function buildGetStaticDataFn(
|
|
101
|
+
settings: AsyncApiDocsSettings,
|
|
102
|
+
pageSlug: string,
|
|
103
|
+
): GetStaticDataFn<PageRouteDetails, PageStaticData> {
|
|
104
|
+
return async function (_route, _data, _context) {
|
|
105
|
+
return {
|
|
106
|
+
props: {
|
|
107
|
+
settings: {
|
|
108
|
+
...settings,
|
|
109
|
+
baseUrlPath: withPathPrefix(pageSlug),
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|