@redocly/portal-plugin-async-api 1.0.1
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 +11 -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 +86 -0
- package/lib/plugin.js.map +1 -0
- package/lib/styles.d.ts +1 -0
- package/lib/styles.js +573 -0
- package/lib/styles.js.map +1 -0
- package/lib/template.d.ts +12 -0
- package/lib/template.js +38 -0
- package/lib/template.js.map +1 -0
- package/package.json +43 -0
- package/src/config.ts +37 -0
- package/src/plugin.ts +101 -0
- package/src/styles.tsx +573 -0
- package/src/template.tsx +69 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +12 -0
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { FromSchema } from 'json-schema-to-ts';
|
|
2
|
+
declare const asyncApiDocsSchema: {
|
|
3
|
+
readonly type: "object";
|
|
4
|
+
readonly properties: {
|
|
5
|
+
readonly schemaId: {
|
|
6
|
+
readonly type: "string";
|
|
7
|
+
};
|
|
8
|
+
readonly hideErrors: {
|
|
9
|
+
readonly type: "boolean";
|
|
10
|
+
};
|
|
11
|
+
readonly hideInfo: {
|
|
12
|
+
readonly type: "boolean";
|
|
13
|
+
};
|
|
14
|
+
readonly hideChannels: {
|
|
15
|
+
readonly type: "boolean";
|
|
16
|
+
};
|
|
17
|
+
readonly hideServers: {
|
|
18
|
+
readonly type: "boolean";
|
|
19
|
+
};
|
|
20
|
+
readonly hideMessages: {
|
|
21
|
+
readonly type: "boolean";
|
|
22
|
+
};
|
|
23
|
+
readonly hideSchemas: {
|
|
24
|
+
readonly type: "boolean";
|
|
25
|
+
};
|
|
26
|
+
readonly expandChannels: {
|
|
27
|
+
readonly type: "object";
|
|
28
|
+
readonly properties: {
|
|
29
|
+
readonly root: {
|
|
30
|
+
readonly type: "boolean";
|
|
31
|
+
};
|
|
32
|
+
readonly elements: {
|
|
33
|
+
readonly type: "boolean";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly additionalProperties: false;
|
|
37
|
+
};
|
|
38
|
+
readonly expandServers: {
|
|
39
|
+
readonly type: "object";
|
|
40
|
+
readonly properties: {
|
|
41
|
+
readonly root: {
|
|
42
|
+
readonly type: "boolean";
|
|
43
|
+
};
|
|
44
|
+
readonly elements: {
|
|
45
|
+
readonly type: "boolean";
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
readonly additionalProperties: false;
|
|
49
|
+
};
|
|
50
|
+
readonly expandMessages: {
|
|
51
|
+
readonly type: "object";
|
|
52
|
+
readonly properties: {
|
|
53
|
+
readonly root: {
|
|
54
|
+
readonly type: "boolean";
|
|
55
|
+
};
|
|
56
|
+
readonly elements: {
|
|
57
|
+
readonly type: "boolean";
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
readonly additionalProperties: false;
|
|
61
|
+
};
|
|
62
|
+
readonly expandSchemas: {
|
|
63
|
+
readonly type: "object";
|
|
64
|
+
readonly properties: {
|
|
65
|
+
readonly root: {
|
|
66
|
+
readonly type: "boolean";
|
|
67
|
+
};
|
|
68
|
+
readonly elements: {
|
|
69
|
+
readonly type: "boolean";
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
readonly additionalProperties: false;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
readonly additionalProperties: false;
|
|
76
|
+
};
|
|
77
|
+
export declare const themeConfigSchema: {
|
|
78
|
+
readonly type: "object";
|
|
79
|
+
readonly properties: {
|
|
80
|
+
readonly asyncapi: {
|
|
81
|
+
readonly type: "object";
|
|
82
|
+
readonly properties: {
|
|
83
|
+
readonly schemaId: {
|
|
84
|
+
readonly type: "string";
|
|
85
|
+
};
|
|
86
|
+
readonly hideErrors: {
|
|
87
|
+
readonly type: "boolean";
|
|
88
|
+
};
|
|
89
|
+
readonly hideInfo: {
|
|
90
|
+
readonly type: "boolean";
|
|
91
|
+
};
|
|
92
|
+
readonly hideChannels: {
|
|
93
|
+
readonly type: "boolean";
|
|
94
|
+
};
|
|
95
|
+
readonly hideServers: {
|
|
96
|
+
readonly type: "boolean";
|
|
97
|
+
};
|
|
98
|
+
readonly hideMessages: {
|
|
99
|
+
readonly type: "boolean";
|
|
100
|
+
};
|
|
101
|
+
readonly hideSchemas: {
|
|
102
|
+
readonly type: "boolean";
|
|
103
|
+
};
|
|
104
|
+
readonly expandChannels: {
|
|
105
|
+
readonly type: "object";
|
|
106
|
+
readonly properties: {
|
|
107
|
+
readonly root: {
|
|
108
|
+
readonly type: "boolean";
|
|
109
|
+
};
|
|
110
|
+
readonly elements: {
|
|
111
|
+
readonly type: "boolean";
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
readonly additionalProperties: false;
|
|
115
|
+
};
|
|
116
|
+
readonly expandServers: {
|
|
117
|
+
readonly type: "object";
|
|
118
|
+
readonly properties: {
|
|
119
|
+
readonly root: {
|
|
120
|
+
readonly type: "boolean";
|
|
121
|
+
};
|
|
122
|
+
readonly elements: {
|
|
123
|
+
readonly type: "boolean";
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
readonly additionalProperties: false;
|
|
127
|
+
};
|
|
128
|
+
readonly expandMessages: {
|
|
129
|
+
readonly type: "object";
|
|
130
|
+
readonly properties: {
|
|
131
|
+
readonly root: {
|
|
132
|
+
readonly type: "boolean";
|
|
133
|
+
};
|
|
134
|
+
readonly elements: {
|
|
135
|
+
readonly type: "boolean";
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
readonly additionalProperties: false;
|
|
139
|
+
};
|
|
140
|
+
readonly expandSchemas: {
|
|
141
|
+
readonly type: "object";
|
|
142
|
+
readonly properties: {
|
|
143
|
+
readonly root: {
|
|
144
|
+
readonly type: "boolean";
|
|
145
|
+
};
|
|
146
|
+
readonly elements: {
|
|
147
|
+
readonly type: "boolean";
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
readonly additionalProperties: false;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
readonly additionalProperties: false;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
export type AsyncApiDocsSettings = FromSchema<typeof asyncApiDocsSchema>;
|
|
158
|
+
export {};
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const expandSectionSchema = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
root: { type: 'boolean' },
|
|
5
|
+
elements: { type: 'boolean' },
|
|
6
|
+
},
|
|
7
|
+
additionalProperties: false,
|
|
8
|
+
};
|
|
9
|
+
const asyncApiDocsSchema = {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
schemaId: { type: 'string' },
|
|
13
|
+
hideErrors: { type: 'boolean' },
|
|
14
|
+
hideInfo: { type: 'boolean' },
|
|
15
|
+
hideChannels: { type: 'boolean' },
|
|
16
|
+
hideServers: { type: 'boolean' },
|
|
17
|
+
hideMessages: { type: 'boolean' },
|
|
18
|
+
hideSchemas: { type: 'boolean' },
|
|
19
|
+
expandChannels: expandSectionSchema,
|
|
20
|
+
expandServers: expandSectionSchema,
|
|
21
|
+
expandMessages: expandSectionSchema,
|
|
22
|
+
expandSchemas: expandSectionSchema,
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
};
|
|
26
|
+
export const themeConfigSchema = {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
asyncapi: asyncApiDocsSchema,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,MAAM,mBAAmB,GAAG;IAC1B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QACzB,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;KAC9B;IACD,oBAAoB,EAAE,KAAK;CACnB,CAAC;AAEX,MAAM,kBAAkB,GAAG;IACzB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC5B,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QAC/B,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QAC7B,YAAY,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QACjC,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QAChC,YAAY,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QACjC,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QAChC,cAAc,EAAE,mBAAmB;QACnC,aAAa,EAAE,mBAAmB;QAClC,cAAc,EAAE,mBAAmB;QACnC,aAAa,EAAE,mBAAmB;KACnC;IACD,oBAAoB,EAAE,KAAK;CACnB,CAAC;AAEX,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,QAAQ,EAAE,kBAAkB;KAC7B;CACO,CAAC"}
|
package/lib/plugin.d.ts
ADDED
package/lib/plugin.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// FIXME: think of a way to make these imports shorter?
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
import { slugFromRelativePath } from '@redocly/portal/dist/server/utils/paths.js';
|
|
12
|
+
import { getAllowedTeamsForRoute } from '@redocly/portal/dist/server/utils/rbac.js';
|
|
13
|
+
import { REDOCLY_TEAMS_RBAC } from '@redocly/portal/dist/shared/constants.js';
|
|
14
|
+
import { withPathPrefix } from '@redocly/portal/dist/shared/urls.js';
|
|
15
|
+
const ASYNCAPI_TEMPLATE_ID = 'asyncapi-docs';
|
|
16
|
+
const ASYNCAPI_SHARED_DATA_PREFIX = 'asyncapi-docs-';
|
|
17
|
+
export default function asyncAPIDocsPlugin() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return {
|
|
20
|
+
processContent: (contentProvider, actions) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a;
|
|
22
|
+
const asyncAPITemplateId = actions.createTemplate(ASYNCAPI_TEMPLATE_ID, '@redocly/portal-plugin-async-api/template.js');
|
|
23
|
+
const config = actions.getConfig();
|
|
24
|
+
const globalSettings = ((_a = config.theme) === null || _a === void 0 ? void 0 : _a.asyncapi) || {};
|
|
25
|
+
const definitions = loadDefinitions();
|
|
26
|
+
for (const [relativePath, parsedDefinition] of definitions) {
|
|
27
|
+
const pageSlug = slugFromRelativePath(relativePath, contentProvider);
|
|
28
|
+
const sharedDataKey = `${ASYNCAPI_SHARED_DATA_PREFIX}${relativePath}`;
|
|
29
|
+
actions.createSharedData(sharedDataKey, parsedDefinition);
|
|
30
|
+
const route = {
|
|
31
|
+
slug: pageSlug,
|
|
32
|
+
fsPath: relativePath,
|
|
33
|
+
templateId: asyncAPITemplateId,
|
|
34
|
+
getStaticData: buildGetStaticDataFn(globalSettings, pageSlug),
|
|
35
|
+
versions: contentProvider.versions.getPageVersions(relativePath, pageSlug),
|
|
36
|
+
[REDOCLY_TEAMS_RBAC]: getAllowedTeamsForRoute(config.rbac, {
|
|
37
|
+
slug: pageSlug,
|
|
38
|
+
fsPath: relativePath,
|
|
39
|
+
}),
|
|
40
|
+
metadata: {
|
|
41
|
+
type: 'asyncapi',
|
|
42
|
+
title: 'AsyncAPI',
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
actions.addRoute(route);
|
|
46
|
+
actions.addRouteSharedData(route.slug, 'AsyncApiDefinition', sharedDataKey);
|
|
47
|
+
}
|
|
48
|
+
function loadDefinitions() {
|
|
49
|
+
var _a;
|
|
50
|
+
const definitions = new Map();
|
|
51
|
+
for (const relativePath of contentProvider.filesList.values()) {
|
|
52
|
+
if (!relativePath.match(/(\.ya?ml|\.json)$/)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const contentRecord = contentProvider.loadContent(relativePath, 'yaml');
|
|
57
|
+
if (contentRecord.isIgnored) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!((_a = contentRecord.parsed) === null || _a === void 0 ? void 0 : _a.asyncapi)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
definitions.set(relativePath, contentRecord.parsed);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return definitions;
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
function buildGetStaticDataFn(settings, pageSlug) {
|
|
74
|
+
return function (_route, _data, _context) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
return {
|
|
77
|
+
props: {
|
|
78
|
+
settings: Object.assign(Object.assign({}, settings), { baseUrlPath: withPathPrefix(pageSlug) }),
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
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oB,CAC3B,QAA8B,EAC9B,QAAgB;YAEhB,OAAO,UAAgB,MAAM,EAAE,KAAK,EAAE,QAAQ;;oBAC5C,OAAO;wBACL,KAAK,EAAE;4BACL,QAAQ,kCACH,QAAQ,KACX,WAAW,EAAE,cAAc,CAAC,QAAQ,CAAC,GACtC;yBACF;qBACF,CAAC;gBACJ,CAAC;aAAA,CAAC;QACJ,CAAC;IACH,CAAC;CAAA"}
|
package/lib/styles.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const StylesProvider: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|