Skip to content

Commit

Permalink
feat(plugin): breaking change - persist spec files between services a…
Browse files Browse the repository at this point in the history
…nd id is now required and foldername removed
  • Loading branch information
David Boyne authored and David Boyne committed Sep 27, 2024
1 parent 5756b37 commit d702c9d
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 56 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ generators: [
'@eventcatalogtest/generator-openapi',
{
services: [
{ path: [path.join(__dirname, 'openapi-files', 'petstore.yml') },
{ path: [path.join(__dirname, 'openapi-files', 'account-service.yml'), id: 'account-service', folderName: 'Account Service' },
{ path: [path.join(__dirname, 'openapi-files', 'petstore.yml'), id: 'pet-store' },
{ path: [path.join(__dirname, 'openapi-files', 'account-service.yml'), id: 'account-service' },
],
domain: { id: 'orders', name: 'Orders', version: '0.0.1' },
},
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
"dependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@changesets/cli": "^2.27.7",
"@eventcatalog/sdk": "^0.1.1",
"@eventcatalog/sdk": "^0.1.3",
"chalk": "^4",
"openapi-types": "^12.1.3",
"slugify": "^1.6.6"
}
},
"packageManager": "[email protected]+sha512.90e27fd38047f18583f3342f784cc3f187f4d4caac89ebc1fffae18dcd7b2dde7678a0bf237481bcb8f7e8e66135fa34803856e4eb2c442ce082ffab5d9d241f"
}
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 23 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export default async (_: any, options: Props) => {
addServiceToDomain,
getService,
versionService,
rmService,
rmServiceById,
writeService,
addFileToService,
getSpecificationFilesForService,
} = utils(process.env.PROJECT_DIR);

const services = options.services ?? [];
Expand All @@ -53,6 +54,7 @@ export default async (_: any, options: Props) => {

const service = buildService(serviceSpec, document);
let serviceMarkdown = service.markdown;
let serviceSpecificationsFiles = [];
let serviceSpecifications = service.specifications;

// Manage domain
Expand Down Expand Up @@ -98,6 +100,7 @@ export default async (_: any, options: Props) => {

if (latestServiceInCatalog) {
serviceMarkdown = latestServiceInCatalog.markdown;
serviceSpecificationsFiles = await getSpecificationFilesForService(service.id, 'latest');
sends = latestServiceInCatalog.sends || ([] as any);

// persist any specifications that are already in the catalog
Expand All @@ -114,7 +117,7 @@ export default async (_: any, options: Props) => {

// Match found, override it
if (latestServiceInCatalog.version === version) {
await rmService(service.name);
await rmServiceById(service.id);
}
}

Expand All @@ -126,17 +129,29 @@ export default async (_: any, options: Props) => {
sends,
receives,
},
{ path: serviceSpec.folderName || service.name }
{ path: service.id }
);

await addFileToService(
service.id,
// What files need added to the service (speficiation files)
const specFiles = [
// add any previous spec files to the list
...serviceSpecificationsFiles,
{
fileName: service.schemaPath,
content: openAPIFile,
fileName: service.schemaPath,
},
version
);
];

for (const specFile of specFiles) {
await addFileToService(
service.id,
{
fileName: specFile.fileName,
content: specFile.content,
},
version
);
}

console.log(chalk.cyan(` - Service (v${version}) created`));
}
Expand Down
Loading

0 comments on commit d702c9d

Please sign in to comment.