@eventcatalog/generator-asyncapi 6.0.1 → 6.1.1

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.d.mts CHANGED
@@ -241,6 +241,7 @@ declare const optionsSchema: z.ZodObject<{
241
241
  debug: z.ZodOptional<z.ZodBoolean>;
242
242
  parseSchemas: z.ZodOptional<z.ZodBoolean>;
243
243
  parseChannels: z.ZodOptional<z.ZodBoolean>;
244
+ parseExamples: z.ZodOptional<z.ZodBoolean>;
244
245
  attachHeadersToSchema: z.ZodOptional<z.ZodBoolean>;
245
246
  saveParsedSpecFile: z.ZodOptional<z.ZodBoolean>;
246
247
  }, "strip", z.ZodTypeAny, {
@@ -304,6 +305,7 @@ declare const optionsSchema: z.ZodObject<{
304
305
  debug?: boolean | undefined;
305
306
  parseSchemas?: boolean | undefined;
306
307
  parseChannels?: boolean | undefined;
308
+ parseExamples?: boolean | undefined;
307
309
  attachHeadersToSchema?: boolean | undefined;
308
310
  saveParsedSpecFile?: boolean | undefined;
309
311
  }, {
@@ -367,6 +369,7 @@ declare const optionsSchema: z.ZodObject<{
367
369
  debug?: boolean | undefined;
368
370
  parseSchemas?: boolean | undefined;
369
371
  parseChannels?: boolean | undefined;
372
+ parseExamples?: boolean | undefined;
370
373
  attachHeadersToSchema?: boolean | undefined;
371
374
  saveParsedSpecFile?: boolean | undefined;
372
375
  }>;
package/dist/index.d.ts CHANGED
@@ -241,6 +241,7 @@ declare const optionsSchema: z.ZodObject<{
241
241
  debug: z.ZodOptional<z.ZodBoolean>;
242
242
  parseSchemas: z.ZodOptional<z.ZodBoolean>;
243
243
  parseChannels: z.ZodOptional<z.ZodBoolean>;
244
+ parseExamples: z.ZodOptional<z.ZodBoolean>;
244
245
  attachHeadersToSchema: z.ZodOptional<z.ZodBoolean>;
245
246
  saveParsedSpecFile: z.ZodOptional<z.ZodBoolean>;
246
247
  }, "strip", z.ZodTypeAny, {
@@ -304,6 +305,7 @@ declare const optionsSchema: z.ZodObject<{
304
305
  debug?: boolean | undefined;
305
306
  parseSchemas?: boolean | undefined;
306
307
  parseChannels?: boolean | undefined;
308
+ parseExamples?: boolean | undefined;
307
309
  attachHeadersToSchema?: boolean | undefined;
308
310
  saveParsedSpecFile?: boolean | undefined;
309
311
  }, {
@@ -367,6 +369,7 @@ declare const optionsSchema: z.ZodObject<{
367
369
  debug?: boolean | undefined;
368
370
  parseSchemas?: boolean | undefined;
369
371
  parseChannels?: boolean | undefined;
372
+ parseExamples?: boolean | undefined;
370
373
  attachHeadersToSchema?: boolean | undefined;
371
374
  saveParsedSpecFile?: boolean | undefined;
372
375
  }>;
package/dist/index.js CHANGED
@@ -1543,7 +1543,7 @@ var import_path3 = __toESM(require("path"));
1543
1543
  // package.json
1544
1544
  var package_default = {
1545
1545
  name: "@eventcatalog/generator-asyncapi",
1546
- version: "6.0.1",
1546
+ version: "6.1.1",
1547
1547
  description: "AsyncAPI generator for EventCatalog",
1548
1548
  scripts: {
1549
1549
  build: "tsup",
@@ -1581,10 +1581,10 @@ var package_default = {
1581
1581
  dependencies: {
1582
1582
  "@asyncapi/avro-schema-parser": "3.0.24",
1583
1583
  "@asyncapi/parser": "3.6.0",
1584
- "@eventcatalog/sdk": "2.12.1",
1584
+ "@eventcatalog/sdk": "2.17.4",
1585
1585
  chalk: "4.1.2",
1586
1586
  "fs-extra": "^11.2.0",
1587
- glob: "^11.0.0",
1587
+ glob: "^12.0.0",
1588
1588
  "gray-matter": "^4.0.3",
1589
1589
  "js-yaml": "^4.1.0",
1590
1590
  lodash: "^4.17.23",
@@ -4071,6 +4071,26 @@ Failed to verify license key`));
4071
4071
  // src/index.ts
4072
4072
  var import_node_path = require("path");
4073
4073
  var parser = new import_parser.Parser();
4074
+ var safeStringify = (obj, indent) => {
4075
+ const seen = /* @__PURE__ */ new WeakSet();
4076
+ return JSON.stringify(
4077
+ obj,
4078
+ (_key, value) => {
4079
+ if (typeof value === "object" && value !== null) {
4080
+ if (seen.has(value)) {
4081
+ const schemaId = value["x-parser-schema-id"];
4082
+ if (schemaId && typeof schemaId === "string") {
4083
+ return { $ref: `#/components/schemas/${schemaId}` };
4084
+ }
4085
+ return { $ref: "#" };
4086
+ }
4087
+ seen.add(value);
4088
+ }
4089
+ return value;
4090
+ },
4091
+ indent
4092
+ );
4093
+ };
4074
4094
  parser.registerSchemaParser((0, import_avro_schema_parser.AvroSchemaParser)());
4075
4095
  var cliArgs = (0, import_minimist.default)(process.argv.slice(2));
4076
4096
  var optionsSchema = import_zod.z.object({
@@ -4139,6 +4159,7 @@ var optionsSchema = import_zod.z.object({
4139
4159
  debug: import_zod.z.boolean().optional(),
4140
4160
  parseSchemas: import_zod.z.boolean().optional(),
4141
4161
  parseChannels: import_zod.z.boolean().optional(),
4162
+ parseExamples: import_zod.z.boolean().optional(),
4142
4163
  attachHeadersToSchema: import_zod.z.boolean().optional(),
4143
4164
  saveParsedSpecFile: import_zod.z.boolean({ invalid_type_error: "The saveParsedSpecFile is not a boolean in options" }).optional()
4144
4165
  });
@@ -4192,7 +4213,10 @@ var index_default = async (config, options) => {
4192
4213
  getSpecificationFilesForService,
4193
4214
  writeChannel,
4194
4215
  getChannel,
4195
- versionChannel
4216
+ versionChannel,
4217
+ addExampleToEvent,
4218
+ addExampleToCommand,
4219
+ addExampleToQuery
4196
4220
  } = (0, import_sdk.default)(process.env.PROJECT_DIR);
4197
4221
  const MESSAGE_OPERATIONS = {
4198
4222
  event: {
@@ -4200,6 +4224,7 @@ var index_default = async (config, options) => {
4200
4224
  version: versionEvent,
4201
4225
  get: getEvent,
4202
4226
  addSchema: addSchemaToEvent,
4227
+ addExample: addExampleToEvent,
4203
4228
  collection: "events"
4204
4229
  },
4205
4230
  command: {
@@ -4207,6 +4232,7 @@ var index_default = async (config, options) => {
4207
4232
  version: versionCommand,
4208
4233
  get: getCommand,
4209
4234
  addSchema: addSchemaToCommand,
4235
+ addExample: addExampleToCommand,
4210
4236
  collection: "commands"
4211
4237
  },
4212
4238
  query: {
@@ -4214,6 +4240,7 @@ var index_default = async (config, options) => {
4214
4240
  version: versionQuery,
4215
4241
  get: getQuery,
4216
4242
  addSchema: addSchemaToQuery,
4243
+ addExample: addExampleToQuery,
4217
4244
  collection: "queries"
4218
4245
  }
4219
4246
  };
@@ -4223,6 +4250,7 @@ var index_default = async (config, options) => {
4223
4250
  saveParsedSpecFile = false,
4224
4251
  parseSchemas = true,
4225
4252
  parseChannels = false,
4253
+ parseExamples = true,
4226
4254
  attachHeadersToSchema = false
4227
4255
  } = options;
4228
4256
  console.log(import_chalk4.default.green(`Processing ${services.length} AsyncAPI files...`));
@@ -4379,6 +4407,7 @@ Processing domain: ${domainName} (v${domainVersion})`));
4379
4407
  version: versionMessage,
4380
4408
  get: getMessage,
4381
4409
  addSchema: addSchemaToMessage,
4410
+ addExample: addExampleToMessage,
4382
4411
  collection: folder
4383
4412
  } = MESSAGE_OPERATIONS[eventType];
4384
4413
  const generatedMarkdownForMessage = defaultMarkdown(document2, message2);
@@ -4431,13 +4460,27 @@ Processing domain: ${domainName} (v${domainVersion})`));
4431
4460
  messageId,
4432
4461
  {
4433
4462
  fileName: getSchemaFileName(message2),
4434
- schema: JSON.stringify(schema, null, 4)
4463
+ schema: safeStringify(schema, 4)
4435
4464
  },
4436
4465
  messageVersion,
4437
4466
  { path: cleanedMessagePath }
4438
4467
  );
4439
4468
  console.log(import_chalk4.default.cyan(` - Schema added to message (v${messageVersion})`));
4440
4469
  }
4470
+ if (parseExamples) {
4471
+ const messageExamples = message2.examples().all();
4472
+ for (let i = 0; i < messageExamples.length; i++) {
4473
+ const example = messageExamples[i];
4474
+ const payload = example.payload();
4475
+ if (payload) {
4476
+ const fileName2 = example.hasName() ? `${example.name()}.json` : `example-${i}.json`;
4477
+ await addExampleToMessage(messageId, { content: JSON.stringify(payload, null, 2), fileName: fileName2 }, messageVersion);
4478
+ }
4479
+ }
4480
+ if (messageExamples.length > 0) {
4481
+ console.log(import_chalk4.default.cyan(` - ${messageExamples.length} example(s) added to message (v${messageVersion})`));
4482
+ }
4483
+ }
4441
4484
  } else {
4442
4485
  console.log(import_chalk4.default.yellow(` - Skipping external message: ${getMessageName(message2)}(v${messageVersion})`));
4443
4486
  }
@@ -4539,7 +4582,7 @@ Finished generating event catalog for AsyncAPI ${serviceId} (v${version})`));
4539
4582
  };
4540
4583
  var getParsedSpecFile = (service, document2) => {
4541
4584
  const isSpecFileJSON = service.path.endsWith(".json");
4542
- return isSpecFileJSON ? JSON.stringify(document2.meta().asyncapi.parsed, null, 4) : import_js_yaml.default.dump(document2.meta().asyncapi.parsed, { noRefs: true });
4585
+ return isSpecFileJSON ? safeStringify(document2.meta().asyncapi.parsed, 4) : import_js_yaml.default.dump(document2.meta().asyncapi.parsed, { noRefs: true });
4543
4586
  };
4544
4587
  var getRawSpecFile = async (service) => {
4545
4588
  if (service.path.startsWith("http")) {