Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ jobs:
- name: Install deps
run: pnpm i

- name: Create .npmrc for GitHub Packages
run: |
cat <<EOF > ~/.npmrc
@nhsdigital:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
always-auth=true
registry=https://registry.npmjs.org/
EOF
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release Pull Request or Publish to npm
uses: changesets/action@master
with:
Expand Down
4 changes: 0 additions & 4 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
strict-peer-dependencies=false

@nhsdigital:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
always-auth=true
104 changes: 4 additions & 100 deletions eventcatalog/src/components/SchemaExplorer/JSONSchemaViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useEffect, useRef, useMemo } from 'react';
import $RefParser from '@apidevtools/json-schema-ref-parser';

interface JSONSchemaViewerProps {
schema: any;
Expand Down Expand Up @@ -100,107 +101,10 @@ function mergeAllOfSchemas(schemaWithProcessor: any): any {
return mergedSchema;
}

function processSchema(schema: any, rootSchema?: any): any {
async function processSchema(schema: any, rootSchema?: any): Promise<any> {
if (!schema) return schema;

const root = rootSchema || schema;

// Handle $ref
if (schema.$ref) {
const refPath = schema.$ref;
let resolvedSchema = null;
let defName = '';

// Try draft-7 style first: #/definitions/
if (refPath.startsWith('#/definitions/')) {
defName = refPath.replace('#/definitions/', '');
if (root.definitions && root.definitions[defName]) {
resolvedSchema = root.definitions[defName];
}
}
// Try 2020-12 style: #/$defs/
else if (refPath.startsWith('#/$defs/')) {
defName = refPath.replace('#/$defs/', '');
if (root.$defs && root.$defs[defName]) {
resolvedSchema = root.$defs[defName];
}
}
// Try other common patterns
else if (refPath.startsWith('#/components/schemas/')) {
defName = refPath.replace('#/components/schemas/', '');
if (root.components && root.components.schemas && root.components.schemas[defName]) {
resolvedSchema = root.components.schemas[defName];
}
}

if (resolvedSchema) {
const processedSchema = processSchema(resolvedSchema, root);
return {
...processedSchema,
_refPath: refPath,
_refName: defName,
_originalRef: schema.$ref,
};
}

return {
type: 'string',
description: `Reference to ${refPath} (definition not found in root schema)`,
title: defName || refPath.split('/').pop(),
_refPath: refPath,
_refName: defName,
_refNotFound: true,
};
}

if (schema.allOf) {
return mergeAllOfSchemas({ ...schema, processSchema: (s: any) => processSchema(s, root) });
}

if (schema.oneOf) {
const processedVariants = schema.oneOf.map((variant: any) => {
const processedVariant = processSchema(variant, root);
return {
title: processedVariant.title || variant.title || 'Unnamed Variant',
required: processedVariant.required || variant.required || [],
properties: processedVariant.properties || {},
...processedVariant,
};
});

const allProperties: Record<string, any> = {};
processedVariants.forEach((variant: any) => {
if (variant.properties) {
Object.assign(allProperties, variant.properties);
}
});

return {
...schema,
type: schema.type || 'object',
properties: {
...(schema.properties || {}),
...allProperties,
},
variants: processedVariants,
};
}

// Process nested schemas in properties
if (schema.properties) {
const processedProperties: Record<string, any> = {};
Object.entries(schema.properties).forEach(([key, prop]: [string, any]) => {
processedProperties[key] = processSchema(prop, root);
});
schema = { ...schema, properties: processedProperties };
}

// Process array items
if (schema.type === 'array' && schema.items) {
schema = { ...schema, items: processSchema(schema.items, root) };
}

return schema;
let dereferencedSchema = await $RefParser.dereference(schema);
return dereferencedSchema;
}

// SchemaProperty component
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@ai-sdk/google": "^2.0.17",
"@ai-sdk/openai": "^2.0.42",
"@ai-sdk/react": "^2.0.60",
"@apidevtools/json-schema-ref-parser": "^15.1.3",
"@astrojs/markdown-remark": "^6.3.9",
"@astrojs/mdx": "^4.3.12",
"@astrojs/node": "^9.5.1",
Expand Down
16 changes: 15 additions & 1 deletion pnpm-lock.yaml

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