@eventcatalog/generator-asyncapi 5.5.0 → 5.5.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
+ attachHeadersToSchema: z.ZodOptional<z.ZodBoolean>;
244
245
  saveParsedSpecFile: z.ZodOptional<z.ZodBoolean>;
245
246
  }, "strip", z.ZodTypeAny, {
246
247
  services: {
@@ -303,6 +304,7 @@ declare const optionsSchema: z.ZodObject<{
303
304
  debug?: boolean | undefined;
304
305
  parseSchemas?: boolean | undefined;
305
306
  parseChannels?: boolean | undefined;
307
+ attachHeadersToSchema?: boolean | undefined;
306
308
  saveParsedSpecFile?: boolean | undefined;
307
309
  }, {
308
310
  services: {
@@ -365,6 +367,7 @@ declare const optionsSchema: z.ZodObject<{
365
367
  debug?: boolean | undefined;
366
368
  parseSchemas?: boolean | undefined;
367
369
  parseChannels?: boolean | undefined;
370
+ attachHeadersToSchema?: boolean | undefined;
368
371
  saveParsedSpecFile?: boolean | undefined;
369
372
  }>;
370
373
  type Props = z.infer<typeof optionsSchema>;
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
+ attachHeadersToSchema: z.ZodOptional<z.ZodBoolean>;
244
245
  saveParsedSpecFile: z.ZodOptional<z.ZodBoolean>;
245
246
  }, "strip", z.ZodTypeAny, {
246
247
  services: {
@@ -303,6 +304,7 @@ declare const optionsSchema: z.ZodObject<{
303
304
  debug?: boolean | undefined;
304
305
  parseSchemas?: boolean | undefined;
305
306
  parseChannels?: boolean | undefined;
307
+ attachHeadersToSchema?: boolean | undefined;
306
308
  saveParsedSpecFile?: boolean | undefined;
307
309
  }, {
308
310
  services: {
@@ -365,6 +367,7 @@ declare const optionsSchema: z.ZodObject<{
365
367
  debug?: boolean | undefined;
366
368
  parseSchemas?: boolean | undefined;
367
369
  parseChannels?: boolean | undefined;
370
+ attachHeadersToSchema?: boolean | undefined;
368
371
  saveParsedSpecFile?: boolean | undefined;
369
372
  }>;
370
373
  type Props = z.infer<typeof optionsSchema>;
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: "5.5.0",
1546
+ version: "5.5.1",
1547
1547
  description: "AsyncAPI generator for EventCatalog",
1548
1548
  scripts: {
1549
1549
  build: "tsup",
@@ -4163,6 +4163,7 @@ var optionsSchema = import_zod.z.object({
4163
4163
  debug: import_zod.z.boolean().optional(),
4164
4164
  parseSchemas: import_zod.z.boolean().optional(),
4165
4165
  parseChannels: import_zod.z.boolean().optional(),
4166
+ attachHeadersToSchema: import_zod.z.boolean().optional(),
4166
4167
  saveParsedSpecFile: import_zod.z.boolean({ invalid_type_error: "The saveParsedSpecFile is not a boolean in options" }).optional()
4167
4168
  });
4168
4169
  var toUniqueArray = (array) => {
@@ -4241,7 +4242,13 @@ var index_default = async (config, options) => {
4241
4242
  }
4242
4243
  };
4243
4244
  validateOptions(options);
4244
- const { services, saveParsedSpecFile = false, parseSchemas = true, parseChannels = false } = options;
4245
+ const {
4246
+ services,
4247
+ saveParsedSpecFile = false,
4248
+ parseSchemas = true,
4249
+ parseChannels = false,
4250
+ attachHeadersToSchema = false
4251
+ } = options;
4245
4252
  console.log(import_chalk4.default.green(`Processing ${services.length} AsyncAPI files...`));
4246
4253
  for (const service of services) {
4247
4254
  console.log(import_chalk4.default.gray(`Processing ${service.path}`));
@@ -4444,10 +4451,7 @@ Processing domain: ${domainName} (v${domainVersion})`));
4444
4451
  );
4445
4452
  console.log(import_chalk4.default.cyan(` - Message (v${messageVersion}) created`));
4446
4453
  if (messageHasSchema(message2)) {
4447
- let schema = message2.payload()?.extensions()?.get("x-parser-original-payload")?.json() || message2.payload()?.json();
4448
- if (schema?.schema) {
4449
- schema = schema.schema;
4450
- }
4454
+ const schema = getSchemaForMessage(message2, attachHeadersToSchema);
4451
4455
  const cleanedMessagePath = messagePath.replace(/\\/g, "/").replace(/^(\.\.\/|\.\/)+/g, "");
4452
4456
  await addSchemaToMessage(
4453
4457
  messageId,
@@ -4568,6 +4572,36 @@ Failed to request AsyncAPI file from ${service.path}`));
4568
4572
  return await (0, import_promises.readFile)(service.path, "utf8");
4569
4573
  }
4570
4574
  };
4575
+ var getSchemaForMessage = (message2, attachHeadersToSchema) => {
4576
+ const payloadSchema = getSchemaFromMessagePart(
4577
+ message2.payload()?.extensions()?.get("x-parser-original-payload")?.json() || message2.payload()?.json()
4578
+ );
4579
+ if (!attachHeadersToSchema || !message2.hasHeaders() || !isJSONSchemaMessage(message2)) {
4580
+ return payloadSchema;
4581
+ }
4582
+ const headersSchema = getSchemaFromMessagePart(
4583
+ message2.headers()?.extensions()?.get("x-parser-original-payload")?.json() || message2.headers()?.json()
4584
+ );
4585
+ if (!headersSchema) {
4586
+ return payloadSchema;
4587
+ }
4588
+ return {
4589
+ type: "object",
4590
+ properties: {
4591
+ headers: headersSchema,
4592
+ payload: payloadSchema
4593
+ }
4594
+ };
4595
+ };
4596
+ var getSchemaFromMessagePart = (schema) => {
4597
+ if (schema?.schema) {
4598
+ return schema.schema;
4599
+ }
4600
+ return schema;
4601
+ };
4602
+ var isJSONSchemaMessage = (message2) => {
4603
+ return getSchemaFileName(message2).endsWith(".json");
4604
+ };
4571
4605
  var isServiceMessageOwner = (message2, operation) => {
4572
4606
  const operationRole = operation?.extensions?.().get?.("x-eventcatalog-role")?.value?.();
4573
4607
  const messageRole = message2.extensions().get("x-eventcatalog-role")?.value();