nestjs-docfy 0.2.7 → 0.3.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 +376 -0
- package/dist/attach-tag-groups.d.ts +14 -0
- package/dist/attach-tag-groups.js +24 -0
- package/dist/attach-tag-groups.js.map +1 -0
- package/dist/cli/build-openapi-patch.d.ts +45 -0
- package/dist/cli/build-openapi-patch.js +151 -0
- package/dist/cli/build-openapi-patch.js.map +1 -0
- package/dist/cli/check.d.ts +18 -0
- package/dist/cli/check.js +108 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/coverage.d.ts +15 -0
- package/dist/cli/coverage.js +34 -0
- package/dist/cli/coverage.js.map +1 -0
- package/dist/cli/eval-decorator-args.d.ts +39 -0
- package/dist/cli/eval-decorator-args.js +115 -0
- package/dist/cli/eval-decorator-args.js.map +1 -0
- package/dist/cli/extract-docs-config.d.ts +19 -0
- package/dist/cli/extract-docs-config.js +89 -0
- package/dist/cli/extract-docs-config.js.map +1 -0
- package/dist/cli/extract-methods.d.ts +13 -0
- package/dist/cli/extract-methods.js +165 -1
- package/dist/cli/extract-methods.js.map +1 -1
- package/dist/cli/generate-file.js +35 -2
- package/dist/cli/generate-file.js.map +1 -1
- package/dist/cli/index.js +355 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/lint.d.ts +33 -0
- package/dist/cli/lint.js +211 -0
- package/dist/cli/lint.js.map +1 -0
- package/dist/cli/merge-spec-patch.d.ts +57 -0
- package/dist/cli/merge-spec-patch.js +115 -0
- package/dist/cli/merge-spec-patch.js.map +1 -0
- package/dist/cli/patch-spec.d.ts +31 -0
- package/dist/cli/patch-spec.js +82 -0
- package/dist/cli/patch-spec.js.map +1 -0
- package/dist/docfy-ui.module.d.ts +48 -0
- package/dist/docfy-ui.module.js +72 -0
- package/dist/docfy-ui.module.js.map +1 -0
- package/dist/docfy.module.js +9 -5
- package/dist/docfy.module.js.map +1 -1
- package/dist/docs.d.ts +13 -0
- package/dist/docs.js +4 -0
- package/dist/docs.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/registry.d.ts +2 -1
- package/dist/registry.js +11 -1
- package/dist/registry.js.map +1 -1
- package/dist/require-ts.d.ts +32 -0
- package/dist/require-ts.js +122 -0
- package/dist/require-ts.js.map +1 -0
- package/dist/resolve-docs-path.d.ts +10 -1
- package/dist/resolve-docs-path.js +18 -2
- package/dist/resolve-docs-path.js.map +1 -1
- package/dist/resolve-source-from-stack.d.ts +35 -0
- package/dist/resolve-source-from-stack.js +153 -0
- package/dist/resolve-source-from-stack.js.map +1 -0
- package/dist/tag-group-registry.d.ts +9 -0
- package/dist/tag-group-registry.js +32 -0
- package/dist/tag-group-registry.js.map +1 -0
- package/dist/testing.js +2 -0
- package/dist/testing.js.map +1 -1
- package/dist/with-docs.decorator.js +7 -1
- package/dist/with-docs.decorator.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ControllerInfo } from './extract-methods';
|
|
2
|
+
export interface CheckIssue {
|
|
3
|
+
controllerClass: string;
|
|
4
|
+
controllerFile: string;
|
|
5
|
+
docsFile: string;
|
|
6
|
+
kind: 'missing-file' | 'undocumented-methods';
|
|
7
|
+
/** Populated when kind === 'undocumented-methods' */
|
|
8
|
+
methods?: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function getDocumentedMethods(docsFilePath: string): Set<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Checks all controllers for documentation drift:
|
|
13
|
+
* - Missing companion docs file
|
|
14
|
+
* - HTTP methods in the controller that are not present in the docs file
|
|
15
|
+
*
|
|
16
|
+
* Returns an array of issues. Empty array means everything is in sync.
|
|
17
|
+
*/
|
|
18
|
+
export declare function checkControllers(controllers: ControllerInfo[], format: 'ts' | 'js'): CheckIssue[];
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDocumentedMethods = getDocumentedMethods;
|
|
7
|
+
exports.checkControllers = checkControllers;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const scan_controllers_1 = require("./scan-controllers");
|
|
10
|
+
/**
|
|
11
|
+
* Extracts the set of method names that are present in a docs file.
|
|
12
|
+
* Matches the pattern used by generate-file: two-space indented keys followed by `: [`.
|
|
13
|
+
* e.g. findAll: [
|
|
14
|
+
* Only identifiers matching /^[$_a-zA-Z][$_a-zA-Z0-9]*$/ are accepted.
|
|
15
|
+
*/
|
|
16
|
+
const IDENTIFIER_RE = /^[$_a-zA-Z][$_a-zA-Z0-9]*$/;
|
|
17
|
+
const METHOD_BLOCK_RE = /^\s+([$_a-zA-Z][$_a-zA-Z0-9]*)\s*:\s*\[/gm;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts the text inside the `methods: { ... }` block of a docs file.
|
|
20
|
+
* Returns an empty string if the block is not found.
|
|
21
|
+
* Uses a simple brace-counter — does not parse TypeScript, but is sufficient
|
|
22
|
+
* for the generated format produced by nestjs-docfy.
|
|
23
|
+
*/
|
|
24
|
+
function extractMethodsSection(content) {
|
|
25
|
+
const methodsIdx = content.indexOf('methods:');
|
|
26
|
+
if (methodsIdx === -1)
|
|
27
|
+
return '';
|
|
28
|
+
const braceStart = content.indexOf('{', methodsIdx);
|
|
29
|
+
if (braceStart === -1)
|
|
30
|
+
return '';
|
|
31
|
+
let depth = 0;
|
|
32
|
+
for (let i = braceStart; i < content.length; i++) {
|
|
33
|
+
if (content[i] === '{')
|
|
34
|
+
depth++;
|
|
35
|
+
else if (content[i] === '}') {
|
|
36
|
+
depth--;
|
|
37
|
+
if (depth === 0)
|
|
38
|
+
return content.slice(braceStart + 1, i);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
function getDocumentedMethods(docsFilePath) {
|
|
44
|
+
let content;
|
|
45
|
+
try {
|
|
46
|
+
content = fs_1.default.readFileSync(docsFilePath, 'utf8');
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return new Set();
|
|
50
|
+
}
|
|
51
|
+
// Only scan the methods block — avoids false positives from classDecorators, etc.
|
|
52
|
+
const methodsSection = extractMethodsSection(content);
|
|
53
|
+
const documented = new Set();
|
|
54
|
+
let match;
|
|
55
|
+
METHOD_BLOCK_RE.lastIndex = 0;
|
|
56
|
+
while ((match = METHOD_BLOCK_RE.exec(methodsSection)) !== null) {
|
|
57
|
+
const name = match[1];
|
|
58
|
+
// Whitelist: only valid identifiers — prevents any crafted file from
|
|
59
|
+
// injecting unexpected names into the result set
|
|
60
|
+
if (IDENTIFIER_RE.test(name)) {
|
|
61
|
+
documented.add(name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return documented;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Checks all controllers for documentation drift:
|
|
68
|
+
* - Missing companion docs file
|
|
69
|
+
* - HTTP methods in the controller that are not present in the docs file
|
|
70
|
+
*
|
|
71
|
+
* Returns an array of issues. Empty array means everything is in sync.
|
|
72
|
+
*/
|
|
73
|
+
function checkControllers(controllers, format) {
|
|
74
|
+
const issues = [];
|
|
75
|
+
for (const ctrl of controllers) {
|
|
76
|
+
const docsFile = (0, scan_controllers_1.deriveDocsFilePath)(ctrl.filePath, format);
|
|
77
|
+
if (!ctrl.hasDocsFile) {
|
|
78
|
+
// Only report as an issue if the controller has HTTP methods worth documenting
|
|
79
|
+
const hasHttpMethods = ctrl.methods.some((m) => m.httpDecorator !== null);
|
|
80
|
+
if (hasHttpMethods) {
|
|
81
|
+
issues.push({
|
|
82
|
+
controllerClass: ctrl.className,
|
|
83
|
+
controllerFile: ctrl.filePath,
|
|
84
|
+
docsFile,
|
|
85
|
+
kind: 'missing-file',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const documented = getDocumentedMethods(docsFile);
|
|
91
|
+
const undocumented = ctrl.methods
|
|
92
|
+
.filter((m) => m.httpDecorator !== null) // only HTTP-mapped methods
|
|
93
|
+
.filter((m) => IDENTIFIER_RE.test(m.name)) // only safe identifiers
|
|
94
|
+
.filter((m) => !documented.has(m.name))
|
|
95
|
+
.map((m) => m.name);
|
|
96
|
+
if (undocumented.length > 0) {
|
|
97
|
+
issues.push({
|
|
98
|
+
controllerClass: ctrl.className,
|
|
99
|
+
controllerFile: ctrl.filePath,
|
|
100
|
+
docsFile,
|
|
101
|
+
kind: 'undocumented-methods',
|
|
102
|
+
methods: undocumented,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return issues;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/cli/check.ts"],"names":[],"mappings":";;;;;AA8CA,oDAsBC;AASD,4CA2CC;AAxHD,4CAAoB;AACpB,yDAAwD;AAYxD;;;;;GAKG;AACH,MAAM,aAAa,GAAG,4BAA4B,CAAC;AACnD,MAAM,eAAe,GAAG,2CAA2C,CAAC;AAEpE;;;;;GAKG;AACH,SAAS,qBAAqB,CAAC,OAAe;IAC5C,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,UAAU,KAAK,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAEjC,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACpD,IAAI,UAAU,KAAK,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAEjC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,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gBAC/B,cAAc,EAAE,IAAI,CAAC,QAAQ;gBAC7B,QAAQ;gBACR,IAAI,EAAE,sBAAsB;gBAC5B,OAAO,EAAE,YAAY;aACtB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ControllerInfo } from './extract-methods';
|
|
2
|
+
export interface CoverageReport {
|
|
3
|
+
totalControllers: number;
|
|
4
|
+
/** HTTP-mapped methods across all controllers */
|
|
5
|
+
totalEndpoints: number;
|
|
6
|
+
documentedEndpoints: number;
|
|
7
|
+
missingEndpoints: number;
|
|
8
|
+
/** Percentage 0–100, one decimal place. NaN when totalEndpoints === 0. */
|
|
9
|
+
coveragePercent: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Computes documentation coverage across all scanned controllers.
|
|
13
|
+
* Only HTTP-mapped methods (those with an httpDecorator) are counted.
|
|
14
|
+
*/
|
|
15
|
+
export declare function computeCoverage(controllers: ControllerInfo[], format: 'ts' | 'js'): CoverageReport;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeCoverage = computeCoverage;
|
|
4
|
+
const scan_controllers_1 = require("./scan-controllers");
|
|
5
|
+
const check_1 = require("./check");
|
|
6
|
+
/**
|
|
7
|
+
* Computes documentation coverage across all scanned controllers.
|
|
8
|
+
* Only HTTP-mapped methods (those with an httpDecorator) are counted.
|
|
9
|
+
*/
|
|
10
|
+
function computeCoverage(controllers, format) {
|
|
11
|
+
let totalEndpoints = 0;
|
|
12
|
+
let documentedEndpoints = 0;
|
|
13
|
+
for (const ctrl of controllers) {
|
|
14
|
+
const httpMethods = ctrl.methods.filter((m) => m.httpDecorator !== null);
|
|
15
|
+
totalEndpoints += httpMethods.length;
|
|
16
|
+
if (ctrl.hasDocsFile) {
|
|
17
|
+
const docsFile = (0, scan_controllers_1.deriveDocsFilePath)(ctrl.filePath, format);
|
|
18
|
+
const documented = (0, check_1.getDocumentedMethods)(docsFile);
|
|
19
|
+
documentedEndpoints += httpMethods.filter((m) => documented.has(m.name)).length;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const missingEndpoints = totalEndpoints - documentedEndpoints;
|
|
23
|
+
const coveragePercent = totalEndpoints === 0
|
|
24
|
+
? NaN
|
|
25
|
+
: Math.round((documentedEndpoints / totalEndpoints) * 1000) / 10;
|
|
26
|
+
return {
|
|
27
|
+
totalControllers: controllers.length,
|
|
28
|
+
totalEndpoints,
|
|
29
|
+
documentedEndpoints,
|
|
30
|
+
missingEndpoints,
|
|
31
|
+
coveragePercent,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=coverage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.js","sourceRoot":"","sources":["../../src/cli/coverage.ts"],"names":[],"mappings":";;AAkBA,0CA+BC;AAjDD,yDAAwD;AACxD,mCAA+C;AAa/C;;;GAGG;AACH,SAAgB,eAAe,CAC7B,WAA6B,EAC7B,MAAmB;IAEnB,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,IAAI,mBAAmB,GAAG,CAAC,CAAC;IAE5B,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,IAAI,CAAC,CAAC;QACzE,cAAc,IAAI,WAAW,CAAC,MAAM,CAAC;QAErC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,QAAQ,GAAG,IAAA,qCAAkB,EAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC3D,MAAM,UAAU,GAAG,IAAA,4BAAoB,EAAC,QAAQ,CAAC,CAAC;YAClD,mBAAmB,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;QAClF,CAAC;IACH,CAAC;IAED,MAAM,gBAAgB,GAAG,cAAc,GAAG,mBAAmB,CAAC;IAC9D,MAAM,eAAe,GACnB,cAAc,KAAK,CAAC;QAClB,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,mBAAmB,GAAG,cAAc,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAErE,OAAO;QACL,gBAAgB,EAAE,WAAW,CAAC,MAAM;QACpC,cAAc;QACd,mBAAmB;QACnB,gBAAgB;QAChB,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Node } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Marker for an expression this evaluator couldn't statically resolve to a
|
|
4
|
+
* plain value — e.g. a variable reference, a function call, a spread. The
|
|
5
|
+
* raw source text is kept so callers can decide whether to ignore it,
|
|
6
|
+
* surface a warning, or (for known patterns like `HttpStatus.CREATED`)
|
|
7
|
+
* recognize it themselves.
|
|
8
|
+
*/
|
|
9
|
+
export interface Unresolved {
|
|
10
|
+
__unresolved: true;
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
export type EvaluatedValue = string | number | boolean | null | EvaluatedValue[] | {
|
|
14
|
+
[key: string]: EvaluatedValue;
|
|
15
|
+
} | Unresolved;
|
|
16
|
+
export declare function isUnresolved(value: EvaluatedValue): value is Unresolved;
|
|
17
|
+
/**
|
|
18
|
+
* Statically evaluates a ts-morph expression node into a plain JS value,
|
|
19
|
+
* without executing any code. Handles the literal shapes that actually
|
|
20
|
+
* appear in `.docs.ts` files written by hand or generated by this tool:
|
|
21
|
+
* string/number/boolean/null literals, array and object literals, and
|
|
22
|
+
* `HttpStatus.X` member access. Anything else (variable references,
|
|
23
|
+
* function calls, spreads, computed keys) becomes an `Unresolved` marker
|
|
24
|
+
* rather than throwing — callers decide what to do with it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function evaluateExpression(node: Node): EvaluatedValue;
|
|
27
|
+
export interface DecoratorCall {
|
|
28
|
+
/** Decorator factory name, e.g. "ApiOperation". */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Each call argument, statically evaluated. */
|
|
31
|
+
args: EvaluatedValue[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Evaluates a decorator factory call expression — e.g. the `ApiOperation({
|
|
35
|
+
* summary: 'X' })` inside an array literal `[ApiOperation({...}), ApiBearerAuth()]`
|
|
36
|
+
* — into a `{ name, args }` pair. Returns null if the expression isn't a
|
|
37
|
+
* recognizable `Identifier(...)` or `Identifier.member(...)` call.
|
|
38
|
+
*/
|
|
39
|
+
export declare function evaluateDecoratorCall(node: Node): DecoratorCall | null;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUnresolved = isUnresolved;
|
|
4
|
+
exports.evaluateExpression = evaluateExpression;
|
|
5
|
+
exports.evaluateDecoratorCall = evaluateDecoratorCall;
|
|
6
|
+
const ts_morph_1 = require("ts-morph");
|
|
7
|
+
function isUnresolved(value) {
|
|
8
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) && '__unresolved' in value;
|
|
9
|
+
}
|
|
10
|
+
/** Common `HttpStatus.X` members from @nestjs/common, for ApiResponse({ status: HttpStatus.CREATED }). */
|
|
11
|
+
const HTTP_STATUS_MEMBERS = {
|
|
12
|
+
CONTINUE: 100, OK: 200, CREATED: 201, ACCEPTED: 202, NO_CONTENT: 204,
|
|
13
|
+
MOVED_PERMANENTLY: 301, FOUND: 302, NOT_MODIFIED: 304,
|
|
14
|
+
BAD_REQUEST: 400, UNAUTHORIZED: 401, FORBIDDEN: 403, NOT_FOUND: 404,
|
|
15
|
+
METHOD_NOT_ALLOWED: 405, NOT_ACCEPTABLE: 406, REQUEST_TIMEOUT: 408,
|
|
16
|
+
CONFLICT: 409, GONE: 410, PAYLOAD_TOO_LARGE: 413, UNSUPPORTED_MEDIA_TYPE: 415,
|
|
17
|
+
UNPROCESSABLE_ENTITY: 422, TOO_MANY_REQUESTS: 429,
|
|
18
|
+
INTERNAL_SERVER_ERROR: 500, NOT_IMPLEMENTED: 501, BAD_GATEWAY: 502,
|
|
19
|
+
SERVICE_UNAVAILABLE: 503, GATEWAY_TIMEOUT: 504,
|
|
20
|
+
};
|
|
21
|
+
function unresolved(node) {
|
|
22
|
+
return { __unresolved: true, text: node.getText() };
|
|
23
|
+
}
|
|
24
|
+
function stripQuotes(text) {
|
|
25
|
+
return text.replace(/^['"`]/, '').replace(/['"`]$/, '');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Statically evaluates a ts-morph expression node into a plain JS value,
|
|
29
|
+
* without executing any code. Handles the literal shapes that actually
|
|
30
|
+
* appear in `.docs.ts` files written by hand or generated by this tool:
|
|
31
|
+
* string/number/boolean/null literals, array and object literals, and
|
|
32
|
+
* `HttpStatus.X` member access. Anything else (variable references,
|
|
33
|
+
* function calls, spreads, computed keys) becomes an `Unresolved` marker
|
|
34
|
+
* rather than throwing — callers decide what to do with it.
|
|
35
|
+
*/
|
|
36
|
+
function evaluateExpression(node) {
|
|
37
|
+
switch (node.getKind()) {
|
|
38
|
+
case ts_morph_1.SyntaxKind.StringLiteral:
|
|
39
|
+
case ts_morph_1.SyntaxKind.NoSubstitutionTemplateLiteral:
|
|
40
|
+
return stripQuotes(node.getText());
|
|
41
|
+
case ts_morph_1.SyntaxKind.NumericLiteral:
|
|
42
|
+
return Number(node.getText());
|
|
43
|
+
case ts_morph_1.SyntaxKind.TrueKeyword:
|
|
44
|
+
return true;
|
|
45
|
+
case ts_morph_1.SyntaxKind.FalseKeyword:
|
|
46
|
+
return false;
|
|
47
|
+
case ts_morph_1.SyntaxKind.NullKeyword:
|
|
48
|
+
return null;
|
|
49
|
+
case ts_morph_1.SyntaxKind.PrefixUnaryExpression: {
|
|
50
|
+
// Handles negative numeric literals, e.g. `-1`.
|
|
51
|
+
const text = node.getText();
|
|
52
|
+
const asNumber = Number(text);
|
|
53
|
+
return Number.isFinite(asNumber) ? asNumber : unresolved(node);
|
|
54
|
+
}
|
|
55
|
+
case ts_morph_1.SyntaxKind.ArrayLiteralExpression: {
|
|
56
|
+
const elements = node.asKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression).getElements();
|
|
57
|
+
return elements.map((el) => evaluateExpression(el));
|
|
58
|
+
}
|
|
59
|
+
case ts_morph_1.SyntaxKind.ObjectLiteralExpression: {
|
|
60
|
+
const result = {};
|
|
61
|
+
const props = node.asKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression).getProperties();
|
|
62
|
+
for (const prop of props) {
|
|
63
|
+
if (prop.getKind() === ts_morph_1.SyntaxKind.PropertyAssignment) {
|
|
64
|
+
const pa = prop.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAssignment);
|
|
65
|
+
const key = pa.getName();
|
|
66
|
+
const initializer = pa.getInitializer();
|
|
67
|
+
result[key] = initializer ? evaluateExpression(initializer) : unresolved(prop);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// ShorthandPropertyAssignment, SpreadAssignment, MethodDeclaration, computed keys —
|
|
71
|
+
// none of these can be resolved without executing code.
|
|
72
|
+
const name = 'getName' in prop && typeof prop.getName === 'function' ? prop.getName() : '?';
|
|
73
|
+
result[name] = unresolved(prop);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
case ts_morph_1.SyntaxKind.PropertyAccessExpression: {
|
|
79
|
+
const pae = node.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
80
|
+
const objectText = pae.getExpression().getText();
|
|
81
|
+
const memberName = pae.getName();
|
|
82
|
+
if (objectText === 'HttpStatus' && memberName in HTTP_STATUS_MEMBERS) {
|
|
83
|
+
return HTTP_STATUS_MEMBERS[memberName];
|
|
84
|
+
}
|
|
85
|
+
return unresolved(node);
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
return unresolved(node);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Evaluates a decorator factory call expression — e.g. the `ApiOperation({
|
|
93
|
+
* summary: 'X' })` inside an array literal `[ApiOperation({...}), ApiBearerAuth()]`
|
|
94
|
+
* — into a `{ name, args }` pair. Returns null if the expression isn't a
|
|
95
|
+
* recognizable `Identifier(...)` or `Identifier.member(...)` call.
|
|
96
|
+
*/
|
|
97
|
+
function evaluateDecoratorCall(node) {
|
|
98
|
+
if (node.getKind() !== ts_morph_1.SyntaxKind.CallExpression)
|
|
99
|
+
return null;
|
|
100
|
+
const call = node.asKindOrThrow(ts_morph_1.SyntaxKind.CallExpression);
|
|
101
|
+
const expr = call.getExpression();
|
|
102
|
+
let name;
|
|
103
|
+
if (expr.getKind() === ts_morph_1.SyntaxKind.Identifier) {
|
|
104
|
+
name = expr.getText();
|
|
105
|
+
}
|
|
106
|
+
else if (expr.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
107
|
+
name = expr.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression).getName();
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const args = call.getArguments().map((arg) => evaluateExpression(arg));
|
|
113
|
+
return { name, args };
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=eval-decorator-args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval-decorator-args.js","sourceRoot":"","sources":["../../src/cli/eval-decorator-args.ts"],"names":[],"mappings":";;AAuBA,oCAEC;AA+BD,gDA8DC;AAeD,sDAg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AAC;QAED;YACE,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC;AASD;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,IAAU;IAC9C,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,qBAAU,CAAC,cAAc;QAAE,OAAO,IAAI,CAAC;IAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,qBAAU,CAAC,cAAc,CAAC,CAAC;IAE3D,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IAClC,IAAI,IAAY,CAAC;IACjB,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,qBAAU,CAAC,UAAU,EAAE,CAAC;QAC7C,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;SAAM,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,qBAAU,CAAC,wBAAwB,EAAE,CAAC;QAClE,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,qBAAU,CAAC,wBAAwB,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3E,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;IACvE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DecoratorCall } from './eval-decorator-args';
|
|
2
|
+
export interface ExtractedDocsConfig {
|
|
3
|
+
classDecorators: DecoratorCall[];
|
|
4
|
+
methods: Record<string, DecoratorCall[]>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Statically extracts the `docs(ControllerClass, { classDecorators, methods })`
|
|
8
|
+
* call from a `.controller.docs.ts` file's source text — without executing
|
|
9
|
+
* it. Used to compute an OpenAPI patch directly from the file (see
|
|
10
|
+
* build-openapi-patch.ts), bypassing the runtime require()/Reflect-metadata
|
|
11
|
+
* pipeline entirely. That's the whole point: this works under any build
|
|
12
|
+
* mode, including NestJS CLI's `webpack: true`, because it never requires
|
|
13
|
+
* the file, never touches require.cache, and never needs a live reference
|
|
14
|
+
* to the same class object the running app uses (see the README's "Not
|
|
15
|
+
* supported: webpack: true" section for why the runtime pipeline can't).
|
|
16
|
+
*
|
|
17
|
+
* Returns null if the file can't be parsed or no `docs(...)` call is found.
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractDocsConfig(sourceText: string): ExtractedDocsConfig | null;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractDocsConfig = extractDocsConfig;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const eval_decorator_args_1 = require("./eval-decorator-args");
|
|
6
|
+
/**
|
|
7
|
+
* Statically extracts the `docs(ControllerClass, { classDecorators, methods })`
|
|
8
|
+
* call from a `.controller.docs.ts` file's source text — without executing
|
|
9
|
+
* it. Used to compute an OpenAPI patch directly from the file (see
|
|
10
|
+
* build-openapi-patch.ts), bypassing the runtime require()/Reflect-metadata
|
|
11
|
+
* pipeline entirely. That's the whole point: this works under any build
|
|
12
|
+
* mode, including NestJS CLI's `webpack: true`, because it never requires
|
|
13
|
+
* the file, never touches require.cache, and never needs a live reference
|
|
14
|
+
* to the same class object the running app uses (see the README's "Not
|
|
15
|
+
* supported: webpack: true" section for why the runtime pipeline can't).
|
|
16
|
+
*
|
|
17
|
+
* Returns null if the file can't be parsed or no `docs(...)` call is found.
|
|
18
|
+
*/
|
|
19
|
+
function extractDocsConfig(sourceText) {
|
|
20
|
+
let project;
|
|
21
|
+
try {
|
|
22
|
+
project = new ts_morph_1.Project({ useInMemoryFileSystem: true, skipFileDependencyResolution: true });
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
let sf;
|
|
28
|
+
try {
|
|
29
|
+
sf = project.createSourceFile('docs.ts', sourceText);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const docsCall = sf.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression).find((call) => {
|
|
35
|
+
try {
|
|
36
|
+
return call.getExpression().getText() === 'docs';
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (!docsCall)
|
|
43
|
+
return null;
|
|
44
|
+
const args = docsCall.getArguments();
|
|
45
|
+
if (args.length < 2)
|
|
46
|
+
return null;
|
|
47
|
+
const configArg = args[1];
|
|
48
|
+
if (configArg.getKind() !== ts_morph_1.SyntaxKind.ObjectLiteralExpression)
|
|
49
|
+
return null;
|
|
50
|
+
const configObj = configArg.asKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
51
|
+
const classDecorators = [];
|
|
52
|
+
const methods = {};
|
|
53
|
+
for (const prop of configObj.getProperties()) {
|
|
54
|
+
if (prop.getKind() !== ts_morph_1.SyntaxKind.PropertyAssignment)
|
|
55
|
+
continue;
|
|
56
|
+
const pa = prop.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAssignment);
|
|
57
|
+
const name = pa.getName();
|
|
58
|
+
const initializer = pa.getInitializer();
|
|
59
|
+
if (!initializer)
|
|
60
|
+
continue;
|
|
61
|
+
if (name === 'classDecorators' && initializer.getKind() === ts_morph_1.SyntaxKind.ArrayLiteralExpression) {
|
|
62
|
+
for (const el of initializer.asKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression).getElements()) {
|
|
63
|
+
const call = (0, eval_decorator_args_1.evaluateDecoratorCall)(el);
|
|
64
|
+
if (call)
|
|
65
|
+
classDecorators.push(call);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (name === 'methods' && initializer.getKind() === ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
|
|
69
|
+
for (const methodProp of initializer.asKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression).getProperties()) {
|
|
70
|
+
if (methodProp.getKind() !== ts_morph_1.SyntaxKind.PropertyAssignment)
|
|
71
|
+
continue;
|
|
72
|
+
const methodPa = methodProp.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAssignment);
|
|
73
|
+
const methodName = methodPa.getName();
|
|
74
|
+
const methodInit = methodPa.getInitializer();
|
|
75
|
+
if (!methodInit || methodInit.getKind() !== ts_morph_1.SyntaxKind.ArrayLiteralExpression)
|
|
76
|
+
continue;
|
|
77
|
+
const calls = [];
|
|
78
|
+
for (const el of methodInit.asKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression).getElements()) {
|
|
79
|
+
const call = (0, eval_decorator_args_1.evaluateDecoratorCall)(el);
|
|
80
|
+
if (call)
|
|
81
|
+
calls.push(call);
|
|
82
|
+
}
|
|
83
|
+
methods[methodName] = calls;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { classDecorators, methods };
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=extract-docs-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-docs-config.js","sourceRoot":"","sources":["../../src/cli/extract-docs-config.ts"],"names":[],"mappings":";;AAqBA,8CAmEC;AAxFD,uCAA+C;AAC/C,+DAA6E;AAO7E;;;;;;;;;;;;GAYG;AACH,SAAgB,iBAAiB,CAAC,UAAkB;IAClD,IAAI,OAAgB,CAAC;IACrB,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,kBAAO,CAAC,EAAE,qBAAqB,EAAE,IAAI,EAAE,4BAA4B,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,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A,2CAAqB,EAAC,EAAE,CAAC,CAAC;oBACvC,IAAI,IAAI;wBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC7B,CAAC;gBACD,OAAO,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -9,10 +9,16 @@ export interface ParamInfo {
|
|
|
9
9
|
export type JsonSchemaType = 'string' | 'number' | 'boolean' | 'integer' | 'array' | 'object';
|
|
10
10
|
export interface SchemaProperty {
|
|
11
11
|
type?: JsonSchemaType;
|
|
12
|
+
format?: string;
|
|
12
13
|
nullable?: boolean;
|
|
13
14
|
items?: SchemaProperty;
|
|
14
15
|
properties?: Record<string, SchemaProperty>;
|
|
15
16
|
required?: string[];
|
|
17
|
+
minimum?: number;
|
|
18
|
+
maximum?: number;
|
|
19
|
+
minLength?: number;
|
|
20
|
+
maxLength?: number;
|
|
21
|
+
enum?: (string | number)[];
|
|
16
22
|
}
|
|
17
23
|
export interface InlineSchema {
|
|
18
24
|
properties: Record<string, SchemaProperty>;
|
|
@@ -38,11 +44,18 @@ export interface ResponseTypeInfo {
|
|
|
38
44
|
isInterface: boolean;
|
|
39
45
|
/** Extracted property schema when `isInterface` is true. Used to emit `schema:` instead of `type:`. */
|
|
40
46
|
inlineSchema?: InlineSchema;
|
|
47
|
+
/**
|
|
48
|
+
* Schema inferred from class-validator decorators when the type is a class.
|
|
49
|
+
* Only set when the class has class-validator decorators and no `@ApiProperty`.
|
|
50
|
+
* Used to emit `schema:` instead of `type:` so docs are accurate even without @ApiProperty.
|
|
51
|
+
*/
|
|
52
|
+
classSchema?: InlineSchema;
|
|
41
53
|
}
|
|
42
54
|
export interface MethodInfo {
|
|
43
55
|
name: string;
|
|
44
56
|
httpDecorator: string | null;
|
|
45
57
|
httpPath: string | null;
|
|
58
|
+
httpStatusCode: number | null;
|
|
46
59
|
params: ParamInfo[];
|
|
47
60
|
returnType: string;
|
|
48
61
|
responseType: ResponseTypeInfo | null;
|