vona-module-a-openapi 5.0.16 → 5.0.18

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/index.js CHANGED
@@ -5,9 +5,9 @@ import { OpenApiGeneratorV3, OpenApiGeneratorV31, OpenAPIRegistry } from '@astea
5
5
  import * as ModuleInfo from '@cabloy/module-info';
6
6
  import { isEmptyObject, isNil } from '@cabloy/utils';
7
7
  import { toUpperCaseFirstChar } from '@cabloy/word-utils';
8
+ import { getTypeName, coerceWithNil } from '@cabloy/zod-query';
8
9
  import { Service, SymbolRequestMappingHandler } from 'vona-module-a-web';
9
10
  import { z } from 'zod';
10
- import { coerceWithNil } from '@cabloy/zod-query';
11
11
  import 'openapi3-ts/oas30';
12
12
  import 'openapi3-ts/oas31';
13
13
 
@@ -275,11 +275,11 @@ let ServiceOpenapi = (_dec$1 = Service(), _dec2$1 = BeanInfo({
275
275
  security,
276
276
  description: actionOpenApiOptions?.description,
277
277
  summary: actionOpenApiOptions?.summary,
278
- request: this._collectRequest(controller, actionKey, actionOpenApiOptions, controllerOpenApiOptions),
278
+ request: this._collectRequest(info, controller, actionKey, actionOpenApiOptions, controllerOpenApiOptions),
279
279
  responses: this._collectResponses(controller, actionKey, actionOpenApiOptions)
280
280
  });
281
281
  }
282
- _collectRequest(controller, actionKey, actionOpenApiOptions, controllerOpenApiOptions) {
282
+ _collectRequest(info, controller, actionKey, actionOpenApiOptions, controllerOpenApiOptions) {
283
283
  // meta
284
284
  const argsMeta = this._prepareArgsMeta(controller, actionKey, actionOpenApiOptions, controllerOpenApiOptions);
285
285
  if (!argsMeta) return;
@@ -334,6 +334,10 @@ let ServiceOpenapi = (_dec$1 = Service(), _dec2$1 = BeanInfo({
334
334
  }
335
335
  }
336
336
  if (!schema) continue;
337
+ // check schema
338
+ if (getTypeName(schema) === 'ZodAny') {
339
+ throw new Error(`Invalid OpenAPI argument type: ${info.relativeName}:${controller.name}.${actionKey}#${argumentType}`);
340
+ }
337
341
  // record
338
342
  if (argumentType === 'body') {
339
343
  // body
@@ -519,6 +523,13 @@ function setPublic(target, prop, _descriptor, value) {
519
523
  const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
520
524
  options.public = value;
521
525
  }
526
+ function httpCode(httpCode) {
527
+ return function (target, prop, descriptor) {
528
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
529
+ options.httpCode = httpCode;
530
+ return descriptor;
531
+ };
532
+ }
522
533
  function contentType(contentType) {
523
534
  return function (target, prop, descriptor) {
524
535
  const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
@@ -579,15 +590,29 @@ function headers(headers) {
579
590
  return descriptor;
580
591
  };
581
592
  }
593
+ function setHeader(field, val) {
594
+ return function (target, prop, descriptor) {
595
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
596
+ if (!options.setHeaders) options.setHeaders = {};
597
+ if (typeof field === 'string') {
598
+ options.setHeaders[field] = val;
599
+ } else {
600
+ Object.assign(options.setHeaders, field);
601
+ }
602
+ return descriptor;
603
+ };
604
+ }
582
605
  const Api = {
583
606
  field: Field$1,
607
+ httpCode,
584
608
  contentType,
585
609
  body,
586
610
  bodyCustom,
587
611
  exclude,
588
612
  tags,
589
613
  header,
590
- headers
614
+ headers,
615
+ setHeader
591
616
  };
592
617
 
593
618
  function createPipesArgumentDecorator(paramType, extractValue) {
@@ -3,6 +3,7 @@ import type { IOpenApiHeader, TypeResponseContentType } from '../../types/api.ts
3
3
  import type { SchemaLike, SchemaLikeCreate } from '../../types/decorator.ts';
4
4
  import { Field } from './field.ts';
5
5
  export declare function setPublic(target: object, prop?: MetadataKey, _descriptor?: PropertyDescriptor, value?: boolean): void;
6
+ declare function httpCode(httpCode: number): MethodDecorator;
6
7
  declare function contentType(contentType: TypeResponseContentType): MethodDecorator;
7
8
  declare function body(...schemaLikes: SchemaLike[]): MethodDecorator;
8
9
  declare function bodyCustom(bodySchemaWrapper: SchemaLikeCreate | false, ...schemaLikes: SchemaLike[]): MethodDecorator;
@@ -10,8 +11,13 @@ declare function exclude(): ClassDecorator & MethodDecorator;
10
11
  declare function tags(tags: string[]): ClassDecorator & MethodDecorator;
11
12
  declare function header(header: IOpenApiHeader): ClassDecorator & MethodDecorator;
12
13
  declare function headers(headers: IOpenApiHeader[]): ClassDecorator & MethodDecorator;
14
+ declare function setHeader(field: {
15
+ [key: string]: string | string[];
16
+ }): ClassDecorator & MethodDecorator;
17
+ declare function setHeader(field: string, val: string | string[]): ClassDecorator & MethodDecorator;
13
18
  export declare const Api: {
14
19
  field: typeof Field;
20
+ httpCode: typeof httpCode;
15
21
  contentType: typeof contentType;
16
22
  body: typeof body;
17
23
  bodyCustom: typeof bodyCustom;
@@ -19,5 +25,6 @@ export declare const Api: {
19
25
  tags: typeof tags;
20
26
  header: typeof header;
21
27
  headers: typeof headers;
28
+ setHeader: typeof setHeader;
22
29
  };
23
30
  export {};
@@ -8,10 +8,14 @@ export interface IOpenApiHeader {
8
8
  name: string;
9
9
  description?: string;
10
10
  }
11
+ export interface IResponseHeaders {
12
+ [key: string]: string | string[];
13
+ }
11
14
  export interface IOpenApiOptions {
12
15
  public?: boolean;
13
16
  description?: string;
14
17
  summary?: string;
18
+ httpCode?: number;
15
19
  contentType?: TypeResponseContentType;
16
20
  bodySchema?: z.ZodSchema;
17
21
  bodySchemaWrapper?: SchemaLikeCreate | false;
@@ -19,6 +23,7 @@ export interface IOpenApiOptions {
19
23
  tags?: string[];
20
24
  operationId?: string;
21
25
  headers?: IOpenApiHeader[];
26
+ setHeaders?: IResponseHeaders;
22
27
  }
23
28
  export type TypeGenerateJsonScene = 'api' | 'rest';
24
29
  export type TypeOpenApiVersion = 'V30' | 'V31';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-openapi",
3
3
  "type": "module",
4
- "version": "5.0.16",
4
+ "version": "5.0.18",
5
5
  "title": "a-openapi",
6
6
  "vonaModule": {
7
7
  "capabilities": {
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "@asteasolutions/zod-to-openapi": "^7.3.0",
37
37
  "@cabloy/zod-errors-custom": "^1.0.13",
38
- "@cabloy/zod-query": "^1.0.14",
38
+ "@cabloy/zod-query": "^1.0.15",
39
39
  "@zhennann/currency": "^2.0.0",
40
40
  "openapi3-ts": "^4.4.0",
41
41
  "zod": "^3.25.58"