@duplojs/http 0.2.0 → 0.5.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/dist/client/getBody.cjs +22 -0
- package/dist/client/getBody.d.ts +1 -0
- package/dist/client/getBody.mjs +20 -0
- package/dist/client/hooks.cjs +79 -0
- package/dist/client/hooks.d.ts +33 -0
- package/dist/client/hooks.mjs +70 -0
- package/dist/client/httpClient.cjs +153 -0
- package/dist/client/httpClient.d.ts +60 -0
- package/dist/client/httpClient.mjs +130 -0
- package/dist/client/index.cjs +33 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.mjs +9 -0
- package/dist/client/insertParamsInPath.cjs +12 -0
- package/dist/client/insertParamsInPath.d.ts +2 -0
- package/dist/client/insertParamsInPath.mjs +10 -0
- package/dist/client/kind.cjs +9 -0
- package/dist/client/kind.d.ts +6 -0
- package/dist/client/kind.mjs +7 -0
- package/dist/client/promiseRequest.cjs +355 -0
- package/dist/client/promiseRequest.d.ts +98 -0
- package/dist/client/promiseRequest.mjs +332 -0
- package/dist/client/queryToString.cjs +25 -0
- package/dist/client/queryToString.d.ts +2 -0
- package/dist/client/queryToString.mjs +23 -0
- package/dist/client/types/ObjectCanBeEmpty.cjs +2 -0
- package/dist/client/types/ObjectCanBeEmpty.d.ts +4 -0
- package/dist/client/types/ObjectCanBeEmpty.mjs +1 -0
- package/dist/client/types/clientRequestParams.cjs +2 -0
- package/dist/client/types/clientRequestParams.d.ts +51 -0
- package/dist/client/types/clientRequestParams.mjs +1 -0
- package/dist/client/types/clientResponse.cjs +2 -0
- package/dist/client/types/clientResponse.d.ts +34 -0
- package/dist/client/types/clientResponse.mjs +1 -0
- package/dist/client/types/index.cjs +7 -0
- package/dist/client/types/index.d.ts +4 -0
- package/dist/client/types/index.mjs +4 -0
- package/dist/client/types/serverRoute.cjs +2 -0
- package/dist/client/types/serverRoute.d.ts +22 -0
- package/dist/client/types/serverRoute.mjs +1 -0
- package/dist/client/unexpectedResponseError.cjs +44 -0
- package/dist/client/unexpectedResponseError.d.ts +38 -0
- package/dist/client/unexpectedResponseError.mjs +39 -0
- package/dist/core/builders/preflight/builder.cjs +1 -0
- package/dist/core/builders/preflight/builder.d.ts +5 -1
- package/dist/core/builders/preflight/builder.mjs +1 -0
- package/dist/core/builders/preflight/process.cjs +2 -1
- package/dist/core/builders/preflight/process.d.ts +4 -2
- package/dist/core/builders/preflight/process.mjs +2 -1
- package/dist/core/builders/preflight/route.cjs +4 -0
- package/dist/core/builders/preflight/route.d.ts +9 -3
- package/dist/core/builders/preflight/route.mjs +4 -0
- package/dist/core/builders/process/builder.cjs +1 -0
- package/dist/core/builders/process/builder.d.ts +4 -1
- package/dist/core/builders/process/builder.mjs +1 -0
- package/dist/core/builders/process/checker.cjs +2 -1
- package/dist/core/builders/process/checker.d.ts +4 -2
- package/dist/core/builders/process/checker.mjs +2 -1
- package/dist/core/builders/process/cut.cjs +2 -1
- package/dist/core/builders/process/cut.d.ts +3 -1
- package/dist/core/builders/process/cut.mjs +2 -1
- package/dist/core/builders/process/extract.cjs +2 -1
- package/dist/core/builders/process/extract.d.ts +3 -1
- package/dist/core/builders/process/extract.mjs +2 -1
- package/dist/core/builders/process/index.cjs +1 -1
- package/dist/core/builders/process/index.d.ts +1 -1
- package/dist/core/builders/process/index.mjs +1 -1
- package/dist/core/builders/process/presetChecker.cjs +2 -1
- package/dist/core/builders/process/presetChecker.d.ts +3 -1
- package/dist/core/builders/process/presetChecker.mjs +2 -1
- package/dist/core/builders/process/process.cjs +2 -1
- package/dist/core/builders/process/process.d.ts +4 -2
- package/dist/core/builders/process/process.mjs +2 -1
- package/dist/core/builders/route/builder.cjs +1 -0
- package/dist/core/builders/route/builder.d.ts +4 -1
- package/dist/core/builders/route/builder.mjs +1 -0
- package/dist/core/builders/route/checker.cjs +2 -1
- package/dist/core/builders/route/checker.d.ts +4 -2
- package/dist/core/builders/route/checker.mjs +2 -1
- package/dist/core/builders/route/cut.cjs +2 -1
- package/dist/core/builders/route/cut.d.ts +3 -1
- package/dist/core/builders/route/cut.mjs +2 -1
- package/dist/core/builders/route/extract.cjs +2 -1
- package/dist/core/builders/route/extract.d.ts +3 -1
- package/dist/core/builders/route/extract.mjs +2 -1
- package/dist/core/builders/route/handler.cjs +9 -2
- package/dist/core/builders/route/handler.d.ts +3 -1
- package/dist/core/builders/route/handler.mjs +9 -2
- package/dist/core/builders/route/presetChecker.cjs +2 -1
- package/dist/core/builders/route/presetChecker.d.ts +3 -1
- package/dist/core/builders/route/presetChecker.mjs +2 -1
- package/dist/core/builders/route/process.cjs +2 -1
- package/dist/core/builders/route/process.d.ts +4 -2
- package/dist/core/builders/route/process.mjs +2 -1
- package/dist/core/functionsBuilders/route/default.cjs +10 -9
- package/dist/core/functionsBuilders/route/default.mjs +3 -2
- package/dist/core/functionsBuilders/route/hook.cjs +22 -22
- package/dist/core/functionsBuilders/route/hook.d.ts +2 -2
- package/dist/core/functionsBuilders/route/hook.mjs +2 -2
- package/dist/core/functionsBuilders/steps/create.d.ts +2 -2
- package/dist/core/functionsBuilders/steps/defaults/checkerStep.cjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/checkerStep.mjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/cutStep.cjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/cutStep.mjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/extractStep.cjs +6 -5
- package/dist/core/functionsBuilders/steps/defaults/extractStep.mjs +4 -3
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.cjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/handlerStep.mjs +3 -2
- package/dist/core/functionsBuilders/steps/defaults/processStep.cjs +5 -4
- package/dist/core/functionsBuilders/steps/defaults/processStep.mjs +3 -2
- package/dist/core/hub/defaultNotfoundHandler.cjs +1 -0
- package/dist/core/hub/defaultNotfoundHandler.d.ts +2 -1
- package/dist/core/hub/defaultNotfoundHandler.mjs +1 -0
- package/dist/core/hub/index.cjs +2 -1
- package/dist/core/hub/index.mjs +2 -1
- package/dist/core/index.cjs +43 -34
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.mjs +8 -3
- package/dist/core/metadata/base.cjs +20 -0
- package/dist/core/metadata/base.d.ts +14 -0
- package/dist/core/metadata/base.mjs +17 -0
- package/dist/core/metadata/ignoreByRouteStore.cjs +7 -0
- package/dist/core/metadata/ignoreByRouteStore.d.ts +1 -0
- package/dist/core/metadata/ignoreByRouteStore.mjs +5 -0
- package/dist/core/metadata/index.cjs +10 -0
- package/dist/core/metadata/index.d.ts +2 -0
- package/dist/core/metadata/index.mjs +2 -0
- package/dist/core/process/index.d.ts +3 -1
- package/dist/core/response/base.cjs +40 -0
- package/dist/core/response/base.d.ts +21 -0
- package/dist/core/response/base.mjs +38 -0
- package/dist/core/response/contract.cjs +2 -2
- package/dist/core/response/contract.d.ts +120 -118
- package/dist/core/response/contract.mjs +2 -2
- package/dist/core/{route/hooks/response.cjs → response/hook.cjs} +4 -3
- package/dist/core/{route/hooks/response.d.ts → response/hook.d.ts} +2 -2
- package/dist/core/{route/hooks/response.mjs → response/hook.mjs} +3 -2
- package/dist/core/response/index.cjs +9 -38
- package/dist/core/response/index.d.ts +3 -20
- package/dist/core/response/index.mjs +3 -38
- package/dist/core/response/predicted.cjs +22 -0
- package/dist/core/response/predicted.d.ts +11 -0
- package/dist/core/response/predicted.mjs +20 -0
- package/dist/core/route/{hooks/index.cjs → hooks.cjs} +2 -3
- package/dist/core/route/{hooks/index.d.ts → hooks.d.ts} +4 -4
- package/dist/core/route/{hooks/index.mjs → hooks.mjs} +2 -2
- package/dist/core/route/index.cjs +4 -4
- package/dist/core/route/index.d.ts +2 -0
- package/dist/core/route/index.mjs +1 -1
- package/dist/core/router/index.cjs +1 -0
- package/dist/core/router/index.mjs +1 -0
- package/dist/core/steps/checker.d.ts +2 -0
- package/dist/core/steps/cut.d.ts +5 -3
- package/dist/core/steps/extract.d.ts +2 -0
- package/dist/core/steps/handler.d.ts +5 -3
- package/dist/core/steps/identifier.d.ts +2 -2
- package/dist/core/steps/presetChecker.d.ts +2 -0
- package/dist/core/steps/process.d.ts +2 -0
- package/dist/core/steps/types/stepFunctionParams.d.ts +2 -2
- package/dist/core/types/forbiddenBigintDataParser.cjs +2 -0
- package/dist/core/types/forbiddenBigintDataParser.d.ts +6 -0
- package/dist/core/types/forbiddenBigintDataParser.mjs +1 -0
- package/dist/core/types/index.cjs +1 -0
- package/dist/core/types/index.d.ts +1 -0
- package/dist/core/types/index.mjs +1 -0
- package/dist/interfaces/node/createHttpServer.cjs +1 -0
- package/dist/interfaces/node/createHttpServer.d.ts +2 -1
- package/dist/interfaces/node/createHttpServer.mjs +1 -0
- package/dist/interfaces/node/hooks.cjs +16 -13
- package/dist/interfaces/node/hooks.mjs +15 -12
- package/dist/plugins/codeGenerator/{stepsToDataParser.cjs → aggregateStepContract.cjs} +8 -5
- package/dist/plugins/codeGenerator/{stepsToDataParser.d.ts → aggregateStepContract.d.ts} +1 -1
- package/dist/plugins/codeGenerator/{stepsToDataParser.mjs → aggregateStepContract.mjs} +9 -6
- package/dist/plugins/codeGenerator/index.cjs +4 -5
- package/dist/plugins/codeGenerator/index.d.ts +2 -1
- package/dist/plugins/codeGenerator/index.mjs +3 -2
- package/dist/plugins/codeGenerator/metadata.cjs +8 -0
- package/dist/plugins/codeGenerator/metadata.d.ts +1 -0
- package/dist/plugins/codeGenerator/metadata.mjs +6 -0
- package/dist/plugins/codeGenerator/plugin.cjs +1 -1
- package/dist/plugins/codeGenerator/plugin.mjs +1 -1
- package/dist/plugins/codeGenerator/routeToDataParser.cjs +11 -57
- package/dist/plugins/codeGenerator/routeToDataParser.d.ts +2 -181
- package/dist/plugins/codeGenerator/routeToDataParser.mjs +13 -56
- package/dist/plugins/openApiGenerator/aggregateStepContract.cjs +65 -0
- package/dist/plugins/openApiGenerator/aggregateStepContract.d.ts +18 -0
- package/dist/plugins/openApiGenerator/aggregateStepContract.mjs +63 -0
- package/dist/plugins/openApiGenerator/index.cjs +19 -0
- package/dist/plugins/openApiGenerator/index.d.ts +8 -0
- package/dist/plugins/openApiGenerator/index.mjs +8 -0
- package/dist/plugins/openApiGenerator/makeOpenApiPage.cjs +30 -0
- package/dist/plugins/openApiGenerator/makeOpenApiPage.d.ts +7 -0
- package/dist/plugins/openApiGenerator/makeOpenApiPage.mjs +28 -0
- package/dist/plugins/openApiGenerator/makeOpenApiRoute.cjs +15 -0
- package/dist/plugins/openApiGenerator/makeOpenApiRoute.d.ts +20 -0
- package/dist/plugins/openApiGenerator/makeOpenApiRoute.mjs +13 -0
- package/dist/plugins/openApiGenerator/metadata.cjs +8 -0
- package/dist/plugins/openApiGenerator/metadata.d.ts +1 -0
- package/dist/plugins/openApiGenerator/metadata.mjs +6 -0
- package/dist/plugins/openApiGenerator/plugin.cjs +90 -0
- package/dist/plugins/openApiGenerator/plugin.d.ts +49 -0
- package/dist/plugins/openApiGenerator/plugin.mjs +88 -0
- package/dist/plugins/openApiGenerator/routeToOpenApi.cjs +168 -0
- package/dist/plugins/openApiGenerator/routeToOpenApi.d.ts +35 -0
- package/dist/plugins/openApiGenerator/routeToOpenApi.mjs +166 -0
- package/dist/plugins/openApiGenerator/types/endpointResponse.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/endpointResponse.d.ts +19 -0
- package/dist/plugins/openApiGenerator/types/endpointResponse.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/entrypoint.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/entrypoint.d.ts +22 -0
- package/dist/plugins/openApiGenerator/types/entrypoint.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/entrypointKey.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/entrypointKey.d.ts +1 -0
- package/dist/plugins/openApiGenerator/types/entrypointKey.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/index.cjs +11 -0
- package/dist/plugins/openApiGenerator/types/index.d.ts +8 -0
- package/dist/plugins/openApiGenerator/types/index.mjs +8 -0
- package/dist/plugins/openApiGenerator/types/openApiDocument.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiDocument.d.ts +31 -0
- package/dist/plugins/openApiGenerator/types/openApiDocument.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/openApiMethod.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiMethod.d.ts +1 -0
- package/dist/plugins/openApiGenerator/types/openApiMethod.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/openApiOperation.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiOperation.d.ts +8 -0
- package/dist/plugins/openApiGenerator/types/openApiOperation.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/openApiPath.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiPath.d.ts +4 -0
- package/dist/plugins/openApiGenerator/types/openApiPath.mjs +1 -0
- package/dist/plugins/openApiGenerator/types/openApiSecuritySchema.cjs +2 -0
- package/dist/plugins/openApiGenerator/types/openApiSecuritySchema.d.ts +8 -0
- package/dist/plugins/openApiGenerator/types/openApiSecuritySchema.mjs +1 -0
- package/package.json +17 -4
- /package/dist/core/builders/process/{export.cjs → exports.cjs} +0 -0
- /package/dist/core/builders/process/{export.d.ts → exports.d.ts} +0 -0
- /package/dist/core/builders/process/{export.mjs → exports.mjs} +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../../core/steps/index.cjs');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
|
+
var metadata = require('./metadata.cjs');
|
|
6
|
+
var identifier = require('../../core/steps/identifier.cjs');
|
|
7
|
+
var process = require('../../core/steps/process.cjs');
|
|
8
|
+
var extract = require('../../core/steps/extract.cjs');
|
|
9
|
+
var presetChecker = require('../../core/steps/presetChecker.cjs');
|
|
10
|
+
var checker = require('../../core/steps/checker.cjs');
|
|
11
|
+
var cut = require('../../core/steps/cut.cjs');
|
|
12
|
+
var handler = require('../../core/steps/handler.cjs');
|
|
13
|
+
|
|
14
|
+
function aggregateStepContract(steps, params) {
|
|
15
|
+
const filteredStep = utils.A.filter(steps, (step) => utils.A.find(step.definition.metadata, metadata.IgnoreByOpenApiGeneratorMetadata.is) === undefined);
|
|
16
|
+
const processContracts = utils.pipe(filteredStep, utils.A.filter(identifier.stepIdentifier(process.processStepKind)), utils.A.filter((step) => utils.A.find(step.definition.process.definition.metadata, metadata.IgnoreByOpenApiGeneratorMetadata.is) === undefined), utils.A.map((element) => aggregateStepContract(element.definition.process.definition.steps, params)), utils.O.to({
|
|
17
|
+
entrypointContract: utils.A.map((result) => result.entrypointContract),
|
|
18
|
+
endpointContract: utils.A.flatMap((result) => result.endpointContract),
|
|
19
|
+
}));
|
|
20
|
+
const entrypointContract = utils.pipe(filteredStep, utils.A.filter(extract.extractStepKind.has), utils.A.map((extractStep) => extractStep.definition.shape), utils.A.concat(processContracts.entrypointContract), utils.A.reduce(utils.A.reduceFrom({
|
|
21
|
+
body: {},
|
|
22
|
+
headers: {},
|
|
23
|
+
params: {},
|
|
24
|
+
query: {},
|
|
25
|
+
}), ({ element: shape, lastValue, nextWithObject }) => utils.pipe(lastValue, utils.O.entries, utils.A.map(([key, accumulatorValue]) => {
|
|
26
|
+
const currentExtractDataParser = shape[key];
|
|
27
|
+
if (utils.DP.dataParserKind.has(accumulatorValue)
|
|
28
|
+
|| !currentExtractDataParser
|
|
29
|
+
|| (!utils.DP.dataParserKind.has(accumulatorValue)
|
|
30
|
+
&& utils.O.countKeys(accumulatorValue) > 1
|
|
31
|
+
&& utils.DP.dataParserKind.has(currentExtractDataParser)
|
|
32
|
+
&& !utils.DP.objectKind.has(currentExtractDataParser))) {
|
|
33
|
+
return utils.O.entry(key, accumulatorValue);
|
|
34
|
+
}
|
|
35
|
+
if (!utils.DP.dataParserKind.has(currentExtractDataParser)) {
|
|
36
|
+
return utils.O.entry(key, {
|
|
37
|
+
...accumulatorValue,
|
|
38
|
+
...currentExtractDataParser,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (utils.DP.identifier(currentExtractDataParser, utils.DP.objectKind)) {
|
|
42
|
+
return utils.O.entry(key, {
|
|
43
|
+
...accumulatorValue,
|
|
44
|
+
...currentExtractDataParser.definition.shape,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return utils.O.entry(key, currentExtractDataParser);
|
|
48
|
+
}), utils.O.fromEntries, (object) => nextWithObject(lastValue, object))));
|
|
49
|
+
const endpointContract = utils.pipe(filteredStep, utils.A.flatMap((step) => utils.P.match(step)
|
|
50
|
+
.when(process.processStepKind.has, () => [])
|
|
51
|
+
.when(extract.extractStepKind.has, ({ definition }) => definition.responseContract ?? params.defaultExtractContract)
|
|
52
|
+
.when(presetChecker.presetCheckerStepKind.has, ({ definition }) => definition.presetChecker.definition.responseContract)
|
|
53
|
+
.when(utils.hasSomeKinds([
|
|
54
|
+
checker.checkerStepKind,
|
|
55
|
+
cut.cutStepKind,
|
|
56
|
+
handler.handlerStepKind,
|
|
57
|
+
]), ({ definition }) => definition.responseContract)
|
|
58
|
+
.exhaustive()), utils.A.concat(processContracts.endpointContract));
|
|
59
|
+
return {
|
|
60
|
+
entrypointContract,
|
|
61
|
+
endpointContract,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.aggregateStepContract = aggregateStepContract;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Steps } from "../../core/steps";
|
|
2
|
+
import { DP } from "@duplojs/utils";
|
|
3
|
+
import type { ResponseCode, ResponseContract } from "../../core/response";
|
|
4
|
+
import type { EntrypointKey } from "./types";
|
|
5
|
+
export interface EndpointRouteResult {
|
|
6
|
+
code: ResponseCode;
|
|
7
|
+
information: string;
|
|
8
|
+
body: DP.DataParser;
|
|
9
|
+
}
|
|
10
|
+
export type EntrypointReduceResult = Record<EntrypointKey, DP.DataParser | Record<string, DP.DataParser>>;
|
|
11
|
+
export interface AggregateStepsResult {
|
|
12
|
+
entrypointContract: EntrypointReduceResult;
|
|
13
|
+
endpointContract: EndpointRouteResult[];
|
|
14
|
+
}
|
|
15
|
+
export interface AggregateStepsParams {
|
|
16
|
+
readonly defaultExtractContract: ResponseContract.Contract;
|
|
17
|
+
}
|
|
18
|
+
export declare function aggregateStepContract(steps: readonly Steps[], params: AggregateStepsParams): AggregateStepsResult;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import '../../core/steps/index.mjs';
|
|
2
|
+
import { A, pipe, O, DP, P, hasSomeKinds } from '@duplojs/utils';
|
|
3
|
+
import { IgnoreByOpenApiGeneratorMetadata } from './metadata.mjs';
|
|
4
|
+
import { stepIdentifier } from '../../core/steps/identifier.mjs';
|
|
5
|
+
import { processStepKind } from '../../core/steps/process.mjs';
|
|
6
|
+
import { extractStepKind } from '../../core/steps/extract.mjs';
|
|
7
|
+
import { presetCheckerStepKind } from '../../core/steps/presetChecker.mjs';
|
|
8
|
+
import { checkerStepKind } from '../../core/steps/checker.mjs';
|
|
9
|
+
import { cutStepKind } from '../../core/steps/cut.mjs';
|
|
10
|
+
import { handlerStepKind } from '../../core/steps/handler.mjs';
|
|
11
|
+
|
|
12
|
+
function aggregateStepContract(steps, params) {
|
|
13
|
+
const filteredStep = A.filter(steps, (step) => A.find(step.definition.metadata, IgnoreByOpenApiGeneratorMetadata.is) === undefined);
|
|
14
|
+
const processContracts = pipe(filteredStep, A.filter(stepIdentifier(processStepKind)), A.filter((step) => A.find(step.definition.process.definition.metadata, IgnoreByOpenApiGeneratorMetadata.is) === undefined), A.map((element) => aggregateStepContract(element.definition.process.definition.steps, params)), O.to({
|
|
15
|
+
entrypointContract: A.map((result) => result.entrypointContract),
|
|
16
|
+
endpointContract: A.flatMap((result) => result.endpointContract),
|
|
17
|
+
}));
|
|
18
|
+
const entrypointContract = pipe(filteredStep, A.filter(extractStepKind.has), A.map((extractStep) => extractStep.definition.shape), A.concat(processContracts.entrypointContract), A.reduce(A.reduceFrom({
|
|
19
|
+
body: {},
|
|
20
|
+
headers: {},
|
|
21
|
+
params: {},
|
|
22
|
+
query: {},
|
|
23
|
+
}), ({ element: shape, lastValue, nextWithObject }) => pipe(lastValue, O.entries, A.map(([key, accumulatorValue]) => {
|
|
24
|
+
const currentExtractDataParser = shape[key];
|
|
25
|
+
if (DP.dataParserKind.has(accumulatorValue)
|
|
26
|
+
|| !currentExtractDataParser
|
|
27
|
+
|| (!DP.dataParserKind.has(accumulatorValue)
|
|
28
|
+
&& O.countKeys(accumulatorValue) > 1
|
|
29
|
+
&& DP.dataParserKind.has(currentExtractDataParser)
|
|
30
|
+
&& !DP.objectKind.has(currentExtractDataParser))) {
|
|
31
|
+
return O.entry(key, accumulatorValue);
|
|
32
|
+
}
|
|
33
|
+
if (!DP.dataParserKind.has(currentExtractDataParser)) {
|
|
34
|
+
return O.entry(key, {
|
|
35
|
+
...accumulatorValue,
|
|
36
|
+
...currentExtractDataParser,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (DP.identifier(currentExtractDataParser, DP.objectKind)) {
|
|
40
|
+
return O.entry(key, {
|
|
41
|
+
...accumulatorValue,
|
|
42
|
+
...currentExtractDataParser.definition.shape,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return O.entry(key, currentExtractDataParser);
|
|
46
|
+
}), O.fromEntries, (object) => nextWithObject(lastValue, object))));
|
|
47
|
+
const endpointContract = pipe(filteredStep, A.flatMap((step) => P.match(step)
|
|
48
|
+
.when(processStepKind.has, () => [])
|
|
49
|
+
.when(extractStepKind.has, ({ definition }) => definition.responseContract ?? params.defaultExtractContract)
|
|
50
|
+
.when(presetCheckerStepKind.has, ({ definition }) => definition.presetChecker.definition.responseContract)
|
|
51
|
+
.when(hasSomeKinds([
|
|
52
|
+
checkerStepKind,
|
|
53
|
+
cutStepKind,
|
|
54
|
+
handlerStepKind,
|
|
55
|
+
]), ({ definition }) => definition.responseContract)
|
|
56
|
+
.exhaustive()), A.concat(processContracts.endpointContract));
|
|
57
|
+
return {
|
|
58
|
+
entrypointContract,
|
|
59
|
+
endpointContract,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { aggregateStepContract };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('@duplojs/data-parser-tools/toJsonSchema');
|
|
4
|
+
require('./types/index.cjs');
|
|
5
|
+
var plugin = require('./plugin.cjs');
|
|
6
|
+
var routeToOpenApi = require('./routeToOpenApi.cjs');
|
|
7
|
+
var aggregateStepContract = require('./aggregateStepContract.cjs');
|
|
8
|
+
var makeOpenApiRoute = require('./makeOpenApiRoute.cjs');
|
|
9
|
+
var makeOpenApiPage = require('./makeOpenApiPage.cjs');
|
|
10
|
+
var metadata = require('./metadata.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.openApiGeneratorPlugin = plugin.openApiGeneratorPlugin;
|
|
15
|
+
exports.routeToOpenApi = routeToOpenApi.routeToOpenApi;
|
|
16
|
+
exports.aggregateStepContract = aggregateStepContract.aggregateStepContract;
|
|
17
|
+
exports.makeOpenApiRoute = makeOpenApiRoute.makeOpenApiRoute;
|
|
18
|
+
exports.makeOpenApiPage = makeOpenApiPage.makeOpenApiPage;
|
|
19
|
+
exports.IgnoreByOpenApiGeneratorMetadata = metadata.IgnoreByOpenApiGeneratorMetadata;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "@duplojs/data-parser-tools/toJsonSchema";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export * from "./plugin";
|
|
4
|
+
export * from "./routeToOpenApi";
|
|
5
|
+
export * from "./aggregateStepContract";
|
|
6
|
+
export * from "./makeOpenApiRoute";
|
|
7
|
+
export * from "./makeOpenApiPage";
|
|
8
|
+
export * from "./metadata";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '@duplojs/data-parser-tools/toJsonSchema';
|
|
2
|
+
import './types/index.mjs';
|
|
3
|
+
export { openApiGeneratorPlugin } from './plugin.mjs';
|
|
4
|
+
export { routeToOpenApi } from './routeToOpenApi.mjs';
|
|
5
|
+
export { aggregateStepContract } from './aggregateStepContract.mjs';
|
|
6
|
+
export { makeOpenApiRoute } from './makeOpenApiRoute.mjs';
|
|
7
|
+
export { makeOpenApiPage } from './makeOpenApiPage.mjs';
|
|
8
|
+
export { IgnoreByOpenApiGeneratorMetadata } from './metadata.mjs';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function makeOpenApiPage(params) {
|
|
4
|
+
return /* html */ `
|
|
5
|
+
<!DOCTYPE html>
|
|
6
|
+
<html lang="en">
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="utf-8" />
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
10
|
+
<meta name="description" content="SwaggerUI"/>
|
|
11
|
+
<title>${params.pageTitle}</title>
|
|
12
|
+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui.css" />
|
|
13
|
+
<script src="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui-bundle.js" crossorigin></script>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<div id="swagger-ui"></div>
|
|
17
|
+
<script>
|
|
18
|
+
window.onload = () => {
|
|
19
|
+
window.ui = SwaggerUIBundle({
|
|
20
|
+
spec: ${params.openApiDocument},
|
|
21
|
+
dom_id: "#swagger-ui",
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.makeOpenApiPage = makeOpenApiPage;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function makeOpenApiPage(params) {
|
|
2
|
+
return /* html */ `
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="utf-8" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
8
|
+
<meta name="description" content="SwaggerUI"/>
|
|
9
|
+
<title>${params.pageTitle}</title>
|
|
10
|
+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui.css" />
|
|
11
|
+
<script src="https://unpkg.com/swagger-ui-dist@${params.swaggerUiVersion}/swagger-ui-bundle.js" crossorigin></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div id="swagger-ui"></div>
|
|
15
|
+
<script>
|
|
16
|
+
window.onload = () => {
|
|
17
|
+
window.ui = SwaggerUIBundle({
|
|
18
|
+
spec: ${params.openApiDocument},
|
|
19
|
+
dom_id: "#swagger-ui",
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
</script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { makeOpenApiPage };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../../core/builders/index.cjs');
|
|
4
|
+
require('../../core/response/index.cjs');
|
|
5
|
+
var utils = require('@duplojs/utils');
|
|
6
|
+
var builder = require('../../core/builders/route/builder.cjs');
|
|
7
|
+
var contract = require('../../core/response/contract.cjs');
|
|
8
|
+
|
|
9
|
+
function makeOpenApiRoute(routePath, openApiPage) {
|
|
10
|
+
return builder.useRouteBuilder("GET", routePath)
|
|
11
|
+
.handler(contract.ResponseContract.ok("swaggerUi", utils.DP.string()), (__, { response }) => response("swaggerUi", openApiPage)
|
|
12
|
+
.setHeader("content-type", "text/html"));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.makeOpenApiRoute = makeOpenApiRoute;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ResponseContract } from "../../core/response";
|
|
2
|
+
import type { RoutePath } from "../../core/route";
|
|
3
|
+
import { DP } from "@duplojs/utils";
|
|
4
|
+
export declare function makeOpenApiRoute(routePath: RoutePath, openApiPage: string): import("../../core/route").Route<{
|
|
5
|
+
readonly method: "GET";
|
|
6
|
+
readonly metadata: readonly [];
|
|
7
|
+
readonly hooks: readonly [];
|
|
8
|
+
readonly preflightSteps: readonly [];
|
|
9
|
+
readonly paths: readonly [`/${string}`];
|
|
10
|
+
readonly steps: readonly [import("../../core/steps").HandlerStep<{
|
|
11
|
+
readonly responseContract: NoInfer<ResponseContract.Contract<"200", "swaggerUi", DP.DataParserString<{
|
|
12
|
+
readonly errorMessage?: string | undefined;
|
|
13
|
+
readonly identifier?: string | undefined;
|
|
14
|
+
readonly coerce: boolean;
|
|
15
|
+
readonly checkers: readonly [];
|
|
16
|
+
}>>>;
|
|
17
|
+
theFunction(floor: {}, param: import("../../core/steps").HandlerStepFunctionParams<import("../../core/request").Request, import("../../core/response").PredictedResponse<"200", "swaggerUi", string>>): import("@duplojs/utils").MaybePromise<import("../../core/response").PredictedResponse<"200", "swaggerUi", string>>;
|
|
18
|
+
readonly metadata: readonly [];
|
|
19
|
+
}>];
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '../../core/builders/index.mjs';
|
|
2
|
+
import '../../core/response/index.mjs';
|
|
3
|
+
import { DP } from '@duplojs/utils';
|
|
4
|
+
import { useRouteBuilder } from '../../core/builders/route/builder.mjs';
|
|
5
|
+
import { ResponseContract } from '../../core/response/contract.mjs';
|
|
6
|
+
|
|
7
|
+
function makeOpenApiRoute(routePath, openApiPage) {
|
|
8
|
+
return useRouteBuilder("GET", routePath)
|
|
9
|
+
.handler(ResponseContract.ok("swaggerUi", DP.string()), (__, { response }) => response("swaggerUi", openApiPage)
|
|
10
|
+
.setHeader("content-type", "text/html"));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { makeOpenApiRoute };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../../core/metadata/index.cjs');
|
|
4
|
+
var base = require('../../core/metadata/base.cjs');
|
|
5
|
+
|
|
6
|
+
const IgnoreByOpenApiGeneratorMetadata = base.createMetadata("ignore-by-open-api-generator");
|
|
7
|
+
|
|
8
|
+
exports.IgnoreByOpenApiGeneratorMetadata = IgnoreByOpenApiGeneratorMetadata;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const IgnoreByOpenApiGeneratorMetadata: import("../../core/metadata").MetadataHandler<"ignore-by-open-api-generator", unknown>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var routeToOpenApi = require('./routeToOpenApi.cjs');
|
|
4
|
+
var utils = require('@duplojs/utils');
|
|
5
|
+
var makeOpenApiPage = require('./makeOpenApiPage.cjs');
|
|
6
|
+
var makeOpenApiRoute = require('./makeOpenApiRoute.cjs');
|
|
7
|
+
var promises = require('fs/promises');
|
|
8
|
+
|
|
9
|
+
function openApiGeneratorPlugin(pluginParams) {
|
|
10
|
+
return () => ({
|
|
11
|
+
name: "open-api-generator",
|
|
12
|
+
hooksHubLifeCycle: [
|
|
13
|
+
{
|
|
14
|
+
beforeServerBuildRoutes: async (hub) => {
|
|
15
|
+
const contextToJsonSchemaFactory = new Map();
|
|
16
|
+
const resultSchemaContext = new Map();
|
|
17
|
+
const routes = hub.aggregatesRoutes();
|
|
18
|
+
const openApiRoutes = utils.pipe(routes, utils.A.filter((route) => route.definition.method !== "OPTIONS"), utils.A.flatMap((route) => routeToOpenApi.routeToOpenApi(route, {
|
|
19
|
+
defaultExtractContract: hub.defaultExtractContract,
|
|
20
|
+
resultSchemaContext,
|
|
21
|
+
contextToJsonSchemaFactory,
|
|
22
|
+
})));
|
|
23
|
+
if (!utils.A.minElements(openApiRoutes, 1)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const paths = utils.pipe(openApiRoutes, utils.A.group((element, { output }) => output(element.path, element)), utils.O.entries, utils.A.filter((entry) => entry[1] !== undefined), utils.A.map(([path, value]) => utils.pipe(value, utils.A.group(({ method, path, ...rest }, { output }) => output(method, rest)), utils.O.entries, utils.A.filter((entry) => entry[1] !== undefined), utils.A.map(([method, value]) => utils.O.entry(method, utils.A.first(value))), utils.O.fromEntries, (value) => utils.O.entry(path, value))), utils.O.fromEntries);
|
|
27
|
+
const schemaComponents = utils.G.reduce(resultSchemaContext.values(), utils.G.reduceFrom({}), ({ lastValue, element, nextWithObject }) => nextWithObject(lastValue, element));
|
|
28
|
+
const securityScheme = utils.P.match(pluginParams.security)
|
|
29
|
+
.with({ type: "bearer" }, (security) => ({
|
|
30
|
+
type: "http",
|
|
31
|
+
scheme: "bearer",
|
|
32
|
+
bearerFormat: security.bearerFormat ?? "JWT",
|
|
33
|
+
}))
|
|
34
|
+
.with({ type: "basic" }, utils.justReturn({
|
|
35
|
+
type: "http",
|
|
36
|
+
scheme: "basic",
|
|
37
|
+
}))
|
|
38
|
+
.with({ type: "apiKey" }, (security) => ({
|
|
39
|
+
type: "apiKey",
|
|
40
|
+
name: security.paramName,
|
|
41
|
+
in: security.in,
|
|
42
|
+
}))
|
|
43
|
+
.otherwise(utils.justReturn(undefined));
|
|
44
|
+
const securitySchemeName = "auth";
|
|
45
|
+
const securitySchemes = securityScheme
|
|
46
|
+
? {
|
|
47
|
+
[securitySchemeName]: securityScheme,
|
|
48
|
+
}
|
|
49
|
+
: undefined;
|
|
50
|
+
const openApiDocument = {
|
|
51
|
+
openapi: "3.1.0",
|
|
52
|
+
info: {
|
|
53
|
+
title: pluginParams.title ?? "Swagger API",
|
|
54
|
+
version: pluginParams.version ?? "0.0.0",
|
|
55
|
+
summary: pluginParams.summary,
|
|
56
|
+
contact: pluginParams.contact,
|
|
57
|
+
license: pluginParams.license,
|
|
58
|
+
},
|
|
59
|
+
servers: pluginParams.servers,
|
|
60
|
+
paths,
|
|
61
|
+
components: {
|
|
62
|
+
schemas: schemaComponents,
|
|
63
|
+
securitySchemes,
|
|
64
|
+
},
|
|
65
|
+
security: pluginParams.security
|
|
66
|
+
? [
|
|
67
|
+
{
|
|
68
|
+
[securitySchemeName]: [],
|
|
69
|
+
},
|
|
70
|
+
]
|
|
71
|
+
: undefined,
|
|
72
|
+
};
|
|
73
|
+
const openApiDocumentString = JSON.stringify(openApiDocument, null, 2);
|
|
74
|
+
if (pluginParams.outputFilePath) {
|
|
75
|
+
await promises.writeFile(pluginParams.outputFilePath, openApiDocumentString);
|
|
76
|
+
}
|
|
77
|
+
const openApiPage = makeOpenApiPage.makeOpenApiPage({
|
|
78
|
+
openApiDocument: openApiDocumentString,
|
|
79
|
+
pageTitle: pluginParams.title ?? "Swagger API",
|
|
80
|
+
swaggerUiVersion: pluginParams.swaggerUiVersion ?? "5.31.0",
|
|
81
|
+
});
|
|
82
|
+
const openApiRoute = makeOpenApiRoute.makeOpenApiRoute(pluginParams.routePath, openApiPage);
|
|
83
|
+
return hub.register(openApiRoute);
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.openApiGeneratorPlugin = openApiGeneratorPlugin;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { HubPlugin } from "../../core/hub";
|
|
2
|
+
import type { RoutePath } from "../../core/route";
|
|
3
|
+
import type { SupportedBearerFormat } from "./types";
|
|
4
|
+
interface OpenApiSecurityOptionBearer {
|
|
5
|
+
type: "bearer";
|
|
6
|
+
bearerFormat?: SupportedBearerFormat;
|
|
7
|
+
}
|
|
8
|
+
interface OpenApiSecurityOptionApiKey {
|
|
9
|
+
type: "apiKey";
|
|
10
|
+
paramName: string;
|
|
11
|
+
in: "header" | "query" | "cookie";
|
|
12
|
+
}
|
|
13
|
+
interface OpenApiSecurityOptionBasic {
|
|
14
|
+
type: "basic";
|
|
15
|
+
}
|
|
16
|
+
export interface OpenApiGeneratorPluginParams {
|
|
17
|
+
routePath: RoutePath;
|
|
18
|
+
outputFilePath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* @default "Swagger API"
|
|
21
|
+
*/
|
|
22
|
+
title?: string;
|
|
23
|
+
/**
|
|
24
|
+
* @default "0.0.0"
|
|
25
|
+
*/
|
|
26
|
+
version?: string;
|
|
27
|
+
summary?: string;
|
|
28
|
+
contact?: {
|
|
29
|
+
name?: string;
|
|
30
|
+
email?: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
};
|
|
33
|
+
license?: {
|
|
34
|
+
name: string;
|
|
35
|
+
url?: string;
|
|
36
|
+
identifier?: string;
|
|
37
|
+
};
|
|
38
|
+
security?: OpenApiSecurityOptionBearer | OpenApiSecurityOptionApiKey | OpenApiSecurityOptionBasic;
|
|
39
|
+
servers?: {
|
|
40
|
+
url: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
}[];
|
|
43
|
+
/**
|
|
44
|
+
* @default "5.31.0"
|
|
45
|
+
*/
|
|
46
|
+
swaggerUiVersion?: string;
|
|
47
|
+
}
|
|
48
|
+
export declare function openApiGeneratorPlugin(pluginParams: OpenApiGeneratorPluginParams): () => HubPlugin;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { routeToOpenApi } from './routeToOpenApi.mjs';
|
|
2
|
+
import { pipe, A, O, G, P, justReturn } from '@duplojs/utils';
|
|
3
|
+
import { makeOpenApiPage } from './makeOpenApiPage.mjs';
|
|
4
|
+
import { makeOpenApiRoute } from './makeOpenApiRoute.mjs';
|
|
5
|
+
import { writeFile } from 'fs/promises';
|
|
6
|
+
|
|
7
|
+
function openApiGeneratorPlugin(pluginParams) {
|
|
8
|
+
return () => ({
|
|
9
|
+
name: "open-api-generator",
|
|
10
|
+
hooksHubLifeCycle: [
|
|
11
|
+
{
|
|
12
|
+
beforeServerBuildRoutes: async (hub) => {
|
|
13
|
+
const contextToJsonSchemaFactory = new Map();
|
|
14
|
+
const resultSchemaContext = new Map();
|
|
15
|
+
const routes = hub.aggregatesRoutes();
|
|
16
|
+
const openApiRoutes = pipe(routes, A.filter((route) => route.definition.method !== "OPTIONS"), A.flatMap((route) => routeToOpenApi(route, {
|
|
17
|
+
defaultExtractContract: hub.defaultExtractContract,
|
|
18
|
+
resultSchemaContext,
|
|
19
|
+
contextToJsonSchemaFactory,
|
|
20
|
+
})));
|
|
21
|
+
if (!A.minElements(openApiRoutes, 1)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const paths = pipe(openApiRoutes, A.group((element, { output }) => output(element.path, element)), O.entries, A.filter((entry) => entry[1] !== undefined), A.map(([path, value]) => pipe(value, A.group(({ method, path, ...rest }, { output }) => output(method, rest)), O.entries, A.filter((entry) => entry[1] !== undefined), A.map(([method, value]) => O.entry(method, A.first(value))), O.fromEntries, (value) => O.entry(path, value))), O.fromEntries);
|
|
25
|
+
const schemaComponents = G.reduce(resultSchemaContext.values(), G.reduceFrom({}), ({ lastValue, element, nextWithObject }) => nextWithObject(lastValue, element));
|
|
26
|
+
const securityScheme = P.match(pluginParams.security)
|
|
27
|
+
.with({ type: "bearer" }, (security) => ({
|
|
28
|
+
type: "http",
|
|
29
|
+
scheme: "bearer",
|
|
30
|
+
bearerFormat: security.bearerFormat ?? "JWT",
|
|
31
|
+
}))
|
|
32
|
+
.with({ type: "basic" }, justReturn({
|
|
33
|
+
type: "http",
|
|
34
|
+
scheme: "basic",
|
|
35
|
+
}))
|
|
36
|
+
.with({ type: "apiKey" }, (security) => ({
|
|
37
|
+
type: "apiKey",
|
|
38
|
+
name: security.paramName,
|
|
39
|
+
in: security.in,
|
|
40
|
+
}))
|
|
41
|
+
.otherwise(justReturn(undefined));
|
|
42
|
+
const securitySchemeName = "auth";
|
|
43
|
+
const securitySchemes = securityScheme
|
|
44
|
+
? {
|
|
45
|
+
[securitySchemeName]: securityScheme,
|
|
46
|
+
}
|
|
47
|
+
: undefined;
|
|
48
|
+
const openApiDocument = {
|
|
49
|
+
openapi: "3.1.0",
|
|
50
|
+
info: {
|
|
51
|
+
title: pluginParams.title ?? "Swagger API",
|
|
52
|
+
version: pluginParams.version ?? "0.0.0",
|
|
53
|
+
summary: pluginParams.summary,
|
|
54
|
+
contact: pluginParams.contact,
|
|
55
|
+
license: pluginParams.license,
|
|
56
|
+
},
|
|
57
|
+
servers: pluginParams.servers,
|
|
58
|
+
paths,
|
|
59
|
+
components: {
|
|
60
|
+
schemas: schemaComponents,
|
|
61
|
+
securitySchemes,
|
|
62
|
+
},
|
|
63
|
+
security: pluginParams.security
|
|
64
|
+
? [
|
|
65
|
+
{
|
|
66
|
+
[securitySchemeName]: [],
|
|
67
|
+
},
|
|
68
|
+
]
|
|
69
|
+
: undefined,
|
|
70
|
+
};
|
|
71
|
+
const openApiDocumentString = JSON.stringify(openApiDocument, null, 2);
|
|
72
|
+
if (pluginParams.outputFilePath) {
|
|
73
|
+
await writeFile(pluginParams.outputFilePath, openApiDocumentString);
|
|
74
|
+
}
|
|
75
|
+
const openApiPage = makeOpenApiPage({
|
|
76
|
+
openApiDocument: openApiDocumentString,
|
|
77
|
+
pageTitle: pluginParams.title ?? "Swagger API",
|
|
78
|
+
swaggerUiVersion: pluginParams.swaggerUiVersion ?? "5.31.0",
|
|
79
|
+
});
|
|
80
|
+
const openApiRoute = makeOpenApiRoute(pluginParams.routePath, openApiPage);
|
|
81
|
+
return hub.register(openApiRoute);
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { openApiGeneratorPlugin };
|