@redocly/cli 1.34.4 → 2.0.0-next.0
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/README.md +34 -3
- package/bin/cli.js +1 -1
- package/lib/auth/device-flow.d.ts +1 -0
- package/lib/auth/device-flow.d.ts.map +1 -0
- package/lib/auth/device-flow.js +15 -17
- package/lib/auth/device-flow.js.map +1 -0
- package/lib/auth/oauth-client.d.ts +1 -0
- package/lib/auth/oauth-client.d.ts.map +1 -0
- package/lib/auth/oauth-client.js +21 -23
- package/lib/auth/oauth-client.js.map +1 -0
- package/lib/commands/auth.d.ts +3 -5
- package/lib/commands/auth.d.ts.map +1 -0
- package/lib/commands/auth.js +19 -44
- package/lib/commands/auth.js.map +1 -0
- package/lib/commands/build-docs/index.d.ts +4 -3
- package/lib/commands/build-docs/index.d.ts.map +1 -0
- package/lib/commands/build-docs/index.js +23 -24
- package/lib/commands/build-docs/index.js.map +1 -0
- package/lib/commands/build-docs/types.d.ts +2 -1
- package/lib/commands/build-docs/types.d.ts.map +1 -0
- package/lib/commands/build-docs/types.js +2 -2
- package/lib/commands/build-docs/types.js.map +1 -0
- package/lib/commands/build-docs/utils.d.ts +3 -2
- package/lib/commands/build-docs/utils.d.ts.map +1 -0
- package/lib/commands/build-docs/utils.js +35 -37
- package/lib/commands/build-docs/utils.js.map +1 -0
- package/lib/commands/bundle.d.ts +6 -3
- package/lib/commands/bundle.d.ts.map +1 -0
- package/lib/commands/bundle.js +34 -38
- package/lib/commands/bundle.js.map +1 -0
- package/lib/commands/eject.d.ts +3 -2
- package/lib/commands/eject.d.ts.map +1 -0
- package/lib/commands/eject.js +11 -13
- package/lib/commands/eject.js.map +1 -0
- package/lib/commands/join.d.ts +4 -3
- package/lib/commands/join.d.ts.map +1 -0
- package/lib/commands/join.js +79 -81
- package/lib/commands/join.js.map +1 -0
- package/lib/commands/lint.d.ts +8 -6
- package/lib/commands/lint.d.ts.map +1 -0
- package/lib/commands/lint.js +53 -62
- package/lib/commands/lint.js.map +1 -0
- package/lib/commands/preview-project/constants.d.ts +2 -1
- package/lib/commands/preview-project/constants.d.ts.map +1 -0
- package/lib/commands/preview-project/constants.js +4 -6
- package/lib/commands/preview-project/constants.js.map +1 -0
- package/lib/commands/preview-project/index.d.ts +3 -2
- package/lib/commands/preview-project/index.d.ts.map +1 -0
- package/lib/commands/preview-project/index.js +21 -23
- package/lib/commands/preview-project/index.js.map +1 -0
- package/lib/commands/preview-project/types.d.ts +3 -2
- package/lib/commands/preview-project/types.d.ts.map +1 -0
- package/lib/commands/preview-project/types.js +2 -2
- package/lib/commands/preview-project/types.js.map +1 -0
- package/lib/commands/split/index.d.ts +4 -3
- package/lib/commands/split/index.d.ts.map +1 -0
- package/lib/commands/split/index.js +53 -57
- package/lib/commands/split/index.js.map +1 -0
- package/lib/commands/split/types.d.ts +2 -2
- package/lib/commands/split/types.d.ts.map +1 -0
- package/lib/commands/split/types.js +11 -13
- package/lib/commands/split/types.js.map +1 -0
- package/lib/commands/stats.d.ts +3 -2
- package/lib/commands/stats.d.ts.map +1 -0
- package/lib/commands/stats.js +21 -24
- package/lib/commands/stats.js.map +1 -0
- package/lib/commands/translations.d.ts +3 -2
- package/lib/commands/translations.d.ts.map +1 -0
- package/lib/commands/translations.js +11 -13
- package/lib/commands/translations.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +109 -239
- package/lib/index.js.map +1 -0
- package/lib/otel.d.ts +2 -1
- package/lib/otel.d.ts.map +1 -0
- package/lib/otel.js +22 -23
- package/lib/otel.js.map +1 -0
- package/lib/reunite/api/api-client.d.ts +4 -3
- package/lib/reunite/api/api-client.d.ts.map +1 -0
- package/lib/reunite/api/api-client.js +14 -20
- package/lib/reunite/api/api-client.js.map +1 -0
- package/lib/reunite/api/api-keys.d.ts +2 -1
- package/lib/reunite/api/api-keys.d.ts.map +1 -0
- package/lib/reunite/api/api-keys.js +4 -20
- package/lib/reunite/api/api-keys.js.map +1 -0
- package/lib/reunite/api/domains.d.ts +5 -2
- package/lib/reunite/api/domains.d.ts.map +1 -0
- package/lib/reunite/api/domains.js +6 -15
- package/lib/reunite/api/domains.js.map +1 -0
- package/lib/reunite/api/index.d.ts +4 -3
- package/lib/reunite/api/index.d.ts.map +1 -0
- package/lib/reunite/api/index.js +4 -19
- package/lib/reunite/api/index.js.map +1 -0
- package/lib/reunite/api/types.d.ts +1 -0
- package/lib/reunite/api/types.d.ts.map +1 -0
- package/lib/reunite/api/types.js +2 -2
- package/lib/reunite/api/types.js.map +1 -0
- package/lib/reunite/commands/push-status.d.ts +6 -5
- package/lib/reunite/commands/push-status.d.ts.map +1 -0
- package/lib/reunite/commands/push-status.js +31 -37
- package/lib/reunite/commands/push-status.js.map +1 -0
- package/lib/reunite/commands/push.d.ts +6 -6
- package/lib/reunite/commands/push.d.ts.map +1 -0
- package/lib/reunite/commands/push.js +31 -40
- package/lib/reunite/commands/push.js.map +1 -0
- package/lib/reunite/commands/utils.d.ts +4 -3
- package/lib/reunite/commands/utils.d.ts.map +1 -0
- package/lib/reunite/commands/utils.js +9 -12
- package/lib/reunite/commands/utils.js.map +1 -0
- package/lib/reunite/utils.d.ts +1 -0
- package/lib/reunite/utils.d.ts.map +1 -0
- package/lib/reunite/utils.js +2 -5
- package/lib/reunite/utils.js.map +1 -0
- package/lib/types.d.ts +15 -27
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -5
- package/lib/types.js.map +1 -0
- package/lib/utils/assert-node-version.d.ts +1 -0
- package/lib/utils/assert-node-version.d.ts.map +1 -0
- package/lib/utils/assert-node-version.js +8 -10
- package/lib/utils/assert-node-version.js.map +1 -0
- package/lib/utils/error.d.ts +4 -0
- package/lib/utils/error.d.ts.map +1 -0
- package/lib/utils/error.js +8 -0
- package/lib/utils/error.js.map +1 -0
- package/lib/utils/fetch-with-timeout.d.ts +1 -0
- package/lib/utils/fetch-with-timeout.d.ts.map +1 -0
- package/lib/utils/fetch-with-timeout.js +6 -8
- package/lib/utils/fetch-with-timeout.js.map +1 -0
- package/lib/utils/{getCommandNameFromArgs.d.ts → get-command-name-from-args.d.ts} +1 -0
- package/lib/utils/get-command-name-from-args.d.ts.map +1 -0
- package/lib/utils/get-command-name-from-args.js +4 -0
- package/lib/utils/get-command-name-from-args.js.map +1 -0
- package/lib/utils/js-utils.d.ts +1 -0
- package/lib/utils/js-utils.d.ts.map +1 -0
- package/lib/utils/js-utils.js +8 -12
- package/lib/utils/js-utils.js.map +1 -0
- package/lib/utils/miscellaneous.d.ts +9 -48
- package/lib/utils/miscellaneous.d.ts.map +1 -0
- package/lib/utils/miscellaneous.js +131 -269
- package/lib/utils/miscellaneous.js.map +1 -0
- package/lib/utils/package.d.ts +2 -0
- package/lib/utils/package.d.ts.map +1 -0
- package/lib/utils/package.js +4 -0
- package/lib/utils/package.js.map +1 -0
- package/lib/utils/platform.d.ts +1 -0
- package/lib/utils/platform.d.ts.map +1 -0
- package/lib/utils/platform.js +5 -9
- package/lib/utils/platform.js.map +1 -0
- package/lib/utils/proxy-agent.d.ts +3 -0
- package/lib/utils/proxy-agent.d.ts.map +1 -0
- package/lib/utils/proxy-agent.js +6 -0
- package/lib/utils/proxy-agent.js.map +1 -0
- package/lib/utils/spinner.d.ts +1 -0
- package/lib/utils/spinner.d.ts.map +1 -0
- package/lib/utils/spinner.js +8 -10
- package/lib/utils/spinner.js.map +1 -0
- package/lib/utils/telemetry.d.ts +40 -0
- package/lib/utils/telemetry.d.ts.map +1 -0
- package/lib/utils/telemetry.js +138 -0
- package/lib/utils/telemetry.js.map +1 -0
- package/lib/utils/update-version-notifier.d.ts +1 -1
- package/lib/utils/update-version-notifier.d.ts.map +1 -0
- package/lib/utils/update-version-notifier.js +35 -38
- package/lib/utils/update-version-notifier.js.map +1 -0
- package/lib/utils/validate-positive-number.d.ts +2 -0
- package/lib/utils/validate-positive-number.d.ts.map +1 -0
- package/lib/utils/validate-positive-number.js +13 -0
- package/lib/utils/validate-positive-number.js.map +1 -0
- package/lib/wrapper.d.ts +3 -3
- package/lib/wrapper.d.ts.map +1 -0
- package/lib/wrapper.js +39 -26
- package/lib/wrapper.js.map +1 -0
- package/package.json +16 -17
- package/CHANGELOG.md +0 -777
- package/lib/__mocks__/@redocly/openapi-core.d.ts +0 -99
- package/lib/__mocks__/@redocly/openapi-core.js +0 -84
- package/lib/__mocks__/documents.d.ts +0 -150
- package/lib/__mocks__/documents.js +0 -123
- package/lib/__mocks__/fs.d.ts +0 -8
- package/lib/__mocks__/fs.js +0 -9
- package/lib/__mocks__/perf_hooks.d.ts +0 -3
- package/lib/__mocks__/perf_hooks.js +0 -6
- package/lib/__mocks__/redoc.d.ts +0 -6
- package/lib/__mocks__/redoc.js +0 -5
- package/lib/__tests__/commands/build-docs.test.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +0 -54
- package/lib/__tests__/commands/bundle.test.d.ts +0 -1
- package/lib/__tests__/commands/bundle.test.js +0 -235
- package/lib/__tests__/commands/join.test.d.ts +0 -1
- package/lib/__tests__/commands/join.test.js +0 -274
- package/lib/__tests__/commands/lint.test.d.ts +0 -1
- package/lib/__tests__/commands/lint.test.js +0 -149
- package/lib/__tests__/commands/push-region.test.d.ts +0 -1
- package/lib/__tests__/commands/push-region.test.js +0 -90
- package/lib/__tests__/commands/push.test.d.ts +0 -1
- package/lib/__tests__/commands/push.test.js +0 -496
- package/lib/__tests__/fetch-with-timeout.test.d.ts +0 -1
- package/lib/__tests__/fetch-with-timeout.test.js +0 -64
- package/lib/__tests__/fixtures/config.d.ts +0 -21
- package/lib/__tests__/fixtures/config.js +0 -24
- package/lib/__tests__/spinner.test.d.ts +0 -1
- package/lib/__tests__/spinner.test.js +0 -43
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -651
- package/lib/__tests__/wrapper.test.d.ts +0 -1
- package/lib/__tests__/wrapper.test.js +0 -76
- package/lib/auth/__tests__/device-flow.test.d.ts +0 -1
- package/lib/auth/__tests__/device-flow.test.js +0 -62
- package/lib/auth/__tests__/oauth-client.test.d.ts +0 -1
- package/lib/auth/__tests__/oauth-client.test.js +0 -93
- package/lib/commands/preview-docs/index.d.ts +0 -12
- package/lib/commands/preview-docs/index.js +0 -127
- package/lib/commands/preview-docs/preview-server/default.hbs +0 -24
- package/lib/commands/preview-docs/preview-server/hot.js +0 -59
- package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/lib/commands/preview-docs/preview-server/preview-server.d.ts +0 -5
- package/lib/commands/preview-docs/preview-server/preview-server.js +0 -113
- package/lib/commands/preview-docs/preview-server/server.d.ts +0 -22
- package/lib/commands/preview-docs/preview-server/server.js +0 -85
- package/lib/commands/push.d.ts +0 -44
- package/lib/commands/push.js +0 -301
- package/lib/commands/split/__tests__/index.test.d.ts +0 -1
- package/lib/commands/split/__tests__/index.test.js +0 -91
- package/lib/reunite/api/__tests__/api-keys.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api-keys.test.js +0 -26
- package/lib/reunite/api/__tests__/api.client.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api.client.test.js +0 -337
- package/lib/reunite/api/__tests__/domains.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/domains.test.js +0 -32
- package/lib/reunite/commands/__tests__/push-status.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push-status.test.js +0 -563
- package/lib/reunite/commands/__tests__/push.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push.test.js +0 -315
- package/lib/reunite/commands/__tests__/utils.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/utils.test.js +0 -51
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -43
- package/lib/utils/__mocks__/miscellaneous.js +0 -24
- package/lib/utils/getCommandNameFromArgs.js +0 -6
- package/src/__mocks__/@redocly/openapi-core.ts +0 -88
- package/src/__mocks__/documents.ts +0 -124
- package/src/__mocks__/fs.ts +0 -6
- package/src/__mocks__/perf_hooks.ts +0 -3
- package/src/__mocks__/redoc.ts +0 -2
- package/src/__tests__/commands/build-docs.test.ts +0 -59
- package/src/__tests__/commands/bundle.test.ts +0 -285
- package/src/__tests__/commands/join.test.ts +0 -334
- package/src/__tests__/commands/lint.test.ts +0 -190
- package/src/__tests__/commands/push-region.test.ts +0 -104
- package/src/__tests__/commands/push.test.ts +0 -553
- package/src/__tests__/fetch-with-timeout.test.ts +0 -81
- package/src/__tests__/fixtures/config.ts +0 -21
- package/src/__tests__/fixtures/openapi.json +0 -0
- package/src/__tests__/fixtures/openapi.yaml +0 -0
- package/src/__tests__/fixtures/redocly.yaml +0 -0
- package/src/__tests__/spinner.test.ts +0 -51
- package/src/__tests__/utils.test.ts +0 -781
- package/src/__tests__/wrapper.test.ts +0 -91
- package/src/auth/__tests__/device-flow.test.ts +0 -73
- package/src/auth/__tests__/oauth-client.test.ts +0 -117
- package/src/auth/device-flow.ts +0 -175
- package/src/auth/oauth-client.ts +0 -111
- package/src/commands/auth.ts +0 -66
- package/src/commands/build-docs/index.ts +0 -55
- package/src/commands/build-docs/template.hbs +0 -23
- package/src/commands/build-docs/types.ts +0 -25
- package/src/commands/build-docs/utils.ts +0 -110
- package/src/commands/bundle.ts +0 -154
- package/src/commands/eject.ts +0 -42
- package/src/commands/join.ts +0 -794
- package/src/commands/lint.ts +0 -169
- package/src/commands/preview-docs/index.ts +0 -183
- package/src/commands/preview-docs/preview-server/default.hbs +0 -24
- package/src/commands/preview-docs/preview-server/hot.js +0 -59
- package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/src/commands/preview-docs/preview-server/preview-server.ts +0 -159
- package/src/commands/preview-docs/preview-server/server.ts +0 -92
- package/src/commands/preview-project/constants.ts +0 -23
- package/src/commands/preview-project/index.ts +0 -71
- package/src/commands/preview-project/types.ts +0 -12
- package/src/commands/push.ts +0 -470
- package/src/commands/split/__tests__/fixtures/samples.json +0 -61
- package/src/commands/split/__tests__/fixtures/spec.json +0 -70
- package/src/commands/split/__tests__/fixtures/webhooks.json +0 -85
- package/src/commands/split/__tests__/index.test.ts +0 -156
- package/src/commands/split/index.ts +0 -397
- package/src/commands/split/types.ts +0 -60
- package/src/commands/stats.ts +0 -140
- package/src/commands/translations.ts +0 -32
- package/src/custom.d.ts +0 -1
- package/src/index.ts +0 -970
- package/src/otel.ts +0 -59
- package/src/reunite/api/__tests__/api-keys.test.ts +0 -37
- package/src/reunite/api/__tests__/api.client.test.ts +0 -452
- package/src/reunite/api/__tests__/domains.test.ts +0 -41
- package/src/reunite/api/api-client.ts +0 -381
- package/src/reunite/api/api-keys.ts +0 -26
- package/src/reunite/api/domains.ts +0 -23
- package/src/reunite/api/index.ts +0 -3
- package/src/reunite/api/types.ts +0 -108
- package/src/reunite/commands/__tests__/push-status.test.ts +0 -653
- package/src/reunite/commands/__tests__/push.test.ts +0 -385
- package/src/reunite/commands/__tests__/utils.test.ts +0 -62
- package/src/reunite/commands/push-status.ts +0 -325
- package/src/reunite/commands/push.ts +0 -235
- package/src/reunite/commands/utils.ts +0 -66
- package/src/reunite/utils.ts +0 -1
- package/src/types.ts +0 -64
- package/src/utils/__mocks__/miscellaneous.ts +0 -24
- package/src/utils/assert-node-version.ts +0 -19
- package/src/utils/fetch-with-timeout.ts +0 -30
- package/src/utils/getCommandNameFromArgs.ts +0 -5
- package/src/utils/js-utils.ts +0 -24
- package/src/utils/miscellaneous.ts +0 -729
- package/src/utils/platform.ts +0 -31
- package/src/utils/spinner.ts +0 -50
- package/src/utils/update-version-notifier.ts +0 -115
- package/src/wrapper.ts +0 -77
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/src/commands/join.ts
DELETED
|
@@ -1,794 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { red, blue, yellow, green } from 'colorette';
|
|
3
|
-
import { performance } from 'perf_hooks';
|
|
4
|
-
import {
|
|
5
|
-
SpecVersion,
|
|
6
|
-
BaseResolver,
|
|
7
|
-
formatProblems,
|
|
8
|
-
getTotals,
|
|
9
|
-
detectSpec,
|
|
10
|
-
bundleDocument,
|
|
11
|
-
isRef,
|
|
12
|
-
} from '@redocly/openapi-core';
|
|
13
|
-
import { dequal } from '@redocly/openapi-core/lib/utils';
|
|
14
|
-
import {
|
|
15
|
-
getFallbackApisOrExit,
|
|
16
|
-
printExecutionTime,
|
|
17
|
-
exitWithError,
|
|
18
|
-
sortTopLevelKeysForOas,
|
|
19
|
-
getAndValidateFileExtension,
|
|
20
|
-
writeToFileByExtension,
|
|
21
|
-
} from '../utils/miscellaneous';
|
|
22
|
-
import { isObject, isString, keysOf } from '../utils/js-utils';
|
|
23
|
-
import { COMPONENTS, OPENAPI3_METHOD } from './split/types';
|
|
24
|
-
import { crawl, startsWithComponents } from './split';
|
|
25
|
-
|
|
26
|
-
import type { Document, Referenced } from '@redocly/openapi-core';
|
|
27
|
-
import type { BundleResult } from '@redocly/openapi-core/lib/bundle';
|
|
28
|
-
import type {
|
|
29
|
-
Oas3Definition,
|
|
30
|
-
Oas3_1Definition,
|
|
31
|
-
Oas3Parameter,
|
|
32
|
-
Oas3PathItem,
|
|
33
|
-
Oas3Server,
|
|
34
|
-
Oas3Tag,
|
|
35
|
-
} from '@redocly/openapi-core/lib/typings/openapi';
|
|
36
|
-
import type { StrictObject } from '@redocly/openapi-core/lib/utils';
|
|
37
|
-
import type { CommandArgs } from '../wrapper';
|
|
38
|
-
import type { VerifyConfigOptions } from '../types';
|
|
39
|
-
|
|
40
|
-
const Tags = 'tags';
|
|
41
|
-
const xTagGroups = 'x-tagGroups';
|
|
42
|
-
let potentialConflictsTotal = 0;
|
|
43
|
-
|
|
44
|
-
type JoinDocumentContext = {
|
|
45
|
-
api: string;
|
|
46
|
-
apiFilename: string;
|
|
47
|
-
apiTitle?: string;
|
|
48
|
-
tags: Oas3Tag[];
|
|
49
|
-
potentialConflicts: any;
|
|
50
|
-
tagsPrefix: string;
|
|
51
|
-
componentsPrefix: string | undefined;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export type JoinOptions = {
|
|
55
|
-
apis: string[];
|
|
56
|
-
'prefix-tags-with-info-prop'?: string;
|
|
57
|
-
'prefix-tags-with-filename'?: boolean;
|
|
58
|
-
'prefix-components-with-info-prop'?: string;
|
|
59
|
-
'without-x-tag-groups'?: boolean;
|
|
60
|
-
output?: string;
|
|
61
|
-
} & VerifyConfigOptions;
|
|
62
|
-
|
|
63
|
-
export async function handleJoin({
|
|
64
|
-
argv,
|
|
65
|
-
config,
|
|
66
|
-
version: packageVersion,
|
|
67
|
-
collectSpecData,
|
|
68
|
-
}: CommandArgs<JoinOptions>) {
|
|
69
|
-
const startedAt = performance.now();
|
|
70
|
-
|
|
71
|
-
const {
|
|
72
|
-
'prefix-components-with-info-prop': prefixComponentsWithInfoProp,
|
|
73
|
-
'prefix-tags-with-filename': prefixTagsWithFilename,
|
|
74
|
-
'prefix-tags-with-info-prop': prefixTagsWithInfoProp,
|
|
75
|
-
'without-x-tag-groups': withoutXTagGroups,
|
|
76
|
-
output,
|
|
77
|
-
} = argv;
|
|
78
|
-
|
|
79
|
-
const usedTagsOptions = [
|
|
80
|
-
prefixTagsWithFilename && 'prefix-tags-with-filename',
|
|
81
|
-
prefixTagsWithInfoProp && 'prefix-tags-with-info-prop',
|
|
82
|
-
withoutXTagGroups && 'without-x-tag-groups',
|
|
83
|
-
].filter(Boolean);
|
|
84
|
-
|
|
85
|
-
if (usedTagsOptions.length > 1) {
|
|
86
|
-
return exitWithError(
|
|
87
|
-
`You use ${yellow(usedTagsOptions.join(', '))} together.\nPlease choose only one!`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const apis = await getFallbackApisOrExit(argv.apis, config);
|
|
92
|
-
if (apis.length < 2) {
|
|
93
|
-
return exitWithError(`At least 2 APIs should be provided.`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const fileExtension = getAndValidateFileExtension(output || apis[0].path);
|
|
97
|
-
const specFilename = output || `openapi.${fileExtension}`;
|
|
98
|
-
|
|
99
|
-
const externalRefResolver = new BaseResolver(config.resolve);
|
|
100
|
-
const documents = await Promise.all(
|
|
101
|
-
apis.map(
|
|
102
|
-
({ path }) => externalRefResolver.resolveDocument(null, path, true) as Promise<Document>
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const decorators = new Set([
|
|
107
|
-
...Object.keys(config.styleguide.decorators.oas3_0),
|
|
108
|
-
...Object.keys(config.styleguide.decorators.oas3_1),
|
|
109
|
-
...Object.keys(config.styleguide.decorators.oas2),
|
|
110
|
-
]);
|
|
111
|
-
config.styleguide.skipDecorators(Array.from(decorators));
|
|
112
|
-
|
|
113
|
-
const preprocessors = new Set([
|
|
114
|
-
...Object.keys(config.styleguide.preprocessors.oas3_0),
|
|
115
|
-
...Object.keys(config.styleguide.preprocessors.oas3_1),
|
|
116
|
-
...Object.keys(config.styleguide.preprocessors.oas2),
|
|
117
|
-
]);
|
|
118
|
-
config.styleguide.skipPreprocessors(Array.from(preprocessors));
|
|
119
|
-
|
|
120
|
-
const bundleResults = await Promise.all(
|
|
121
|
-
documents.map((document) =>
|
|
122
|
-
bundleDocument({
|
|
123
|
-
document,
|
|
124
|
-
config: config.styleguide,
|
|
125
|
-
externalRefResolver: new BaseResolver(config.resolve),
|
|
126
|
-
}).catch((e) => {
|
|
127
|
-
exitWithError(`${e.message}: ${blue(document.source.absoluteRef)}`);
|
|
128
|
-
})
|
|
129
|
-
)
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
for (const { problems, bundle: document } of bundleResults as BundleResult[]) {
|
|
133
|
-
const fileTotals = getTotals(problems);
|
|
134
|
-
if (fileTotals.errors) {
|
|
135
|
-
formatProblems(problems, {
|
|
136
|
-
totals: fileTotals,
|
|
137
|
-
version: packageVersion,
|
|
138
|
-
});
|
|
139
|
-
exitWithError(
|
|
140
|
-
`❌ Errors encountered while bundling ${blue(
|
|
141
|
-
document.source.absoluteRef
|
|
142
|
-
)}: join will not proceed.`
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
let oasVersion: SpecVersion | null = null;
|
|
148
|
-
for (const document of documents) {
|
|
149
|
-
try {
|
|
150
|
-
const version = detectSpec(document.parsed);
|
|
151
|
-
collectSpecData?.(document.parsed);
|
|
152
|
-
if (version !== SpecVersion.OAS3_0 && version !== SpecVersion.OAS3_1) {
|
|
153
|
-
return exitWithError(
|
|
154
|
-
`Only OpenAPI 3.0 and OpenAPI 3.1 are supported: ${blue(document.source.absoluteRef)}.`
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
oasVersion = oasVersion ?? version;
|
|
159
|
-
if (oasVersion !== version) {
|
|
160
|
-
return exitWithError(
|
|
161
|
-
`All APIs must use the same OpenAPI version: ${blue(document.source.absoluteRef)}.`
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
} catch (e) {
|
|
165
|
-
return exitWithError(`${e.message}: ${blue(document.source.absoluteRef)}.`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const joinedDef: any = {};
|
|
170
|
-
const potentialConflicts = {
|
|
171
|
-
tags: {},
|
|
172
|
-
paths: {},
|
|
173
|
-
components: {},
|
|
174
|
-
webhooks: {},
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
addInfoSectionAndSpecVersion(documents, prefixComponentsWithInfoProp);
|
|
178
|
-
|
|
179
|
-
for (const document of documents) {
|
|
180
|
-
const openapi = document.parsed;
|
|
181
|
-
const { tags, info } = openapi;
|
|
182
|
-
const api = path.relative(process.cwd(), document.source.absoluteRef);
|
|
183
|
-
const apiFilename = getApiFilename(api);
|
|
184
|
-
const tagsPrefix = prefixTagsWithFilename
|
|
185
|
-
? apiFilename
|
|
186
|
-
: getInfoPrefix(info, prefixTagsWithInfoProp, 'tags');
|
|
187
|
-
const componentsPrefix = getInfoPrefix(info, prefixComponentsWithInfoProp, COMPONENTS);
|
|
188
|
-
|
|
189
|
-
if (openapi.hasOwnProperty('x-tagGroups')) {
|
|
190
|
-
process.stderr.write(yellow(`warning: x-tagGroups at ${blue(api)} will be skipped \n`));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const context = {
|
|
194
|
-
api,
|
|
195
|
-
apiFilename,
|
|
196
|
-
apiTitle: info?.title,
|
|
197
|
-
tags,
|
|
198
|
-
potentialConflicts,
|
|
199
|
-
tagsPrefix,
|
|
200
|
-
componentsPrefix,
|
|
201
|
-
};
|
|
202
|
-
if (tags) {
|
|
203
|
-
populateTags(context);
|
|
204
|
-
}
|
|
205
|
-
collectServers(openapi);
|
|
206
|
-
collectExternalDocs(openapi, context);
|
|
207
|
-
collectPaths(openapi, context);
|
|
208
|
-
collectComponents(openapi, context);
|
|
209
|
-
collectWebhooks(oasVersion!, openapi, context);
|
|
210
|
-
if (componentsPrefix) {
|
|
211
|
-
replace$Refs(openapi, componentsPrefix);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
iteratePotentialConflicts(potentialConflicts, withoutXTagGroups);
|
|
216
|
-
const noRefs = true;
|
|
217
|
-
|
|
218
|
-
if (potentialConflictsTotal) {
|
|
219
|
-
return exitWithError(`Please fix conflicts before running ${yellow('join')}.`);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
writeToFileByExtension(sortTopLevelKeysForOas(joinedDef), specFilename, noRefs);
|
|
223
|
-
|
|
224
|
-
printExecutionTime('join', startedAt, specFilename);
|
|
225
|
-
|
|
226
|
-
function populateTags({
|
|
227
|
-
api,
|
|
228
|
-
apiFilename,
|
|
229
|
-
apiTitle,
|
|
230
|
-
tags,
|
|
231
|
-
potentialConflicts,
|
|
232
|
-
tagsPrefix,
|
|
233
|
-
componentsPrefix,
|
|
234
|
-
}: JoinDocumentContext) {
|
|
235
|
-
if (!joinedDef.hasOwnProperty(Tags)) {
|
|
236
|
-
joinedDef[Tags] = [];
|
|
237
|
-
}
|
|
238
|
-
if (!potentialConflicts.tags.hasOwnProperty('all')) {
|
|
239
|
-
potentialConflicts.tags['all'] = {};
|
|
240
|
-
}
|
|
241
|
-
if (withoutXTagGroups && !potentialConflicts.tags.hasOwnProperty('description')) {
|
|
242
|
-
potentialConflicts.tags['description'] = {};
|
|
243
|
-
}
|
|
244
|
-
for (const tag of tags) {
|
|
245
|
-
const entrypointTagName = addPrefix(tag.name, tagsPrefix);
|
|
246
|
-
if (tag.description) {
|
|
247
|
-
tag.description = addComponentsPrefix(tag.description, componentsPrefix!);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const tagDuplicate = joinedDef.tags.find((t: Oas3Tag) => t.name === entrypointTagName);
|
|
251
|
-
|
|
252
|
-
if (tagDuplicate && withoutXTagGroups) {
|
|
253
|
-
// If tag already exist and `without-x-tag-groups` option,
|
|
254
|
-
// check if description are different for potential conflicts warning.
|
|
255
|
-
const isTagDescriptionNotEqual =
|
|
256
|
-
tag.hasOwnProperty('description') && tagDuplicate.description !== tag.description;
|
|
257
|
-
|
|
258
|
-
potentialConflicts.tags.description[entrypointTagName].push(
|
|
259
|
-
...(isTagDescriptionNotEqual ? [api] : [])
|
|
260
|
-
);
|
|
261
|
-
} else if (!tagDuplicate) {
|
|
262
|
-
// Instead add tag to joinedDef if there no duplicate;
|
|
263
|
-
tag['x-displayName'] = tag['x-displayName'] || tag.name;
|
|
264
|
-
tag.name = entrypointTagName;
|
|
265
|
-
joinedDef.tags.push(tag);
|
|
266
|
-
|
|
267
|
-
if (withoutXTagGroups) {
|
|
268
|
-
potentialConflicts.tags.description[entrypointTagName] = [api];
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (!withoutXTagGroups) {
|
|
273
|
-
const groupName = apiTitle || apiFilename;
|
|
274
|
-
createXTagGroups(groupName);
|
|
275
|
-
if (!tagDuplicate) {
|
|
276
|
-
populateXTagGroups(entrypointTagName, getIndexGroup(groupName));
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const doesEntrypointExist =
|
|
281
|
-
!potentialConflicts.tags.all[entrypointTagName] ||
|
|
282
|
-
(potentialConflicts.tags.all[entrypointTagName] &&
|
|
283
|
-
!potentialConflicts.tags.all[entrypointTagName].includes(api));
|
|
284
|
-
potentialConflicts.tags.all[entrypointTagName] = [
|
|
285
|
-
...(potentialConflicts.tags.all[entrypointTagName] || []),
|
|
286
|
-
...(!withoutXTagGroups && doesEntrypointExist ? [api] : []),
|
|
287
|
-
];
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function getIndexGroup(name: string): number {
|
|
292
|
-
return joinedDef[xTagGroups].findIndex((item: any) => item.name === name);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function createXTagGroups(name: string) {
|
|
296
|
-
if (!joinedDef.hasOwnProperty(xTagGroups)) {
|
|
297
|
-
joinedDef[xTagGroups] = [];
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (!joinedDef[xTagGroups].some((g: any) => g.name === name)) {
|
|
301
|
-
joinedDef[xTagGroups].push({ name, tags: [] });
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const indexGroup = getIndexGroup(name);
|
|
305
|
-
|
|
306
|
-
if (!joinedDef[xTagGroups][indexGroup].hasOwnProperty(Tags)) {
|
|
307
|
-
joinedDef[xTagGroups][indexGroup][Tags] = [];
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function populateXTagGroups(entrypointTagName: string, indexGroup: number) {
|
|
312
|
-
if (
|
|
313
|
-
!joinedDef[xTagGroups][indexGroup][Tags].find((t: Oas3Tag) => t.name === entrypointTagName)
|
|
314
|
-
) {
|
|
315
|
-
joinedDef[xTagGroups][indexGroup][Tags].push(entrypointTagName);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
function collectServers(openapi: Oas3Definition | Oas3_1Definition) {
|
|
320
|
-
const { servers } = openapi;
|
|
321
|
-
if (servers) {
|
|
322
|
-
if (!joinedDef.hasOwnProperty('servers')) {
|
|
323
|
-
joinedDef['servers'] = [];
|
|
324
|
-
}
|
|
325
|
-
for (const server of servers) {
|
|
326
|
-
if (!joinedDef.servers.some((s: any) => s.url === server.url)) {
|
|
327
|
-
joinedDef.servers.push(server);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function collectExternalDocs(
|
|
334
|
-
openapi: Oas3Definition | Oas3_1Definition,
|
|
335
|
-
{ api }: JoinDocumentContext
|
|
336
|
-
) {
|
|
337
|
-
const { externalDocs } = openapi;
|
|
338
|
-
if (externalDocs) {
|
|
339
|
-
if (joinedDef.hasOwnProperty('externalDocs')) {
|
|
340
|
-
process.stderr.write(
|
|
341
|
-
yellow(`warning: skip externalDocs from ${blue(path.basename(api))} \n`)
|
|
342
|
-
);
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
joinedDef['externalDocs'] = externalDocs;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function collectPaths(
|
|
350
|
-
openapi: Oas3Definition | Oas3_1Definition,
|
|
351
|
-
{
|
|
352
|
-
apiFilename,
|
|
353
|
-
apiTitle,
|
|
354
|
-
api,
|
|
355
|
-
potentialConflicts,
|
|
356
|
-
tagsPrefix,
|
|
357
|
-
componentsPrefix,
|
|
358
|
-
}: JoinDocumentContext
|
|
359
|
-
) {
|
|
360
|
-
const { paths } = openapi;
|
|
361
|
-
const operationsSet = new Set(keysOf<typeof OPENAPI3_METHOD>(OPENAPI3_METHOD));
|
|
362
|
-
if (paths) {
|
|
363
|
-
if (!joinedDef.hasOwnProperty('paths')) {
|
|
364
|
-
joinedDef['paths'] = {};
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
for (const path of keysOf(paths)) {
|
|
368
|
-
if (!joinedDef.paths.hasOwnProperty(path)) {
|
|
369
|
-
joinedDef.paths[path] = {};
|
|
370
|
-
}
|
|
371
|
-
if (!potentialConflicts.paths.hasOwnProperty(path)) {
|
|
372
|
-
potentialConflicts.paths[path] = {};
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const pathItem = paths[path] as Oas3PathItem;
|
|
376
|
-
|
|
377
|
-
for (const field of keysOf(pathItem)) {
|
|
378
|
-
if (operationsSet.has(field as OPENAPI3_METHOD)) {
|
|
379
|
-
collectPathOperation(pathItem, path, field as OPENAPI3_METHOD);
|
|
380
|
-
}
|
|
381
|
-
if (field === 'servers') {
|
|
382
|
-
collectPathServers(pathItem, path);
|
|
383
|
-
}
|
|
384
|
-
if (field === 'parameters') {
|
|
385
|
-
collectPathParameters(pathItem, path);
|
|
386
|
-
}
|
|
387
|
-
if (typeof pathItem[field] === 'string') {
|
|
388
|
-
collectPathStringFields(pathItem, path, field);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
function collectPathStringFields(
|
|
395
|
-
pathItem: Oas3PathItem,
|
|
396
|
-
path: string | number,
|
|
397
|
-
field: keyof Oas3PathItem
|
|
398
|
-
) {
|
|
399
|
-
const fieldValue = pathItem[field];
|
|
400
|
-
if (
|
|
401
|
-
joinedDef.paths[path].hasOwnProperty(field) &&
|
|
402
|
-
joinedDef.paths[path][field] !== fieldValue
|
|
403
|
-
) {
|
|
404
|
-
process.stderr.write(yellow(`warning: different ${field} values in ${path}\n`));
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
joinedDef.paths[path][field] = fieldValue;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
function collectPathServers(pathItem: Oas3PathItem, path: string | number) {
|
|
411
|
-
if (!pathItem.servers) {
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
if (!joinedDef.paths[path].hasOwnProperty('servers')) {
|
|
416
|
-
joinedDef.paths[path].servers = [];
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
for (const server of pathItem.servers) {
|
|
420
|
-
let isFoundServer = false;
|
|
421
|
-
for (const pathServer of joinedDef.paths[path].servers) {
|
|
422
|
-
if (pathServer.url === server.url) {
|
|
423
|
-
if (!isServersEqual(pathServer, server)) {
|
|
424
|
-
exitWithError(`Different server values for (${server.url}) in ${path}.`);
|
|
425
|
-
}
|
|
426
|
-
isFoundServer = true;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (!isFoundServer) {
|
|
431
|
-
joinedDef.paths[path].servers.push(server);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
function collectPathParameters(pathItem: Oas3PathItem, path: string | number) {
|
|
437
|
-
if (!pathItem.parameters) {
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
if (!joinedDef.paths[path].hasOwnProperty('parameters')) {
|
|
441
|
-
joinedDef.paths[path].parameters = [];
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
for (const parameter of pathItem.parameters as Referenced<Oas3Parameter>[]) {
|
|
445
|
-
let isFoundParameter = false;
|
|
446
|
-
|
|
447
|
-
for (const pathParameter of joinedDef.paths[path]
|
|
448
|
-
.parameters as Referenced<Oas3Parameter>[]) {
|
|
449
|
-
// Compare $ref only if both are reference objects
|
|
450
|
-
if (isRef(pathParameter) && isRef(parameter)) {
|
|
451
|
-
if (pathParameter['$ref'] === parameter['$ref']) {
|
|
452
|
-
isFoundParameter = true;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
// Compare properties only if both are reference objects
|
|
456
|
-
if (!isRef(pathParameter) && !isRef(parameter)) {
|
|
457
|
-
if (pathParameter.name === parameter.name && pathParameter.in === parameter.in) {
|
|
458
|
-
if (!dequal(pathParameter.schema, parameter.schema)) {
|
|
459
|
-
exitWithError(`Different parameter schemas for (${parameter.name}) in ${path}.`);
|
|
460
|
-
}
|
|
461
|
-
isFoundParameter = true;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
if (!isFoundParameter) {
|
|
467
|
-
joinedDef.paths[path].parameters.push(parameter);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function collectPathOperation(
|
|
473
|
-
pathItem: Oas3PathItem,
|
|
474
|
-
path: string | number,
|
|
475
|
-
operation: OPENAPI3_METHOD
|
|
476
|
-
) {
|
|
477
|
-
const pathOperation = pathItem[operation];
|
|
478
|
-
|
|
479
|
-
if (!pathOperation) {
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
joinedDef.paths[path][operation] = pathOperation;
|
|
484
|
-
potentialConflicts.paths[path][operation] = [
|
|
485
|
-
...(potentialConflicts.paths[path][operation] || []),
|
|
486
|
-
api,
|
|
487
|
-
];
|
|
488
|
-
|
|
489
|
-
const { operationId } = pathOperation;
|
|
490
|
-
|
|
491
|
-
if (operationId) {
|
|
492
|
-
if (!potentialConflicts.paths.hasOwnProperty('operationIds')) {
|
|
493
|
-
potentialConflicts.paths['operationIds'] = {};
|
|
494
|
-
}
|
|
495
|
-
potentialConflicts.paths.operationIds[operationId] = [
|
|
496
|
-
...(potentialConflicts.paths.operationIds[operationId] || []),
|
|
497
|
-
api,
|
|
498
|
-
];
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
const { tags, security } = joinedDef.paths[path][operation];
|
|
502
|
-
|
|
503
|
-
if (tags) {
|
|
504
|
-
joinedDef.paths[path][operation].tags = tags.map((tag: string) =>
|
|
505
|
-
addPrefix(tag, tagsPrefix)
|
|
506
|
-
);
|
|
507
|
-
populateTags({
|
|
508
|
-
api,
|
|
509
|
-
apiFilename,
|
|
510
|
-
apiTitle,
|
|
511
|
-
tags: formatTags(tags),
|
|
512
|
-
potentialConflicts,
|
|
513
|
-
tagsPrefix,
|
|
514
|
-
componentsPrefix,
|
|
515
|
-
});
|
|
516
|
-
} else {
|
|
517
|
-
joinedDef.paths[path][operation]['tags'] = [addPrefix('other', tagsPrefix || apiFilename)];
|
|
518
|
-
populateTags({
|
|
519
|
-
api,
|
|
520
|
-
apiFilename,
|
|
521
|
-
apiTitle,
|
|
522
|
-
tags: formatTags(['other']),
|
|
523
|
-
potentialConflicts,
|
|
524
|
-
tagsPrefix: tagsPrefix || apiFilename,
|
|
525
|
-
componentsPrefix,
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
if (!security && openapi.hasOwnProperty('security')) {
|
|
529
|
-
joinedDef.paths[path][operation]['security'] = addSecurityPrefix(
|
|
530
|
-
openapi.security,
|
|
531
|
-
componentsPrefix!
|
|
532
|
-
);
|
|
533
|
-
} else if (pathOperation.security) {
|
|
534
|
-
joinedDef.paths[path][operation].security = addSecurityPrefix(
|
|
535
|
-
pathOperation.security,
|
|
536
|
-
componentsPrefix!
|
|
537
|
-
);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
function isServersEqual(serverOne: Oas3Server, serverTwo: Oas3Server) {
|
|
543
|
-
if (serverOne.description === serverTwo.description) {
|
|
544
|
-
return dequal(serverOne.variables, serverTwo.variables);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
return false;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
function collectComponents(
|
|
551
|
-
openapi: Oas3Definition,
|
|
552
|
-
{ api, potentialConflicts, componentsPrefix }: JoinDocumentContext
|
|
553
|
-
) {
|
|
554
|
-
const { components } = openapi;
|
|
555
|
-
if (components) {
|
|
556
|
-
if (!joinedDef.hasOwnProperty(COMPONENTS)) {
|
|
557
|
-
joinedDef[COMPONENTS] = {};
|
|
558
|
-
}
|
|
559
|
-
for (const [component, componentObj] of Object.entries(components)) {
|
|
560
|
-
if (!potentialConflicts[COMPONENTS].hasOwnProperty(component)) {
|
|
561
|
-
potentialConflicts[COMPONENTS][component] = {};
|
|
562
|
-
joinedDef[COMPONENTS][component] = {};
|
|
563
|
-
}
|
|
564
|
-
for (const item of Object.keys(componentObj)) {
|
|
565
|
-
const componentPrefix = addPrefix(item, componentsPrefix!);
|
|
566
|
-
potentialConflicts.components[component][componentPrefix] = [
|
|
567
|
-
...(potentialConflicts.components[component][item] || []),
|
|
568
|
-
{ [api]: componentObj[item] },
|
|
569
|
-
];
|
|
570
|
-
joinedDef.components[component][componentPrefix] = componentObj[item];
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
function collectWebhooks(
|
|
577
|
-
oasVersion: SpecVersion,
|
|
578
|
-
openapi: StrictObject<Oas3Definition | Oas3_1Definition>,
|
|
579
|
-
{
|
|
580
|
-
apiFilename,
|
|
581
|
-
apiTitle,
|
|
582
|
-
api,
|
|
583
|
-
potentialConflicts,
|
|
584
|
-
tagsPrefix,
|
|
585
|
-
componentsPrefix,
|
|
586
|
-
}: JoinDocumentContext
|
|
587
|
-
) {
|
|
588
|
-
const webhooks = oasVersion === SpecVersion.OAS3_1 ? 'webhooks' : 'x-webhooks';
|
|
589
|
-
const openapiWebhooks = openapi[webhooks];
|
|
590
|
-
if (openapiWebhooks) {
|
|
591
|
-
if (!joinedDef.hasOwnProperty(webhooks)) {
|
|
592
|
-
joinedDef[webhooks] = {};
|
|
593
|
-
}
|
|
594
|
-
for (const webhook of Object.keys(openapiWebhooks)) {
|
|
595
|
-
joinedDef[webhooks][webhook] = openapiWebhooks[webhook];
|
|
596
|
-
|
|
597
|
-
if (!potentialConflicts.webhooks.hasOwnProperty(webhook)) {
|
|
598
|
-
potentialConflicts.webhooks[webhook] = {};
|
|
599
|
-
}
|
|
600
|
-
for (const operation of Object.keys(openapiWebhooks[webhook])) {
|
|
601
|
-
potentialConflicts.webhooks[webhook][operation] = [
|
|
602
|
-
...(potentialConflicts.webhooks[webhook][operation] || []),
|
|
603
|
-
api,
|
|
604
|
-
];
|
|
605
|
-
}
|
|
606
|
-
for (const operationKey of Object.keys(joinedDef[webhooks][webhook])) {
|
|
607
|
-
const { tags } = joinedDef[webhooks][webhook][operationKey];
|
|
608
|
-
if (tags) {
|
|
609
|
-
joinedDef[webhooks][webhook][operationKey].tags = tags.map((tag: string) =>
|
|
610
|
-
addPrefix(tag, tagsPrefix)
|
|
611
|
-
);
|
|
612
|
-
populateTags({
|
|
613
|
-
api,
|
|
614
|
-
apiFilename,
|
|
615
|
-
apiTitle,
|
|
616
|
-
tags: formatTags(tags),
|
|
617
|
-
potentialConflicts,
|
|
618
|
-
tagsPrefix,
|
|
619
|
-
componentsPrefix,
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
function addInfoSectionAndSpecVersion(
|
|
628
|
-
documents: any,
|
|
629
|
-
prefixComponentsWithInfoProp: string | undefined
|
|
630
|
-
) {
|
|
631
|
-
const firstApi = documents[0];
|
|
632
|
-
const openapi = firstApi.parsed;
|
|
633
|
-
const componentsPrefix = getInfoPrefix(openapi.info, prefixComponentsWithInfoProp, COMPONENTS);
|
|
634
|
-
if (!openapi.openapi) exitWithError('Version of specification is not found.');
|
|
635
|
-
if (!openapi.info) exitWithError('Info section is not found in specification.');
|
|
636
|
-
if (openapi.info?.description) {
|
|
637
|
-
openapi.info.description = addComponentsPrefix(openapi.info.description, componentsPrefix);
|
|
638
|
-
}
|
|
639
|
-
joinedDef.openapi = openapi.openapi;
|
|
640
|
-
joinedDef.info = openapi.info;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
function doesComponentsDiffer(curr: object, next: object) {
|
|
645
|
-
return !dequal(Object.values(curr)[0], Object.values(next)[0]);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
function validateComponentsDifference(files: any) {
|
|
649
|
-
let isDiffer = false;
|
|
650
|
-
for (let i = 0, len = files.length; i < len; i++) {
|
|
651
|
-
const next = files[i + 1];
|
|
652
|
-
if (next && doesComponentsDiffer(files[i], next)) {
|
|
653
|
-
isDiffer = true;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
return isDiffer;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
function iteratePotentialConflicts(potentialConflicts: any, withoutXTagGroups?: boolean) {
|
|
660
|
-
for (const group of Object.keys(potentialConflicts)) {
|
|
661
|
-
for (const [key, value] of Object.entries(potentialConflicts[group])) {
|
|
662
|
-
const conflicts = filterConflicts(value as object);
|
|
663
|
-
if (conflicts.length) {
|
|
664
|
-
if (group === COMPONENTS) {
|
|
665
|
-
for (const [_, conflict] of Object.entries(conflicts)) {
|
|
666
|
-
if (validateComponentsDifference(conflict[1])) {
|
|
667
|
-
conflict[1] = conflict[1].map((c: string) => Object.keys(c)[0]);
|
|
668
|
-
showConflicts(green(group) + ' => ' + key, [conflict]);
|
|
669
|
-
potentialConflictsTotal += 1;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
} else {
|
|
673
|
-
if (withoutXTagGroups && group === 'tags') {
|
|
674
|
-
duplicateTagDescriptionWarning(conflicts);
|
|
675
|
-
} else {
|
|
676
|
-
potentialConflictsTotal += conflicts.length;
|
|
677
|
-
showConflicts(green(group) + ' => ' + key, conflicts);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
if (group === 'tags' && !withoutXTagGroups) {
|
|
682
|
-
prefixTagSuggestion(conflicts.length);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
function duplicateTagDescriptionWarning(conflicts: [string, any][]) {
|
|
690
|
-
const tagsKeys = conflicts.map(([tagName]) => `\`${tagName}\``);
|
|
691
|
-
const joinString = yellow(', ');
|
|
692
|
-
process.stderr.write(
|
|
693
|
-
yellow(
|
|
694
|
-
`\nwarning: ${tagsKeys.length} conflict(s) on the ${red(
|
|
695
|
-
tagsKeys.join(joinString)
|
|
696
|
-
)} tags description.\n`
|
|
697
|
-
)
|
|
698
|
-
);
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
function prefixTagSuggestion(conflictsLength: number) {
|
|
702
|
-
process.stderr.write(
|
|
703
|
-
green(
|
|
704
|
-
`\n${conflictsLength} conflict(s) on tags.\nSuggestion: please use ${blue(
|
|
705
|
-
'prefix-tags-with-filename'
|
|
706
|
-
)}, ${blue('prefix-tags-with-info-prop')} or ${blue(
|
|
707
|
-
'without-x-tag-groups'
|
|
708
|
-
)} to prevent naming conflicts.\n\n`
|
|
709
|
-
)
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
function showConflicts(key: string, conflicts: any) {
|
|
714
|
-
for (const [path, files] of conflicts) {
|
|
715
|
-
process.stderr.write(yellow(`Conflict on ${key} : ${red(path)} in files: ${blue(files)} \n`));
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
function filterConflicts(entities: object) {
|
|
720
|
-
return Object.entries(entities).filter(([_, files]) => files.length > 1);
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
function getApiFilename(filePath: string) {
|
|
724
|
-
return path.basename(filePath, path.extname(filePath));
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
function addPrefix(tag: string, tagsPrefix: string) {
|
|
728
|
-
return tagsPrefix ? tagsPrefix + '_' + tag : tag;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
function formatTags(tags: string[]) {
|
|
732
|
-
return tags.map((tag: string) => ({ name: tag }));
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
function addComponentsPrefix(description: string, componentsPrefix: string) {
|
|
736
|
-
return description.replace(/"(#\/components\/.*?)"/g, (match) => {
|
|
737
|
-
const componentName = path.basename(match);
|
|
738
|
-
return match.replace(componentName, addPrefix(componentName, componentsPrefix));
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
function addSecurityPrefix(security: any, componentsPrefix: string) {
|
|
743
|
-
return componentsPrefix
|
|
744
|
-
? security?.map((s: any) => {
|
|
745
|
-
const joinedSecuritySchema = {};
|
|
746
|
-
for (const [key, value] of Object.entries(s)) {
|
|
747
|
-
Object.assign(joinedSecuritySchema, { [componentsPrefix + '_' + key]: value });
|
|
748
|
-
}
|
|
749
|
-
return joinedSecuritySchema;
|
|
750
|
-
})
|
|
751
|
-
: security;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
function getInfoPrefix(info: any, prefixArg: string | undefined, type: string) {
|
|
755
|
-
if (!prefixArg) return '';
|
|
756
|
-
if (!info) exitWithError('Info section is not found in specification.');
|
|
757
|
-
if (!info[prefixArg])
|
|
758
|
-
exitWithError(
|
|
759
|
-
`${yellow(`prefix-${type}-with-info-prop`)} argument value is not found in info section.`
|
|
760
|
-
);
|
|
761
|
-
if (!isString(info[prefixArg]))
|
|
762
|
-
exitWithError(`${yellow(`prefix-${type}-with-info-prop`)} argument value should be string.`);
|
|
763
|
-
if (info[prefixArg].length > 50)
|
|
764
|
-
exitWithError(
|
|
765
|
-
`${yellow(
|
|
766
|
-
`prefix-${type}-with-info-prop`
|
|
767
|
-
)} argument value length should not exceed 50 characters.`
|
|
768
|
-
);
|
|
769
|
-
return info[prefixArg].replaceAll(/\s/g, '_');
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
function replace$Refs(obj: unknown, componentsPrefix: string) {
|
|
773
|
-
crawl(obj, (node: Record<string, unknown>) => {
|
|
774
|
-
if (node.$ref && typeof node.$ref === 'string' && startsWithComponents(node.$ref)) {
|
|
775
|
-
const name = path.basename(node.$ref);
|
|
776
|
-
node.$ref = node.$ref.replace(name, componentsPrefix + '_' + name);
|
|
777
|
-
} else if (isObject(node.discriminator) && isObject(node.discriminator.mapping)) {
|
|
778
|
-
const { mapping } = node.discriminator;
|
|
779
|
-
for (const name of Object.keys(mapping)) {
|
|
780
|
-
const mappingPointer = mapping[name];
|
|
781
|
-
if (typeof mappingPointer === 'string' && startsWithComponents(mappingPointer)) {
|
|
782
|
-
mapping[name] = mappingPointer
|
|
783
|
-
.split('/')
|
|
784
|
-
.map((name, i, arr) => {
|
|
785
|
-
return arr.length - 1 === i && !name.includes(componentsPrefix)
|
|
786
|
-
? componentsPrefix + '_' + name
|
|
787
|
-
: name;
|
|
788
|
-
})
|
|
789
|
-
.join('/');
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
}
|