Skip to content

Commit

Permalink
feat(core): schema viewer now renders yaml files (#998)
Browse files Browse the repository at this point in the history
* feat(core): schema viewer now renders yaml files

* Create yellow-planes-hope.md
  • Loading branch information
boyney123 authored Dec 5, 2024
1 parent e87bb9b commit 38e6165
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-planes-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": patch
---

feat(core): schema viewer now renders yaml files
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const { catalog, id } = Astro.props;
import fs from 'node:fs/promises';
import { existsSync } from 'fs';
import yaml from 'js-yaml';
import path from 'path';
import SchemaViewerClient from './SchemaViewer';
import Admonition from '../Admonition';
Expand Down Expand Up @@ -48,7 +49,11 @@ try {
if (exists) {
// Load the schema for the component
schema = await fs.readFile(schemaPath, 'utf-8');
schema = JSON.parse(schema);
if (schemaPath.endsWith('.yml') || schemaPath.endsWith('.yaml')) {
schema = yaml.load(schema);
} else {
schema = JSON.parse(schema);
}
}
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The `Inventory Adjusted` event is triggered whenever there is a change in the in

<NodeGraph />

<SchemaViewer file="schema.json" title="JSON Schema" maxHeight="500" />
<SchemaViewer file="schema.yml" title="JSON Schema" maxHeight="500" />

## Payload example

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
$schema: http://json-schema.org/draft-07/schema#
title: Employee
type: object
description: A record representing an employee
properties:
Name:
type: string
description: The name of the employee
Age:
type: integer
description: The age of the employee
Department:
type: string
description: The department where the employee works
Position:
type: string
description: The position or title of the employee within the department
Salary:
type: number
format: double
description: The salary of the employee
JoinDate:
type: string
format: date
description: The date when the employee joined the company
required:
- Name
- Age
- Department
- Position
- Salary
- JoinDate
12 changes: 10 additions & 2 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"glob": "^10.4.1",
"gray-matter": "^4.0.3",
"html-to-image": "^1.11.11",
"js-yaml": "^4.1.0",
"lodash.debounce": "^4.0.8",
"lodash.merge": "4.6.2",
"lucide-react": "^0.453.0",
Expand All @@ -91,6 +92,7 @@
"@playwright/test": "^1.48.1",
"@types/dagre": "^0.7.52",
"@types/diff": "^5.2.2",
"@types/js-yaml": "^4.0.9",
"@types/lodash.debounce": "^4.0.9",
"@types/lodash.merge": "4.6.9",
"@types/node": "^20.14.2",
Expand Down

0 comments on commit 38e6165

Please sign in to comment.