@achinet/nestjs-async 0.1.1 → 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/dist/asyncapi-document.builder.d.ts +1 -1
- package/dist/asyncapi-document.builder.js.map +1 -1
- package/dist/asyncapi.module.js +8 -5
- package/dist/asyncapi.module.js.map +1 -1
- package/dist/binding/asyncapi.kafka.interfaces.d.ts +1 -1
- package/dist/decorators/asyncapi-operation-for-meta-key.decorator.js +3 -3
- package/dist/decorators/asyncapi-operation-for-meta-key.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-operation.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-pub.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-service.decorator.d.ts +1 -1
- package/dist/decorators/asyncapi-service.decorator.js +2 -2
- package/dist/decorators/asyncapi-service.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-sub.decorator.js.map +1 -1
- package/dist/explorers/asyncapi-class.explorer.js +1 -5
- package/dist/explorers/asyncapi-class.explorer.js.map +1 -1
- package/dist/explorers/asyncapi-operation.explorer.d.ts +1 -2
- package/dist/explorers/asyncapi-operation.explorer.js +2 -2
- package/dist/explorers/asyncapi-operation.explorer.js.map +1 -1
- package/dist/interface/asyncapi-common.interfaces.d.ts +1 -1
- package/dist/interface/asyncapi-server.interface.d.ts +1 -1
- package/dist/interface/asyncapi-template-options.interface.d.ts +2 -3
- package/dist/interface/index.d.ts +0 -1
- package/dist/interface/index.js +0 -1
- package/dist/interface/index.js.map +1 -1
- package/dist/services/asyncapi.explorer.d.ts +2 -4
- package/dist/services/asyncapi.explorer.js +8 -13
- package/dist/services/asyncapi.explorer.js.map +1 -1
- package/dist/services/asyncapi.generator.d.ts +4 -3
- package/dist/services/asyncapi.generator.js +72 -17
- package/dist/services/asyncapi.generator.js.map +1 -1
- package/dist/services/asyncapi.scanner.d.ts +1 -4
- package/dist/services/asyncapi.scanner.js +10 -31
- package/dist/services/asyncapi.scanner.js.map +1 -1
- package/dist/services/asyncapi.transformer.js.map +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/operation-object.factory.d.ts +2 -6
- package/dist/services/operation-object.factory.js +7 -14
- package/dist/services/operation-object.factory.js.map +1 -1
- package/dist/services/swagger-schema.factory.d.ts +6 -0
- package/dist/services/swagger-schema.factory.js +27 -0
- package/dist/services/swagger-schema.factory.js.map +1 -0
- package/dist/utils/decorator.utils.d.ts +2 -0
- package/dist/utils/decorator.utils.js +26 -0
- package/dist/utils/decorator.utils.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/{sample/felines/rto → utils}/index.js +2 -1
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/path.utils.d.ts +2 -0
- package/dist/utils/path.utils.js +8 -0
- package/dist/utils/path.utils.js.map +1 -0
- package/package.json +57 -37
- package/.prettierrc +0 -5
- package/CHANGELOG.md +0 -20
- package/dist/interface/generator-options.interface.d.ts +0 -22
- package/dist/interface/generator-options.interface.js +0 -3
- package/dist/interface/generator-options.interface.js.map +0 -1
- package/dist/sample/app.module.d.ts +0 -2
- package/dist/sample/app.module.js +0 -20
- package/dist/sample/app.module.js.map +0 -1
- package/dist/sample/common.d.ts +0 -3
- package/dist/sample/common.js +0 -40
- package/dist/sample/common.js.map +0 -1
- package/dist/sample/constants.d.ts +0 -12
- package/dist/sample/constants.js +0 -16
- package/dist/sample/constants.js.map +0 -1
- package/dist/sample/felines/class/cat.class.d.ts +0 -4
- package/dist/sample/felines/class/cat.class.js +0 -24
- package/dist/sample/felines/class/cat.class.js.map +0 -1
- package/dist/sample/felines/class/feline.class.d.ts +0 -19
- package/dist/sample/felines/class/feline.class.js +0 -20
- package/dist/sample/felines/class/feline.class.js.map +0 -1
- package/dist/sample/felines/class/index.d.ts +0 -5
- package/dist/sample/felines/class/index.js +0 -22
- package/dist/sample/felines/class/index.js.map +0 -1
- package/dist/sample/felines/class/lion.class.d.ts +0 -4
- package/dist/sample/felines/class/lion.class.js +0 -8
- package/dist/sample/felines/class/lion.class.js.map +0 -1
- package/dist/sample/felines/class/message.class.d.ts +0 -7
- package/dist/sample/felines/class/message.class.js +0 -28
- package/dist/sample/felines/class/message.class.js.map +0 -1
- package/dist/sample/felines/class/tiger.class.d.ts +0 -4
- package/dist/sample/felines/class/tiger.class.js +0 -8
- package/dist/sample/felines/class/tiger.class.js.map +0 -1
- package/dist/sample/felines/dto/create-feline.dto.d.ts +0 -4
- package/dist/sample/felines/dto/create-feline.dto.js +0 -28
- package/dist/sample/felines/dto/create-feline.dto.js.map +0 -1
- package/dist/sample/felines/dto/index.d.ts +0 -2
- package/dist/sample/felines/dto/index.js +0 -19
- package/dist/sample/felines/dto/index.js.map +0 -1
- package/dist/sample/felines/dto/journaling-data.dto.d.ts +0 -4
- package/dist/sample/felines/dto/journaling-data.dto.js +0 -8
- package/dist/sample/felines/dto/journaling-data.dto.js.map +0 -1
- package/dist/sample/felines/felines.constants.d.ts +0 -1
- package/dist/sample/felines/felines.constants.js +0 -5
- package/dist/sample/felines/felines.constants.js.map +0 -1
- package/dist/sample/felines/felines.controller.d.ts +0 -15
- package/dist/sample/felines/felines.controller.js +0 -101
- package/dist/sample/felines/felines.controller.js.map +0 -1
- package/dist/sample/felines/felines.gateway.d.ts +0 -16
- package/dist/sample/felines/felines.gateway.js +0 -90
- package/dist/sample/felines/felines.gateway.js.map +0 -1
- package/dist/sample/felines/felines.module.d.ts +0 -2
- package/dist/sample/felines/felines.module.js +0 -28
- package/dist/sample/felines/felines.module.js.map +0 -1
- package/dist/sample/felines/felines.service.d.ts +0 -8
- package/dist/sample/felines/felines.service.js +0 -33
- package/dist/sample/felines/felines.service.js.map +0 -1
- package/dist/sample/felines/rto/feline.rto.d.ts +0 -7
- package/dist/sample/felines/rto/feline.rto.js +0 -31
- package/dist/sample/felines/rto/feline.rto.js.map +0 -1
- package/dist/sample/felines/rto/index.d.ts +0 -1
- package/dist/sample/felines/rto/index.js.map +0 -1
- package/dist/sample/index.d.ts +0 -3
- package/dist/sample/index.js +0 -20
- package/dist/sample/index.js.map +0 -1
- package/dist/sample/main.d.ts +0 -1
- package/dist/sample/main.js +0 -30
- package/dist/sample/main.js.map +0 -1
- package/dist/src/asyncapi-document.builder.d.ts +0 -27
- package/dist/src/asyncapi-document.builder.js +0 -110
- package/dist/src/asyncapi-document.builder.js.map +0 -1
- package/dist/src/asyncapi.constants.d.ts +0 -6
- package/dist/src/asyncapi.constants.js +0 -11
- package/dist/src/asyncapi.constants.js.map +0 -1
- package/dist/src/asyncapi.module.d.ts +0 -8
- package/dist/src/asyncapi.module.js +0 -47
- package/dist/src/asyncapi.module.js.map +0 -1
- package/dist/src/binding/asyncapi.amqp.interfaces.d.ts +0 -38
- package/dist/src/binding/asyncapi.amqp.interfaces.js +0 -3
- package/dist/src/binding/asyncapi.amqp.interfaces.js.map +0 -1
- package/dist/src/binding/asyncapi.kafka.interfaces.d.ts +0 -21
- package/dist/src/binding/asyncapi.kafka.interfaces.js +0 -3
- package/dist/src/binding/asyncapi.kafka.interfaces.js.map +0 -1
- package/dist/src/binding/index.d.ts +0 -2
- package/dist/src/binding/index.js +0 -19
- package/dist/src/binding/index.js.map +0 -1
- package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.d.ts +0 -2
- package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.js +0 -37
- package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.js.map +0 -1
- package/dist/src/decorators/asyncapi-operation.decorator.d.ts +0 -2
- package/dist/src/decorators/asyncapi-operation.decorator.js +0 -9
- package/dist/src/decorators/asyncapi-operation.decorator.js.map +0 -1
- package/dist/src/decorators/asyncapi-pub.decorator.d.ts +0 -2
- package/dist/src/decorators/asyncapi-pub.decorator.js +0 -10
- package/dist/src/decorators/asyncapi-pub.decorator.js.map +0 -1
- package/dist/src/decorators/asyncapi-service.decorator.d.ts +0 -1
- package/dist/src/decorators/asyncapi-service.decorator.js +0 -9
- package/dist/src/decorators/asyncapi-service.decorator.js.map +0 -1
- package/dist/src/decorators/asyncapi-sub.decorator.d.ts +0 -2
- package/dist/src/decorators/asyncapi-sub.decorator.js +0 -10
- package/dist/src/decorators/asyncapi-sub.decorator.js.map +0 -1
- package/dist/src/decorators/index.d.ts +0 -4
- package/dist/src/decorators/index.js +0 -21
- package/dist/src/decorators/index.js.map +0 -1
- package/dist/src/explorers/asyncapi-class.explorer.d.ts +0 -5
- package/dist/src/explorers/asyncapi-class.explorer.js +0 -27
- package/dist/src/explorers/asyncapi-class.explorer.js.map +0 -1
- package/dist/src/explorers/asyncapi-operation.explorer.d.ts +0 -17
- package/dist/src/explorers/asyncapi-operation.explorer.js +0 -26
- package/dist/src/explorers/asyncapi-operation.explorer.js.map +0 -1
- package/dist/src/explorers/index.d.ts +0 -2
- package/dist/src/explorers/index.js +0 -19
- package/dist/src/explorers/index.js.map +0 -1
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -21
- package/dist/src/index.js.map +0 -1
- package/dist/src/interface/asyncapi-common.interfaces.d.ts +0 -126
- package/dist/src/interface/asyncapi-common.interfaces.js +0 -3
- package/dist/src/interface/asyncapi-common.interfaces.js.map +0 -1
- package/dist/src/interface/asyncapi-document-options.interface.d.ts +0 -3
- package/dist/src/interface/asyncapi-document-options.interface.js +0 -3
- package/dist/src/interface/asyncapi-document-options.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-message.interface.d.ts +0 -8
- package/dist/src/interface/asyncapi-message.interface.js +0 -3
- package/dist/src/interface/asyncapi-message.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-operation-headers.interface.d.ts +0 -6
- package/dist/src/interface/asyncapi-operation-headers.interface.js +0 -3
- package/dist/src/interface/asyncapi-operation-headers.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-operation-options-raw.interface.d.ts +0 -21
- package/dist/src/interface/asyncapi-operation-options-raw.interface.js +0 -3
- package/dist/src/interface/asyncapi-operation-options-raw.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-operation-options.interface.d.ts +0 -8
- package/dist/src/interface/asyncapi-operation-options.interface.js +0 -3
- package/dist/src/interface/asyncapi-operation-options.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-operation-payload.interface.d.ts +0 -2
- package/dist/src/interface/asyncapi-operation-payload.interface.js +0 -3
- package/dist/src/interface/asyncapi-operation-payload.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-server.interface.d.ts +0 -10
- package/dist/src/interface/asyncapi-server.interface.js +0 -3
- package/dist/src/interface/asyncapi-server.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-template-options.interface.d.ts +0 -7
- package/dist/src/interface/asyncapi-template-options.interface.js +0 -3
- package/dist/src/interface/asyncapi-template-options.interface.js.map +0 -1
- package/dist/src/interface/denormalized-doc-resolvers.interface.d.ts +0 -6
- package/dist/src/interface/denormalized-doc-resolvers.interface.js +0 -3
- package/dist/src/interface/denormalized-doc-resolvers.interface.js.map +0 -1
- package/dist/src/interface/denormalized-doc.interface.d.ts +0 -10
- package/dist/src/interface/denormalized-doc.interface.js +0 -3
- package/dist/src/interface/denormalized-doc.interface.js.map +0 -1
- package/dist/src/interface/generator-options.interface.d.ts +0 -22
- package/dist/src/interface/generator-options.interface.js +0 -3
- package/dist/src/interface/generator-options.interface.js.map +0 -1
- package/dist/src/interface/index.d.ts +0 -11
- package/dist/src/interface/index.js +0 -28
- package/dist/src/interface/index.js.map +0 -1
- package/dist/src/services/asyncapi.explorer.d.ts +0 -12
- package/dist/src/services/asyncapi.explorer.js +0 -69
- package/dist/src/services/asyncapi.explorer.js.map +0 -1
- package/dist/src/services/asyncapi.generator.d.ts +0 -6
- package/dist/src/services/asyncapi.generator.js +0 -68
- package/dist/src/services/asyncapi.generator.js.map +0 -1
- package/dist/src/services/asyncapi.scanner.d.ts +0 -14
- package/dist/src/services/asyncapi.scanner.js +0 -71
- package/dist/src/services/asyncapi.scanner.js.map +0 -1
- package/dist/src/services/asyncapi.transformer.d.ts +0 -4
- package/dist/src/services/asyncapi.transformer.js +0 -33
- package/dist/src/services/asyncapi.transformer.js.map +0 -1
- package/dist/src/services/index.d.ts +0 -4
- package/dist/src/services/index.js +0 -21
- package/dist/src/services/index.js.map +0 -1
- package/dist/src/services/operation-object.factory.d.ts +0 -9
- package/dist/src/services/operation-object.factory.js +0 -37
- package/dist/src/services/operation-object.factory.js.map +0 -1
- package/dist/test/configs/jest-base.config.d.ts +0 -3
- package/dist/test/configs/jest-base.config.js +0 -20
- package/dist/test/configs/jest-base.config.js.map +0 -1
- package/dist/test/configs/jest-e2e.config.d.ts +0 -3
- package/dist/test/configs/jest-e2e.config.js +0 -16
- package/dist/test/configs/jest-e2e.config.js.map +0 -1
- package/dist/test/express.e2e-spec.d.ts +0 -1
- package/dist/test/express.e2e-spec.js +0 -89
- package/dist/test/express.e2e-spec.js.map +0 -1
- package/dist/test/fastify.e2e-spec.d.ts +0 -1
- package/dist/test/fastify.e2e-spec.js +0 -57
- package/dist/test/fastify.e2e-spec.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/eslint.config.mjs +0 -21
- package/misc/references/ref.html +0 -303
- package/misc/references/ref.json +0 -1
- package/misc/references/ref.yaml +0 -292
- package/misc/take-snaphots.sh +0 -8
- package/sample/app.module.ts +0 -7
- package/sample/common.ts +0 -49
- package/sample/constants.ts +0 -12
- package/sample/felines/class/cat.class.ts +0 -9
- package/sample/felines/class/feline.class.ts +0 -29
- package/sample/felines/class/index.ts +0 -5
- package/sample/felines/class/lion.class.ts +0 -5
- package/sample/felines/class/message.class.ts +0 -17
- package/sample/felines/class/tiger.class.ts +0 -5
- package/sample/felines/dto/create-feline.dto.ts +0 -13
- package/sample/felines/dto/index.ts +0 -2
- package/sample/felines/dto/journaling-data.dto.ts +0 -5
- package/sample/felines/felines.constants.ts +0 -1
- package/sample/felines/felines.controller.ts +0 -76
- package/sample/felines/felines.gateway.ts +0 -76
- package/sample/felines/felines.module.ts +0 -15
- package/sample/felines/felines.service.ts +0 -24
- package/sample/felines/rto/feline.rto.ts +0 -17
- package/sample/felines/rto/index.ts +0 -1
- package/sample/index.ts +0 -3
- package/sample/main.ts +0 -34
- package/src/asyncapi-document.builder.ts +0 -172
- package/src/asyncapi.constants.ts +0 -8
- package/src/asyncapi.module.ts +0 -65
- package/src/binding/asyncapi.amqp.interfaces.ts +0 -48
- package/src/binding/asyncapi.kafka.interfaces.ts +0 -35
- package/src/binding/index.ts +0 -2
- package/src/decorators/asyncapi-operation-for-meta-key.decorator.ts +0 -58
- package/src/decorators/asyncapi-operation.decorator.ts +0 -7
- package/src/decorators/asyncapi-pub.decorator.ts +0 -11
- package/src/decorators/asyncapi-service.decorator.ts +0 -9
- package/src/decorators/asyncapi-sub.decorator.ts +0 -11
- package/src/decorators/index.ts +0 -4
- package/src/explorers/asyncapi-class.explorer.ts +0 -26
- package/src/explorers/asyncapi-operation.explorer.ts +0 -40
- package/src/explorers/index.ts +0 -2
- package/src/index.ts +0 -4
- package/src/interface/asyncapi-common.interfaces.ts +0 -169
- package/src/interface/asyncapi-document-options.interface.ts +0 -3
- package/src/interface/asyncapi-message.interface.ts +0 -10
- package/src/interface/asyncapi-operation-headers.interface.ts +0 -6
- package/src/interface/asyncapi-operation-options-raw.interface.ts +0 -23
- package/src/interface/asyncapi-operation-options.interface.ts +0 -10
- package/src/interface/asyncapi-operation-payload.interface.ts +0 -3
- package/src/interface/asyncapi-server.interface.ts +0 -11
- package/src/interface/asyncapi-template-options.interface.ts +0 -20
- package/src/interface/denormalized-doc-resolvers.interface.ts +0 -6
- package/src/interface/denormalized-doc.interface.ts +0 -6
- package/src/interface/generator-options.interface.ts +0 -21
- package/src/interface/index.ts +0 -12
- package/src/services/asyncapi.explorer.ts +0 -112
- package/src/services/asyncapi.generator.ts +0 -45
- package/src/services/asyncapi.scanner.ts +0 -105
- package/src/services/asyncapi.transformer.ts +0 -33
- package/src/services/index.ts +0 -4
- package/src/services/operation-object.factory.ts +0 -55
- package/test/__mocks__/@asyncapi/generator.js +0 -41
- package/test/configs/jest-base.config.ts +0 -19
- package/test/configs/jest-e2e.config.js +0 -7
- package/test/configs/jest-e2e.config.ts +0 -19
- package/test/configs/jest-swagger-plugin.js +0 -16
- package/test/express.e2e-spec.ts +0 -64
- package/test/fastify.e2e-spec.ts +0 -65
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -8
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import jsyaml from 'js-yaml';
|
|
3
|
-
import os from 'os';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { AsyncApiDocument, AsyncApiTemplateOptions, GeneratorOptions } from '../interface';
|
|
6
|
-
|
|
7
|
-
export class AsyncapiGenerator {
|
|
8
|
-
private readonly templateOptions?: AsyncApiTemplateOptions;
|
|
9
|
-
|
|
10
|
-
constructor(templateOptions?: AsyncApiTemplateOptions) {
|
|
11
|
-
this.templateOptions = templateOptions;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public async generate(contract: AsyncApiDocument): Promise<string> {
|
|
15
|
-
// Lazy-load @asyncapi/generator to avoid loading it at module initialization time.
|
|
16
|
-
// This allows tests and code that only use decorators to work without
|
|
17
|
-
// requiring the full generator dependency tree (which has nested semver issues in Jest).
|
|
18
|
-
const { default: Generator } = await import('@asyncapi/generator');
|
|
19
|
-
|
|
20
|
-
const yaml = jsyaml.dump(contract);
|
|
21
|
-
const tmpDir = path.join(os.tmpdir(), `asyncapi-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
22
|
-
|
|
23
|
-
const generator: GeneratorOptions = new Generator('@asyncapi/html-template', tmpDir, {
|
|
24
|
-
forceWrite: true,
|
|
25
|
-
templateParams: {
|
|
26
|
-
singleFile: true,
|
|
27
|
-
...this.templateOptions,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
await generator.generateFromString(yaml, {
|
|
32
|
-
resolve: {
|
|
33
|
-
file: false,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const htmlPath = path.join(tmpDir, 'index.html');
|
|
38
|
-
const html = await fs.readFile(htmlPath, 'utf-8');
|
|
39
|
-
|
|
40
|
-
// Clean up temp directory
|
|
41
|
-
await fs.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
|
|
42
|
-
|
|
43
|
-
return html;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { INestApplicationContext, Type } from '@nestjs/common';
|
|
2
|
-
import { MODULE_PATH } from '@nestjs/common/constants';
|
|
3
|
-
import { Injectable, InjectionToken } from '@nestjs/common/interfaces';
|
|
4
|
-
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|
5
|
-
import { Module } from '@nestjs/core/injector/module';
|
|
6
|
-
import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
|
|
7
|
-
import { ModelPropertiesAccessor } from '@nestjs/swagger/dist/services/model-properties-accessor';
|
|
8
|
-
import { SchemaObjectFactory } from '@nestjs/swagger/dist/services/schema-object-factory';
|
|
9
|
-
import { SwaggerTypesMapper } from '@nestjs/swagger/dist/services/swagger-types-mapper';
|
|
10
|
-
import { stripLastSlash } from '@nestjs/swagger/dist/utils/strip-last-slash.util';
|
|
11
|
-
import { flatten, isEmpty } from 'lodash';
|
|
12
|
-
import { AsyncApiDocument, AsyncApiDocumentOptions, DenormalizedDoc } from '../interface';
|
|
13
|
-
import { AsyncApiExplorer } from './asyncapi.explorer';
|
|
14
|
-
import { AsyncapiTransformer } from './asyncapi.transformer';
|
|
15
|
-
|
|
16
|
-
export class AsyncapiScanner {
|
|
17
|
-
private readonly transformer = new AsyncapiTransformer();
|
|
18
|
-
|
|
19
|
-
private readonly explorer = new AsyncApiExplorer();
|
|
20
|
-
|
|
21
|
-
private readonly modelPropertiesAccessor = new ModelPropertiesAccessor();
|
|
22
|
-
|
|
23
|
-
private readonly swaggerTypesMapper = new SwaggerTypesMapper();
|
|
24
|
-
|
|
25
|
-
private readonly schemaObjectFactory = new SchemaObjectFactory(this.modelPropertiesAccessor, this.swaggerTypesMapper);
|
|
26
|
-
|
|
27
|
-
public scanApplication(
|
|
28
|
-
app: INestApplicationContext,
|
|
29
|
-
options: AsyncApiDocumentOptions,
|
|
30
|
-
): Omit<AsyncApiDocument, 'asyncapi' | 'info'> {
|
|
31
|
-
const {
|
|
32
|
-
deepScanRoutes,
|
|
33
|
-
include: includedModules = [],
|
|
34
|
-
extraModels = [],
|
|
35
|
-
ignoreGlobalPrefix = false,
|
|
36
|
-
operationIdFactory,
|
|
37
|
-
} = options;
|
|
38
|
-
|
|
39
|
-
const { container } = app as any;
|
|
40
|
-
const modules: Module[] = this.getModules(container.getModules(), includedModules);
|
|
41
|
-
const globalPrefix = !ignoreGlobalPrefix ? stripLastSlash(this.getGlobalPrefix(app)) : '';
|
|
42
|
-
|
|
43
|
-
const denormalizedChannels = modules.reduce((channels, { providers, metatype, imports, controllers }) => {
|
|
44
|
-
let allProviders = new Map([...providers, ...controllers]);
|
|
45
|
-
|
|
46
|
-
if (deepScanRoutes) {
|
|
47
|
-
// only load submodules routes if asked
|
|
48
|
-
const isGlobal = (module: Type<any>) => !container.isGlobalModule(module);
|
|
49
|
-
|
|
50
|
-
Array.from(imports.values())
|
|
51
|
-
.filter(isGlobal as any)
|
|
52
|
-
.map(({ providers: relatedProviders, controllers: relatedControllers }) => ({
|
|
53
|
-
relatedProviders,
|
|
54
|
-
relatedControllers,
|
|
55
|
-
}))
|
|
56
|
-
.forEach(({ relatedProviders, relatedControllers }) => {
|
|
57
|
-
allProviders = new Map([...allProviders, ...relatedProviders, ...relatedControllers]);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
const path = metatype ? Reflect.getMetadata(MODULE_PATH, metatype) : undefined;
|
|
61
|
-
|
|
62
|
-
return [...channels, ...this.scanModuleProviders(allProviders, path, globalPrefix, operationIdFactory)];
|
|
63
|
-
}, []);
|
|
64
|
-
|
|
65
|
-
const schemas = this.explorer.getSchemas();
|
|
66
|
-
this.addExtraModels(schemas, extraModels);
|
|
67
|
-
const normalizedChannels = this.transformer.normalizeChannels(flatten(denormalizedChannels));
|
|
68
|
-
return {
|
|
69
|
-
...normalizedChannels,
|
|
70
|
-
components: { schemas },
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private scanModuleProviders(
|
|
75
|
-
providers: Map<InjectionToken, InstanceWrapper<Injectable>>,
|
|
76
|
-
modulePath?: string,
|
|
77
|
-
globalPrefix?: string,
|
|
78
|
-
operationIdFactory?: (controllerKey: string, methodKey: string) => string,
|
|
79
|
-
): DenormalizedDoc[] {
|
|
80
|
-
const denormalizedArray = [...providers.values()].reduce((denormalized, prov) => {
|
|
81
|
-
const object = this.explorer.explorerAsyncapiServices(prov, modulePath, globalPrefix, operationIdFactory);
|
|
82
|
-
return [...denormalized, ...object];
|
|
83
|
-
}, []);
|
|
84
|
-
|
|
85
|
-
return flatten(denormalizedArray) as any;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private getModules(modulesContainer: Map<string, Module>, include: Function[]): Module[] {
|
|
89
|
-
if (!include || isEmpty(include)) {
|
|
90
|
-
return [...modulesContainer.values()];
|
|
91
|
-
}
|
|
92
|
-
return [...modulesContainer.values()].filter(({ metatype }) => include.some((item) => item === metatype));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private getGlobalPrefix(app: INestApplicationContext): string {
|
|
96
|
-
const internalConfigRef = (app as any).config;
|
|
97
|
-
return internalConfigRef?.getGlobalPrefix() || '';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private addExtraModels(schemas: Record<string, SchemaObject>, extraModels: Function[]) {
|
|
101
|
-
extraModels.forEach((item) => {
|
|
102
|
-
this.schemaObjectFactory.exploreModelSchema(item, schemas);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AsyncChannelObject, AsyncChannelsObject, DenormalizedDoc } from '../interface';
|
|
2
|
-
|
|
3
|
-
export class AsyncapiTransformer {
|
|
4
|
-
public normalizeChannels(denormalizedDocs: DenormalizedDoc[]): Record<'channels', AsyncChannelsObject> {
|
|
5
|
-
const flatChannels = denormalizedDocs.map((doc: DenormalizedDoc) => {
|
|
6
|
-
const key = doc.root?.name;
|
|
7
|
-
const value: AsyncChannelObject = {
|
|
8
|
-
description: doc.root?.description,
|
|
9
|
-
bindings: doc.root?.bindings,
|
|
10
|
-
parameters: doc.root?.parameters,
|
|
11
|
-
subscribe: doc.operations?.sub,
|
|
12
|
-
publish: doc.operations?.pub,
|
|
13
|
-
};
|
|
14
|
-
return { key, value };
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const channels = flatChannels.reduce((acc, { key, value }) => {
|
|
18
|
-
// skip entries without a channel name
|
|
19
|
-
if (!key) return acc;
|
|
20
|
-
|
|
21
|
-
if (!acc[key]) {
|
|
22
|
-
acc[key] = value;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
acc[key].publish = acc[key].publish ?? value.publish;
|
|
26
|
-
acc[key].subscribe = acc[key].subscribe ?? value.subscribe;
|
|
27
|
-
|
|
28
|
-
return acc;
|
|
29
|
-
}, {} as AsyncChannelsObject);
|
|
30
|
-
|
|
31
|
-
return { channels };
|
|
32
|
-
}
|
|
33
|
-
}
|
package/src/services/index.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
|
|
2
|
-
import { ModelPropertiesAccessor } from '@nestjs/swagger/dist/services/model-properties-accessor';
|
|
3
|
-
import { SchemaObjectFactory } from '@nestjs/swagger/dist/services/schema-object-factory';
|
|
4
|
-
import { SwaggerTypesMapper } from '@nestjs/swagger/dist/services/swagger-types-mapper';
|
|
5
|
-
import { getSchemaPath } from '@nestjs/swagger/dist/utils';
|
|
6
|
-
import { AsyncApiOperationOptionsRaw, AsyncMessageObject, AsyncOperationObject, OneOfMessageType } from '../interface';
|
|
7
|
-
|
|
8
|
-
export class OperationObjectFactory {
|
|
9
|
-
private readonly modelPropertiesAccessor = new ModelPropertiesAccessor();
|
|
10
|
-
|
|
11
|
-
private readonly swaggerTypesMapper = new SwaggerTypesMapper();
|
|
12
|
-
|
|
13
|
-
private readonly schemaObjectFactory = new SchemaObjectFactory(this.modelPropertiesAccessor, this.swaggerTypesMapper);
|
|
14
|
-
|
|
15
|
-
create(
|
|
16
|
-
operation: AsyncApiOperationOptionsRaw,
|
|
17
|
-
produces: string[],
|
|
18
|
-
schemas: Record<string, SchemaObject>,
|
|
19
|
-
): AsyncOperationObject {
|
|
20
|
-
const { message } = operation;
|
|
21
|
-
const { oneOf } = message as OneOfMessageType;
|
|
22
|
-
|
|
23
|
-
if (oneOf) {
|
|
24
|
-
return {
|
|
25
|
-
...operation,
|
|
26
|
-
message: {
|
|
27
|
-
oneOf: oneOf.map((i) => ({
|
|
28
|
-
...i,
|
|
29
|
-
payload: {
|
|
30
|
-
$ref: getSchemaPath(this.getDtoName(i as AsyncMessageObject, schemas)),
|
|
31
|
-
},
|
|
32
|
-
})),
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
...operation,
|
|
39
|
-
message: {
|
|
40
|
-
...operation.message,
|
|
41
|
-
payload: {
|
|
42
|
-
$ref: getSchemaPath(this.getDtoName(message as AsyncMessageObject, schemas)),
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private getDtoName(message: AsyncMessageObject, schemas: Record<string, SchemaObject>): string {
|
|
49
|
-
if (!message.payload || !message.payload.type) {
|
|
50
|
-
throw new Error('Async message payload or payload.type is undefined; ensure message.payload is provided.');
|
|
51
|
-
}
|
|
52
|
-
const messagePayloadType = message.payload.type as Function;
|
|
53
|
-
return this.schemaObjectFactory.exploreModelSchema(messagePayloadType, schemas);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mock for @asyncapi/generator to avoid ESM issues in Jest tests.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
|
|
8
|
-
class MockGenerator {
|
|
9
|
-
constructor(templateName, targetDir, options = {}) {
|
|
10
|
-
this.templateName = templateName;
|
|
11
|
-
this.targetDir = targetDir;
|
|
12
|
-
this.options = options;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async generateFromString(yaml) {
|
|
16
|
-
const html = `<!DOCTYPE html>
|
|
17
|
-
<html>
|
|
18
|
-
<head>
|
|
19
|
-
<title>AsyncAPI Documentation</title>
|
|
20
|
-
</head>
|
|
21
|
-
<body>
|
|
22
|
-
<h1>AsyncAPI Documentation</h1>
|
|
23
|
-
<p>Mock HTML generated for testing</p>
|
|
24
|
-
<pre>${yaml.replace(/</g, '<').replace(/>/g, '>')}</pre>
|
|
25
|
-
</body>
|
|
26
|
-
</html>`;
|
|
27
|
-
|
|
28
|
-
// Create the target directory and write the file
|
|
29
|
-
fs.mkdirSync(this.targetDir, { recursive: true });
|
|
30
|
-
fs.writeFileSync(path.join(this.targetDir, 'index.html'), html, 'utf-8');
|
|
31
|
-
|
|
32
|
-
return html;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async generate(asyncapi) {
|
|
36
|
-
return this.generateFromString(JSON.stringify(asyncapi, null, 2));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = MockGenerator;
|
|
41
|
-
module.exports.default = MockGenerator;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { JestConfigWithTsJest } from 'ts-jest';
|
|
2
|
-
|
|
3
|
-
export const baseConfig: JestConfigWithTsJest = {
|
|
4
|
-
moduleFileExtensions: ['js', 'json', 'ts'],
|
|
5
|
-
rootDir: '../../',
|
|
6
|
-
transform: {
|
|
7
|
-
'^.+\\.(t|j)s$': 'ts-jest',
|
|
8
|
-
},
|
|
9
|
-
collectCoverageFrom: ['**/*.(t|j)s'],
|
|
10
|
-
coverageDirectory: './coverage',
|
|
11
|
-
testEnvironment: 'node',
|
|
12
|
-
moduleNameMapper: {
|
|
13
|
-
'#lib(|/.*)$': '<rootDir>/lib/$1',
|
|
14
|
-
'#sample(|/.*)$': '<rootDir>/sample/$1',
|
|
15
|
-
'#test(|/.*)$': '<rootDir>/test/$1',
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default baseConfig;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { JestConfigWithTsJest } from 'ts-jest';
|
|
2
|
-
import { baseConfig } from './jest-base.config';
|
|
3
|
-
|
|
4
|
-
export const e2eConfig: JestConfigWithTsJest = {
|
|
5
|
-
...baseConfig,
|
|
6
|
-
testRegex: '.\\.e2e-spec\\.ts$',
|
|
7
|
-
transform: {
|
|
8
|
-
'^.+\\.(t|j)s$': [
|
|
9
|
-
'ts-jest',
|
|
10
|
-
{
|
|
11
|
-
astTransformers: {
|
|
12
|
-
before: ['test/configs/jest-swagger-plugin.js'],
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default e2eConfig;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
-
const transformer = require('@nestjs/swagger/plugin');
|
|
3
|
-
|
|
4
|
-
module.exports.name = 'nestjs-swagger-transformer';
|
|
5
|
-
// you should change the version number anytime you change the configuration below - otherwise, jest will not detect changes
|
|
6
|
-
module.exports.version = 1;
|
|
7
|
-
|
|
8
|
-
module.exports.factory = (cs) => {
|
|
9
|
-
return transformer.before(
|
|
10
|
-
{
|
|
11
|
-
introspectComments: true,
|
|
12
|
-
dtoFileNameSuffix: ['.dto.ts', '.class.ts'],
|
|
13
|
-
},
|
|
14
|
-
cs.program, // "cs.tsCompiler.program" for older versions of Jest (<= v27)
|
|
15
|
-
);
|
|
16
|
-
};
|
package/test/express.e2e-spec.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { NestFactory } from '@nestjs/core';
|
|
2
|
-
import { ExpressAdapter, NestExpressApplication } from '@nestjs/platform-express';
|
|
3
|
-
import * as fs from 'fs/promises';
|
|
4
|
-
import jsyaml from 'js-yaml';
|
|
5
|
-
import request from 'supertest';
|
|
6
|
-
import { AsyncApiModule } from '../src';
|
|
7
|
-
import { AppModule } from '../sample/app.module';
|
|
8
|
-
import { makeAsyncapiDocument } from '../sample/common';
|
|
9
|
-
import { DOC_RELATIVE_PATH } from '../sample/constants';
|
|
10
|
-
|
|
11
|
-
describe('Express AsyncAPI', () => {
|
|
12
|
-
let app: NestExpressApplication;
|
|
13
|
-
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
app = await NestFactory.create<NestExpressApplication>(AppModule, new ExpressAdapter(), { logger: false });
|
|
16
|
-
const asyncapiDocument = await makeAsyncapiDocument(app);
|
|
17
|
-
await AsyncApiModule.setup(DOC_RELATIVE_PATH, app, asyncapiDocument);
|
|
18
|
-
|
|
19
|
-
await app.init();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should serve doc html', async () => {
|
|
23
|
-
const { text } = await request(app.getHttpServer())
|
|
24
|
-
.get(DOC_RELATIVE_PATH)
|
|
25
|
-
.expect(200)
|
|
26
|
-
.expect('Content-Type', /text\/html/);
|
|
27
|
-
const htmlSample = await fs.readFile('./misc/references/ref.html', {
|
|
28
|
-
encoding: 'utf8',
|
|
29
|
-
});
|
|
30
|
-
expect(text).toEqual(htmlSample);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should serve doc json', async () => {
|
|
34
|
-
const { text } = await request(app.getHttpServer())
|
|
35
|
-
.get(`${DOC_RELATIVE_PATH}-json`)
|
|
36
|
-
.expect(200)
|
|
37
|
-
.expect('Content-Type', /application\/json/);
|
|
38
|
-
|
|
39
|
-
const jsonFetched = JSON.parse(text);
|
|
40
|
-
const jsonReferenceSample = JSON.parse(
|
|
41
|
-
await fs.readFile('./misc/references/ref.json', {
|
|
42
|
-
encoding: 'utf8',
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
expect(jsonFetched).toEqual(jsonReferenceSample);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should serve doc yaml', async () => {
|
|
50
|
-
const { text } = await request(app.getHttpServer())
|
|
51
|
-
.get(`${DOC_RELATIVE_PATH}-yaml`)
|
|
52
|
-
.expect(200)
|
|
53
|
-
.expect('Content-Type', /text\/yaml/);
|
|
54
|
-
|
|
55
|
-
const yamlFetched = jsyaml.load(text);
|
|
56
|
-
const yamlReferenceSample = jsyaml.load(
|
|
57
|
-
await fs.readFile('./misc/references/ref.yaml', {
|
|
58
|
-
encoding: 'utf8',
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
expect(yamlFetched).toEqual(yamlReferenceSample);
|
|
63
|
-
});
|
|
64
|
-
});
|
package/test/fastify.e2e-spec.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { NestFactory } from '@nestjs/core';
|
|
2
|
-
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
|
|
3
|
-
import fs from 'fs/promises';
|
|
4
|
-
import jsyaml from 'js-yaml';
|
|
5
|
-
import request from 'supertest';
|
|
6
|
-
import { AsyncApiModule } from '../src';
|
|
7
|
-
import { AppModule } from '../sample/app.module';
|
|
8
|
-
import { makeAsyncapiDocument } from '../sample/common';
|
|
9
|
-
import { DOC_RELATIVE_PATH } from '../sample/constants';
|
|
10
|
-
|
|
11
|
-
describe('Fastify AsyncAPI', () => {
|
|
12
|
-
let app: NestFastifyApplication;
|
|
13
|
-
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter(), { logger: false });
|
|
16
|
-
const asyncapiDocument = await makeAsyncapiDocument(app);
|
|
17
|
-
await AsyncApiModule.setup(DOC_RELATIVE_PATH, app, asyncapiDocument);
|
|
18
|
-
|
|
19
|
-
await app.init();
|
|
20
|
-
await app.getHttpAdapter().getInstance().ready();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should serve doc html', async () => {
|
|
24
|
-
const { text } = await request(app.getHttpServer())
|
|
25
|
-
.get(DOC_RELATIVE_PATH)
|
|
26
|
-
.expect(200)
|
|
27
|
-
.expect('Content-Type', /text\/html/);
|
|
28
|
-
const htmlSample = await fs.readFile('./misc/references/ref.html', {
|
|
29
|
-
encoding: 'utf8',
|
|
30
|
-
});
|
|
31
|
-
expect(text).toEqual(htmlSample);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should serve doc json', async () => {
|
|
35
|
-
const { text } = await request(app.getHttpServer())
|
|
36
|
-
.get(`${DOC_RELATIVE_PATH}-json`)
|
|
37
|
-
.expect(200)
|
|
38
|
-
.expect('Content-Type', /application\/json/);
|
|
39
|
-
|
|
40
|
-
const jsonFetched = JSON.parse(text);
|
|
41
|
-
const jsonReferenceSample = JSON.parse(
|
|
42
|
-
await fs.readFile('./misc/references/ref.json', {
|
|
43
|
-
encoding: 'utf8',
|
|
44
|
-
}),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(jsonFetched).toEqual(jsonReferenceSample);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should serve doc yaml', async () => {
|
|
51
|
-
const { text } = await request(app.getHttpServer())
|
|
52
|
-
.get(`${DOC_RELATIVE_PATH}-yaml`)
|
|
53
|
-
.expect(200)
|
|
54
|
-
.expect('Content-Type', /text\/yaml/);
|
|
55
|
-
|
|
56
|
-
const yamlFetched = jsyaml.load(text);
|
|
57
|
-
const yamlReferenceSample = jsyaml.load(
|
|
58
|
-
await fs.readFile('./misc/references/ref.yaml', {
|
|
59
|
-
encoding: 'utf8',
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
expect(yamlFetched).toEqual(yamlReferenceSample);
|
|
64
|
-
});
|
|
65
|
-
});
|
package/tsconfig.build.json
DELETED