@lucaapp/service-utils 5.30.0 → 5.31.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.
@@ -13,6 +13,17 @@ type ApiConstructorOptions = {
13
13
  * stays hidden. Routing is unaffected; this only controls documentation.
14
14
  */
15
15
  hidden?: boolean;
16
+ /**
17
+ * Paths kept out of the generated OpenAPI spec, matched against the full
18
+ * registered path including the prefix. A string must match exactly; a
19
+ * RegExp is tested against it. Inherited by children.
20
+ *
21
+ * This is the central place to keep routes undocumented, so the decision
22
+ * lives in one list next to the Api rather than spread across the route
23
+ * files it applies to. `hidden` on a single endpoint does the same thing at
24
+ * the definition site; prefer this list when the routes share a reason.
25
+ */
26
+ excludeFromSpec?: ReadonlyArray<string | RegExp>;
16
27
  openApiVersion?: OpenApiVersion;
17
28
  apiVersion?: string;
18
29
  apiTitle?: string;
@@ -39,6 +50,7 @@ export declare class Api {
39
50
  debug: boolean;
40
51
  tags: string[];
41
52
  private hidden;
53
+ private excludeFromSpec;
42
54
  constructor(options?: ApiConstructorOptions);
43
55
  child(options: ApiChildOptions): Api;
44
56
  get<TResponseSchemas extends ReadonlyArray<EndpointResponseSchema>, TRequestBodySchema extends ZodObjectSchemaOrUndefined = undefined, TRequestParamsSchema extends ZodObjectSchemaOrUndefined = undefined, TRequestQuerySchema extends ZodObjectSchemaOrUndefined = undefined, TRequestHeadersSchema extends ZodObjectSchemaOrUndefined = undefined, TMiddlewares extends ReadonlyArray<Middleware<any, any, any, any, any, any>> | undefined = undefined>(path: string, summary: string, options: EndpointOptions<TResponseSchemas, TRequestBodySchema, TRequestParamsSchema, TRequestQuerySchema, TRequestHeadersSchema, TMiddlewares>, handler: EndpointHandler<TResponseSchemas, TRequestBodySchema, TRequestParamsSchema, TRequestQuerySchema, TRequestHeadersSchema, TMiddlewares>): void;
@@ -31,6 +31,7 @@ class Api {
31
31
  this.debug = options.debug || false;
32
32
  this.tags = options.tags || [];
33
33
  this.hidden = options.hidden || false;
34
+ this.excludeFromSpec = options.excludeFromSpec || [];
34
35
  this.router.use(body_parser_1.default.json({ verify: rawBodySaver, limit: '2mb' }));
35
36
  }
36
37
  child(options) {
@@ -42,29 +43,30 @@ class Api {
42
43
  router: this.router,
43
44
  // Once hidden, always hidden: a child cannot re-expose its parent's tree.
44
45
  hidden: this.hidden || options.hidden || false,
46
+ excludeFromSpec: this.excludeFromSpec,
45
47
  });
46
48
  child.rootPrefixPath = this.rootPrefixPath;
47
49
  return child;
48
50
  }
49
51
  get(path, summary, options, handler) {
50
52
  (0, endpoint_1.mountEndpoint)(this.router, 'get', path, options, handler, this.debug);
51
- (0, openapi_1.registerEndpoint)(this.registry, 'get', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
53
+ (0, openapi_1.registerEndpoint)(this.registry, 'get', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
52
54
  }
53
55
  post(path, summary, options, handler) {
54
56
  (0, endpoint_1.mountEndpoint)(this.router, 'post', path, options, handler, this.debug);
55
- (0, openapi_1.registerEndpoint)(this.registry, 'post', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
57
+ (0, openapi_1.registerEndpoint)(this.registry, 'post', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
56
58
  }
57
59
  patch(path, summary, options, handler) {
58
60
  (0, endpoint_1.mountEndpoint)(this.router, 'patch', path, options, handler, this.debug);
59
- (0, openapi_1.registerEndpoint)(this.registry, 'patch', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
61
+ (0, openapi_1.registerEndpoint)(this.registry, 'patch', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
60
62
  }
61
63
  put(path, summary, options, handler) {
62
64
  (0, endpoint_1.mountEndpoint)(this.router, 'put', path, options, handler, this.debug);
63
- (0, openapi_1.registerEndpoint)(this.registry, 'put', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
65
+ (0, openapi_1.registerEndpoint)(this.registry, 'put', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
64
66
  }
65
67
  delete(path, summary, options, handler) {
66
68
  (0, endpoint_1.mountEndpoint)(this.router, 'delete', path, options, handler, this.debug);
67
- (0, openapi_1.registerEndpoint)(this.registry, 'delete', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden);
69
+ (0, openapi_1.registerEndpoint)(this.registry, 'delete', this.prefixPath, this.rootPrefixPath, path, summary, options, this.tags, this.debug, this.hidden, this.excludeFromSpec);
68
70
  }
69
71
  generateOpenAPISpec() {
70
72
  let generator;
@@ -25,5 +25,5 @@ export declare const hoistCombinatorRequiredFields: (spec: {
25
25
  schemas?: Record<string, unknown>;
26
26
  };
27
27
  }) => void;
28
- export declare const registerEndpoint: (registry: OpenAPIRegistry, method: HttpMethod, prefixPath: string, rootPrefixPath: string, path: string, summary: string, options: EndpointOptions<any, any, any, any, any, any>, tags: string[], debug: boolean, hiddenApi?: boolean) => void;
28
+ export declare const registerEndpoint: (registry: OpenAPIRegistry, method: HttpMethod, prefixPath: string, rootPrefixPath: string, path: string, summary: string, options: EndpointOptions<any, any, any, any, any, any>, tags: string[], debug: boolean, hiddenApi?: boolean, excludeFromSpec?: ReadonlyArray<string | RegExp>) => void;
29
29
  export {};
@@ -227,11 +227,16 @@ const hoistCombinatorRequiredFields = (spec) => {
227
227
  exports.hoistCombinatorRequiredFields = hoistCombinatorRequiredFields;
228
228
  const registerEndpoint = (registry, method, prefixPath, rootPrefixPath, path, summary,
229
229
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
- options, tags, debug, hiddenApi = false) => {
230
+ options, tags, debug, hiddenApi = false, excludeFromSpec = []) => {
231
231
  // Hidden endpoints are never registered, so they leave no path, no
232
232
  // operationId and no security behind. Checked before any schema work: there
233
233
  // is nothing to build for an operation that will not be published.
234
- if (hiddenApi || options.hidden) {
234
+ //
235
+ // The exclusion list is matched against the same path string the spec would
236
+ // have used, so an entry can be copied straight out of a generated spec.
237
+ const specPath = mapExpressParamsToOpenAPIParams(prefixPath + path);
238
+ const excluded = excludeFromSpec.some(pattern => typeof pattern === 'string' ? pattern === specPath : pattern.test(specPath));
239
+ if (hiddenApi || options.hidden || excluded) {
235
240
  return;
236
241
  }
237
242
  let bodySchema = options.schemas?.body || undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucaapp/service-utils",
3
- "version": "5.30.0",
3
+ "version": "5.31.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [