@eventcatalog/generator-openapi 7.6.5 → 7.7.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 +44 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -12
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.mts +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1589,9 +1589,9 @@ var buildService = (serviceOptions, document2, generateMarkdown) => {
|
|
|
1589
1589
|
// src/utils/openapi.ts
|
|
1590
1590
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
1591
1591
|
var DEFAULT_MESSAGE_TYPE = "query";
|
|
1592
|
-
async function getSchemasByOperationId(filePath, operationId) {
|
|
1592
|
+
async function getSchemasByOperationId(filePath, operationId, parsedDocument) {
|
|
1593
1593
|
try {
|
|
1594
|
-
const api = await SwaggerParser.dereference(filePath);
|
|
1594
|
+
const api = parsedDocument || await SwaggerParser.dereference(filePath);
|
|
1595
1595
|
const schemas = {
|
|
1596
1596
|
parameters: [],
|
|
1597
1597
|
requestBody: null,
|
|
@@ -1612,7 +1612,8 @@ async function getSchemasByOperationId(filePath, operationId) {
|
|
|
1612
1612
|
for (const [statusCode, response] of Object.entries(typedOperation.responses)) {
|
|
1613
1613
|
if (response.content) {
|
|
1614
1614
|
const contentType = Object.keys(response.content)[0];
|
|
1615
|
-
|
|
1615
|
+
const schemaOrContent = response.content[contentType].schema || response.content[contentType];
|
|
1616
|
+
schemas.responses[statusCode] = { ...schemaOrContent };
|
|
1616
1617
|
schemas.responses[statusCode].isSchema = !!response.content[contentType].schema;
|
|
1617
1618
|
}
|
|
1618
1619
|
}
|
|
@@ -1640,9 +1641,9 @@ function getDeprecatedValues(openAPIOperation) {
|
|
|
1640
1641
|
}
|
|
1641
1642
|
return deprecated;
|
|
1642
1643
|
}
|
|
1643
|
-
async function getOperationsByType(openApiPath, httpMethodsToMessages) {
|
|
1644
|
+
async function getOperationsByType(openApiPath, httpMethodsToMessages, parsedDocument) {
|
|
1644
1645
|
try {
|
|
1645
|
-
const api = await SwaggerParser.validate(openApiPath);
|
|
1646
|
+
const api = parsedDocument || await SwaggerParser.validate(openApiPath);
|
|
1646
1647
|
const operations = [];
|
|
1647
1648
|
for (const path4 in api.paths) {
|
|
1648
1649
|
const pathItem = api.paths[path4];
|
|
@@ -1810,7 +1811,7 @@ var getSummary2 = (message2) => {
|
|
|
1810
1811
|
return escapeSpecialCharactersThatBreakMarkdown(eventCatalogMessageSummary);
|
|
1811
1812
|
};
|
|
1812
1813
|
var buildMessage = async (pathToFile, document2, operation, generateMarkdown, messageIdConfig, serviceId, serviceVersion) => {
|
|
1813
|
-
const requestBodiesAndResponses = await getSchemasByOperationId(pathToFile, operation.operationId);
|
|
1814
|
+
const requestBodiesAndResponses = await getSchemasByOperationId(pathToFile, operation.operationId, document2);
|
|
1814
1815
|
const extensions = operation.extensions || {};
|
|
1815
1816
|
const operationTags = operation.tags.map((badge) => ({
|
|
1816
1817
|
content: `tag:${badge}`,
|
|
@@ -4067,7 +4068,7 @@ import { join } from "path";
|
|
|
4067
4068
|
// package.json
|
|
4068
4069
|
var package_default = {
|
|
4069
4070
|
name: "@eventcatalog/generator-openapi",
|
|
4070
|
-
version: "7.
|
|
4071
|
+
version: "7.7.0",
|
|
4071
4072
|
description: "OpenAPI generator for EventCatalog",
|
|
4072
4073
|
scripts: {
|
|
4073
4074
|
build: "tsup",
|
|
@@ -4180,6 +4181,25 @@ var isVersionLessThan = (version, givenVersion) => {
|
|
|
4180
4181
|
var toUniqueArray = (array) => {
|
|
4181
4182
|
return array.filter((item, index, self) => index === self.findIndex((t) => t.id === item.id && t.version === item.version));
|
|
4182
4183
|
};
|
|
4184
|
+
var fetchAuthenticatedSpec = async (specUrl, headers) => {
|
|
4185
|
+
const response = await fetch(specUrl, { method: "GET", headers });
|
|
4186
|
+
if (!response.ok) {
|
|
4187
|
+
throw new Error(`Failed to fetch file: ${specUrl}, status: ${response.status}`);
|
|
4188
|
+
}
|
|
4189
|
+
const content = await response.text();
|
|
4190
|
+
const contentType = response.headers.get("content-type") || "";
|
|
4191
|
+
if (contentType.includes("json")) {
|
|
4192
|
+
return JSON.parse(content);
|
|
4193
|
+
}
|
|
4194
|
+
if (contentType.includes("yaml")) {
|
|
4195
|
+
return yaml.load(content);
|
|
4196
|
+
}
|
|
4197
|
+
try {
|
|
4198
|
+
return JSON.parse(content);
|
|
4199
|
+
} catch {
|
|
4200
|
+
return yaml.load(content);
|
|
4201
|
+
}
|
|
4202
|
+
};
|
|
4183
4203
|
var mergeOpenApiIntoSpecifications = (existingSpecs, openapiFileName) => {
|
|
4184
4204
|
if (Array.isArray(existingSpecs)) {
|
|
4185
4205
|
return [...existingSpecs.filter((spec) => spec.type !== "openapi"), { type: "openapi", path: openapiFileName }];
|
|
@@ -4213,8 +4233,17 @@ var index_default = async (_, options) => {
|
|
|
4213
4233
|
const specFiles = Array.isArray(serviceSpec.path) ? serviceSpec.path : [serviceSpec.path];
|
|
4214
4234
|
const specs = specFiles.map(async (specFile) => {
|
|
4215
4235
|
try {
|
|
4216
|
-
|
|
4217
|
-
const
|
|
4236
|
+
const isUrl = specFile.startsWith("http");
|
|
4237
|
+
const hasHeaders = serviceSpec.headers && Object.keys(serviceSpec.headers).length > 0;
|
|
4238
|
+
let document2;
|
|
4239
|
+
if (isUrl && hasHeaders) {
|
|
4240
|
+
const parsedSpec = await fetchAuthenticatedSpec(specFile, serviceSpec.headers);
|
|
4241
|
+
await SwaggerParser2.validate(parsedSpec);
|
|
4242
|
+
document2 = await SwaggerParser2.dereference(parsedSpec);
|
|
4243
|
+
} else {
|
|
4244
|
+
await SwaggerParser2.validate(specFile);
|
|
4245
|
+
document2 = await SwaggerParser2.dereference(specFile);
|
|
4246
|
+
}
|
|
4218
4247
|
return {
|
|
4219
4248
|
document: document2,
|
|
4220
4249
|
path: specFile,
|
|
@@ -4333,7 +4362,6 @@ Processing domain: ${domainName} (v${domainVersion})`));
|
|
|
4333
4362
|
// @ts-ignore
|
|
4334
4363
|
toUniqueArray([...latestServiceInCatalog.receives, ...receives])
|
|
4335
4364
|
) : receives;
|
|
4336
|
-
console.log("MEOW", "HELLO", latestServiceInCatalog.writesTo, serviceWritesTo);
|
|
4337
4365
|
serviceWritesTo = latestServiceInCatalog.writesTo ? toUniqueArray([...latestServiceInCatalog.writesTo, ...configuredWritesTo]) : configuredWritesTo;
|
|
4338
4366
|
serviceReadsFrom = latestServiceInCatalog.readsFrom ? toUniqueArray([...latestServiceInCatalog.readsFrom, ...configuredReadsFrom]) : configuredReadsFrom;
|
|
4339
4367
|
}
|
|
@@ -4381,7 +4409,7 @@ Processing domain: ${domainName} (v${domainVersion})`));
|
|
|
4381
4409
|
}
|
|
4382
4410
|
};
|
|
4383
4411
|
var processMessagesForOpenAPISpec = async (pathToSpec, document2, servicePath, options) => {
|
|
4384
|
-
const operations = await getOperationsByType(pathToSpec, options.httpMethodsToMessages);
|
|
4412
|
+
const operations = await getOperationsByType(pathToSpec, options.httpMethodsToMessages, document2);
|
|
4385
4413
|
const sidebarBadgeType = options.sidebarBadgeType || "HTTP_METHOD";
|
|
4386
4414
|
const version = options.serviceVersion || document2.info.version;
|
|
4387
4415
|
const preserveExistingMessages = options.preserveExistingMessages ?? true;
|
|
@@ -4507,7 +4535,11 @@ var getParsedSpecFile = (service, document2) => {
|
|
|
4507
4535
|
var getRawSpecFile = async (service) => {
|
|
4508
4536
|
const specPath = service.path;
|
|
4509
4537
|
if (specPath.startsWith("http")) {
|
|
4510
|
-
const
|
|
4538
|
+
const fetchOptions = { method: "GET" };
|
|
4539
|
+
if (service.headers && Object.keys(service.headers).length > 0) {
|
|
4540
|
+
fetchOptions.headers = service.headers;
|
|
4541
|
+
}
|
|
4542
|
+
const file = await fetch(specPath, fetchOptions);
|
|
4511
4543
|
if (!file.ok) {
|
|
4512
4544
|
throw new Error(`Failed to fetch file: ${specPath}, status: ${file.status}`);
|
|
4513
4545
|
}
|