@eventcatalog/generator-openapi 7.9.0 → 7.10.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/index.js CHANGED
@@ -1610,15 +1610,19 @@ async function getSchemasByOperationId(filePath, operationId, parsedDocument) {
1610
1610
  }
1611
1611
  if (typedOperation.requestBody && typedOperation.requestBody.content) {
1612
1612
  const contentType = Object.keys(typedOperation.requestBody.content)[0];
1613
- schemas.requestBody = typedOperation.requestBody.content[contentType].schema;
1613
+ if (contentType) {
1614
+ schemas.requestBody = typedOperation.requestBody.content[contentType].schema;
1615
+ }
1614
1616
  }
1615
1617
  if (typedOperation.responses) {
1616
1618
  for (const [statusCode, response] of Object.entries(typedOperation.responses)) {
1617
1619
  if (response.content) {
1618
1620
  const contentType = Object.keys(response.content)[0];
1619
- const schemaOrContent = response.content[contentType].schema || response.content[contentType];
1620
- schemas.responses[statusCode] = { ...schemaOrContent };
1621
- schemas.responses[statusCode].isSchema = !!response.content[contentType].schema;
1621
+ if (contentType) {
1622
+ const schemaOrContent = response.content[contentType].schema || response.content[contentType];
1623
+ schemas.responses[statusCode] = { ...schemaOrContent };
1624
+ schemas.responses[statusCode].isSchema = !!response.content[contentType].schema;
1625
+ }
1622
1626
  }
1623
1627
  }
1624
1628
  }
