@eventcatalog/generator-openapi 7.8.0 → 7.9.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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +67 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -3
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.mts +13 -7
- package/dist/types.d.ts +13 -7
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1627,6 +1627,53 @@ async function getSchemasByOperationId(filePath, operationId, parsedDocument) {
|
|
|
1627
1627
|
return;
|
|
1628
1628
|
}
|
|
1629
1629
|
}
|
|
1630
|
+
async function getExamplesByOperationId(filePath, operationId, parsedDocument) {
|
|
1631
|
+
const api = parsedDocument || await SwaggerParser.dereference(filePath);
|
|
1632
|
+
const examples = [];
|
|
1633
|
+
for (const [, pathItem] of Object.entries(api.paths)) {
|
|
1634
|
+
for (const [, operation] of Object.entries(pathItem)) {
|
|
1635
|
+
const typedOperation = operation;
|
|
1636
|
+
if (typedOperation.operationId !== operationId) continue;
|
|
1637
|
+
if (typedOperation.requestBody?.content) {
|
|
1638
|
+
const contentType = Object.keys(typedOperation.requestBody.content)[0];
|
|
1639
|
+
const mediaType = typedOperation.requestBody.content[contentType];
|
|
1640
|
+
if (mediaType.example) {
|
|
1641
|
+
examples.push({ fileName: "example.json", content: JSON.stringify(mediaType.example, null, 2) });
|
|
1642
|
+
}
|
|
1643
|
+
if (mediaType.examples) {
|
|
1644
|
+
for (const [name, exampleObj] of Object.entries(mediaType.examples)) {
|
|
1645
|
+
if (exampleObj.value) {
|
|
1646
|
+
examples.push({ fileName: `${name}.json`, content: JSON.stringify(exampleObj.value, null, 2) });
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
if (typedOperation.responses) {
|
|
1652
|
+
for (const [statusCode, response] of Object.entries(typedOperation.responses)) {
|
|
1653
|
+
if (response.content) {
|
|
1654
|
+
const contentType = Object.keys(response.content)[0];
|
|
1655
|
+
const mediaType = response.content[contentType];
|
|
1656
|
+
if (mediaType.example) {
|
|
1657
|
+
examples.push({ fileName: `response-${statusCode}.json`, content: JSON.stringify(mediaType.example, null, 2) });
|
|
1658
|
+
}
|
|
1659
|
+
if (mediaType.examples) {
|
|
1660
|
+
for (const [name, exampleObj] of Object.entries(mediaType.examples)) {
|
|
1661
|
+
if (exampleObj.value) {
|
|
1662
|
+
examples.push({
|
|
1663
|
+
fileName: `response-${statusCode}-${name}.json`,
|
|
1664
|
+
content: JSON.stringify(exampleObj.value, null, 2)
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
return examples;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
return examples;
|
|
1676
|
+
}
|
|
1630
1677
|
function getDeprecatedValues(openAPIOperation) {
|
|
1631
1678
|
const deprecatedDate = openAPIOperation["x-eventcatalog-deprecated-date"] || null;
|
|
1632
1679
|
const deprecatedMessage = openAPIOperation["x-eventcatalog-deprecated-message"] || null;
|
|
@@ -1884,7 +1931,10 @@ var getMessageTypeUtils = (projectDirectory, messageType) => {
|
|
|
1884
1931
|
getQuery,
|
|
1885
1932
|
rmQueryById,
|
|
1886
1933
|
writeQuery,
|
|
1887
|
-
addFileToQuery
|
|
1934
|
+
addFileToQuery,
|
|
1935
|
+
addExampleToEvent,
|
|
1936
|
+
addExampleToCommand,
|
|
1937
|
+
addExampleToQuery
|
|
1888
1938
|
} = utils(projectDirectory);
|
|
1889
1939
|
const messageTypeMap = {
|
|
1890
1940
|
event: {
|
|
@@ -1893,6 +1943,7 @@ var getMessageTypeUtils = (projectDirectory, messageType) => {
|
|
|
1893
1943
|
rmMessageById: rmEventById,
|
|
1894
1944
|
writeMessage: writeEvent,
|
|
1895
1945
|
addFileToMessage: addFileToEvent,
|
|
1946
|
+
addExampleToMessage: addExampleToEvent,
|
|
1896
1947
|
collection: "events"
|
|
1897
1948
|
},
|
|
1898
1949
|
command: {
|
|
@@ -1901,6 +1952,7 @@ var getMessageTypeUtils = (projectDirectory, messageType) => {
|
|
|
1901
1952
|
rmMessageById: rmCommandById,
|
|
1902
1953
|
writeMessage: writeCommand,
|
|
1903
1954
|
addFileToMessage: addFileToCommand,
|
|
1955
|
+
addExampleToMessage: addExampleToCommand,
|
|
1904
1956
|
collection: "commands"
|
|
1905
1957
|
},
|
|
1906
1958
|
query: {
|
|
@@ -1909,6 +1961,7 @@ var getMessageTypeUtils = (projectDirectory, messageType) => {
|
|
|
1909
1961
|
rmMessageById: rmQueryById,
|
|
1910
1962
|
writeMessage: writeQuery,
|
|
1911
1963
|
addFileToMessage: addFileToQuery,
|
|
1964
|
+
addExampleToMessage: addExampleToQuery,
|
|
1912
1965
|
collection: "queries"
|
|
1913
1966
|
}
|
|
1914
1967
|
};
|
|
@@ -4147,7 +4200,7 @@ import { join } from "path";
|
|
|
4147
4200
|
// package.json
|
|
4148
4201
|
var package_default = {
|
|
4149
4202
|
name: "@eventcatalog/generator-openapi",
|
|
4150
|
-
version: "7.
|
|
4203
|
+
version: "7.9.0",
|
|
4151
4204
|
description: "OpenAPI generator for EventCatalog",
|
|
4152
4205
|
scripts: {
|
|
4153
4206
|
build: "tsup",
|
|
@@ -4184,7 +4237,7 @@ var package_default = {
|
|
|
4184
4237
|
dependencies: {
|
|
4185
4238
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
4186
4239
|
"@changesets/cli": "^2.27.7",
|
|
4187
|
-
"@eventcatalog/sdk": "2.
|
|
4240
|
+
"@eventcatalog/sdk": "2.17.4",
|
|
4188
4241
|
chalk: "4.1.2",
|
|
4189
4242
|
"js-yaml": "^4.1.0",
|
|
4190
4243
|
"openapi-types": "^12.1.3",
|
|
@@ -4581,6 +4634,7 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document2, servicePath, o
|
|
|
4581
4634
|
const sidebarBadgeType = options.sidebarBadgeType || "HTTP_METHOD";
|
|
4582
4635
|
const version = options.serviceVersion || document2.info.version;
|
|
4583
4636
|
const preserveExistingMessages = options.preserveExistingMessages ?? true;
|
|
4637
|
+
const parseExamples = options.parseExamples ?? true;
|
|
4584
4638
|
const isDraft = options.isDraft ?? null;
|
|
4585
4639
|
let receives = [], sends = [];
|
|
4586
4640
|
for (const operation of operations) {
|
|
@@ -4601,6 +4655,7 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document2, servicePath, o
|
|
|
4601
4655
|
console.log(chalk4.blue(`Processing message: ${message2.name} (v${message2.version})`));
|
|
4602
4656
|
const {
|
|
4603
4657
|
addFileToMessage,
|
|
4658
|
+
addExampleToMessage,
|
|
4604
4659
|
writeMessage,
|
|
4605
4660
|
getMessage,
|
|
4606
4661
|
versionMessage,
|
|
@@ -4687,6 +4742,15 @@ var processMessagesForOpenAPISpec = async (pathToSpec, document2, servicePath, o
|
|
|
4687
4742
|
);
|
|
4688
4743
|
}
|
|
4689
4744
|
}
|
|
4745
|
+
if (parseExamples && operation.operationId) {
|
|
4746
|
+
const operationExamples = await getExamplesByOperationId(pathToSpec, operation.operationId, document2);
|
|
4747
|
+
for (const example of operationExamples) {
|
|
4748
|
+
await addExampleToMessage(message2.id, { content: example.content, fileName: example.fileName }, message2.version);
|
|
4749
|
+
}
|
|
4750
|
+
if (operationExamples.length > 0) {
|
|
4751
|
+
console.log(chalk4.cyan(` - ${operationExamples.length} example(s) added to message (v${message2.version})`));
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
4690
4754
|
console.log(chalk4.cyan(` - Message (v${message2.version}) created`));
|
|
4691
4755
|
if (!operation.operationId) {
|
|
4692
4756
|
console.log(chalk4.yellow(` - OperationId not found for ${operation.method} ${operation.path}, creating one...`));
|