@@ -1641,14 +1645,16 @@ async function getExamplesByOperationId(filePath, operationId, parsedDocument) {
1641
1645
  if (typedOperation.operationId !== operationId) continue;
1642
1646
  if (typedOperation.requestBody?.content) {
1643
1647
  const contentType = Object.keys(typedOperation.requestBody.content)[0];
1644
- const mediaType = typedOperation.requestBody.content[contentType];
1645
- if (mediaType.example) {
1646
- examples.push({ fileName: "example.json", content: JSON.stringify(mediaType.example, null, 2) });
1647
- }
1648
- if (mediaType.examples) {
1649
- for (const [name, exampleObj] of Object.entries(mediaType.examples)) {
1650
- if (exampleObj.value) {
1651
- examples.push({ fileName: `${name}.json`, content: JSON.stringify(exampleObj.value, null, 2) });
1648
+ if (contentType) {
1649
+ const mediaType = typedOperation.requestBody.content[contentType];
1650
+ if (mediaType.example) {
1651
+ examples.push({ fileName: "example.json", content: JSON.stringify(mediaType.example, null, 2) });
1652
+ }
1653
+ if (mediaType.examples) {
1654
+ for (const [name, exampleObj] of Object.entries(mediaType.examples)) {
1655
+ if (exampleObj.value) {
1656
+ examples.push({ fileName: `${name}.json`, content: JSON.stringify(exampleObj.value, null, 2) });
1657
+ }
1652
1658
  }
1653
1659
  }
1654
1660
  }
@@ -1657,17 +1663,19 @@ async function getExamplesByOperationId(filePath, operationId, parsedDocument) {
1657
1663
  for (const [statusCode, response] of Object.entries(typedOperation.responses)) {
1658
1664
  if (response.content) {
1659
1665
  const contentType = Object.keys(response.content)[0];
1660
- const mediaType = response.content[contentType];
1661
- if (mediaType.example) {
1662
- examples.push({ fileName: `response-${statusCode}.json`, content: JSON.stringify(mediaType.example, null, 2) });
1663
- }
1664
- if (mediaType.examples) {
1665
- for (const [name, exampleObj] of Object.entries(mediaType.examples)) {
1666
- if (exampleObj.value) {
1667
- examples.push({
1668
- fileName: `response-${statusCode}-${name}.json`,
1669
- content: JSON.stringify(exampleObj.value, null, 2)
1670
- });
1666
+ if (contentType) {
1667
+ const mediaType = response.content[contentType];
1668
+ if (mediaType.example) {
1669
+ examples.push({ fileName: `response-${statusCode}.json`, content: JSON.stringify(mediaType.example, null, 2) });
1670
+ }
1671
+ if (mediaType.examples) {
1672
+ for (const [name, exampleObj] of Object.entries(mediaType.examples)) {
1673
+ if (exampleObj.value) {
1674
+ examples.push({
1675
+ fileName: `response-${statusCode}-${name}.json`,
1676
+ content: JSON.stringify(exampleObj.value, null, 2)
1677
+ });
1678
+ }
1671
1679
  }
1672
1680
  }
1673
1681
  }
@@ -4205,7 +4213,7 @@ var import_node_path = require("path");
4205
4213
  // package.json
4206
4214
  var package_default = {
4207
4215
  name: "@eventcatalog/generator-openapi",
4208
- version: "7.9.0",
4216
+ version: "7.10.0",
4209
4217
  description: "OpenAPI generator for EventCatalog",
4210
4218
  scripts: {
4211
4219
  build: "tsup",
@@ -4242,7 +4250,7 @@ var package_default = {
4242
4250
  dependencies: {
4243
4251
  "@apidevtools/swagger-parser": "^10.1.0",
4244
4252
  "@changesets/cli": "^2.27.7",
4245
- "@eventcatalog/sdk": "2.17.4",
4253
+ "@eventcatalog/sdk": "^2.18.2",
4246
4254
  chalk: "4.1.2",
4247
4255
  "js-yaml": "^4.1.0",
4248
4256
  "openapi-types": "^12.1.3",
@@ -4423,7 +4431,8 @@ var index_default = async (_, options) => {
4423
4431
  getService,
4424
4432
  versionService,
4425
4433
  writeService,
4426
- addFileToService
4434
+ addFileToService,
4435
+ getResourcePath
4427
4436
  } = (0, import_sdk2.default)(process.env.PROJECT_DIR);
4428
4437
  const { services = [], saveParsedSpecFile = false } = options;
4429
4438
  for (const serviceSpec of services) {
@@ -4480,10 +4489,6 @@ var index_default = async (_, options) => {
4480
4489
  // @ts-ignore
4481
4490
  isDomainMarkedAsDraft || document2.info?.["x-eventcatalog-draft"] || serviceSpec.draft || null
4482
4491
  );
4483
- let servicePath = options.domain ? (0, import_node_path.join)("../", "domains", options.domain.id, "services", service.id) : (0, import_node_path.join)("../", "services", service.id);
4484
- if (options.writeFilesToRoot) {
4485
- servicePath = service.id;
4486
- }
4487
4492
  if (options.domain) {
4488
4493
  const { id: domainId, name: domainName, version: domainVersion } = options.domain;
4489
4494
  const domain = await getDomain(options.domain.id, domainVersion || "latest");
@@ -4511,6 +4516,22 @@ Processing domain: ${domainName} (v${domainVersion})`));
4511
4516
  }
4512
4517
  await addServiceToDomain(domainId, { id: service.id, version: service.version }, domainVersion);
4513
4518
  }
4519
+ let servicePath = (0, import_node_path.join)("../", "services", service.id);
4520
+ if (options.domain) {
4521
+ const domainResource = await getResourcePath(
4522
+ process.env.PROJECT_DIR,
4523
+ options.domain.id,
4524
+ options.domain.version
4525
+ );
4526
+ if (domainResource) {
4527
+ servicePath = (0, import_node_path.join)("../", domainResource.directory, "services", service.id);
4528
+ } else {
4529
+ servicePath = (0, import_node_path.join)("../", "domains", options.domain.id, "services", service.id);
4530
+ }
4531
+ }
4532
+ if (options.writeFilesToRoot) {
4533
+ servicePath = service.id;
4534
+ }
4514
4535
  const latestServiceInCatalog = await getService(service.id, "latest");
4515
4536
  const versionTheService = latestServiceInCatalog && isVersionGreaterThan(version, latestServiceInCatalog.version);
4516
4537
  console.log(import_chalk4.default.blue(`Processing service: ${document2.info.title} (v${version})`));