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
44 changes: 44 additions & 0 deletions shell/src/app/shared/monaco-editor/monaco-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,50 @@ describe('MonacoEditor component', () => {
);
});

it('registers the active catalog schema from A2UI_CATALOG for catalog.json references', async () => {
fixture = TestBed.createComponent(MonacoEditor);
const catalogService = TestBed.inject(CatalogManagement);
const activeCatalogSchema: Catalog = {
catalogId: 'https://a2ui.org/specification/v0_9/material_catalog.json',
components: {
MaterialButton: {type: 'object'},
},
functions: {
formatString: {type: 'object', properties: {call: {const: 'formatString'}}},
updateDataModel: {type: 'object', properties: {call: {const: 'updateDataModel'}}},
callMcpTool: {type: 'object', properties: {call: {const: 'callMcpTool'}}},
},
$defs: {
anyFunction: {
anyOf: [
{$ref: '#/functions/formatString'},
{$ref: '#/functions/updateDataModel'},
{$ref: '#/functions/callMcpTool'},
],
},
},
};
(catalogService.activeCatalog as WritableSignal<Catalog | null>).set(activeCatalogSchema);
fixture.detectChanges();

await TestbedHarnessEnvironment.harnessForFixture(fixture, MonacoEditorHarness);
await Promise.resolve();
fixture.detectChanges();

const lastCall = mockSetDiagnosticsOptions.mock.calls.at(-1)?.[0] as {
schemas: Array<{uri: string; schema: Record<string, unknown>}>;
};
const catalogSchemas = lastCall.schemas.filter(
s =>
s.uri === 'file:///catalog.json' ||
s.uri === 'https://a2ui.org/specification/v0_9/catalog.json',
);
expect(catalogSchemas).toHaveLength(2);
for (const entry of catalogSchemas) {
expect(entry.schema).toEqual(activeCatalogSchema);
}
});

it('returns line and column from getFirstErrorMarker when diagnostics are present', async () => {
fixture = TestBed.createComponent(MonacoEditor);
fixture.detectChanges();
Expand Down
21 changes: 10 additions & 11 deletions shell/src/app/shared/monaco-editor/monaco-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
ThemePreference,
} from '../../settings/app-config-provider/app-config-provider';
import {COMMON_TYPES_SCHEMA} from '../../gallery/schema/common-types-schema';
import {BASIC_CATALOG_SCHEMA} from '../../gallery/schema/basic-catalog-schema';
import {Catalog} from '../../storage/models/catalog-storage.model';

/**
* A standalone Angular component that wraps the Monaco Editor.
Expand Down Expand Up @@ -493,7 +493,7 @@ export class MonacoEditor {
jsonContrib.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemaValidation: 'error',
schemas: this.buildValidationSchemas(layoutSchema, galleryExampleSchema),
schemas: this.buildValidationSchemas(layoutSchema, galleryExampleSchema, catalog),
});
});

Expand Down Expand Up @@ -733,14 +733,17 @@ export class MonacoEditor {
* @param layoutSchema The dynamically generated schema representing the full A2UI layout
* structure, including the active catalog's components.
* @param galleryExampleSchema The schema for Gallery example drafts (`{components, data}`).
* @param catalog The active catalog JSON schema received from the renderer (`A2UI_CATALOG`).
* @return An array of schemas configured with URIs that match `$ref` references
* within the component schemas. We map local constants (like COMMON_TYPES_SCHEMA)
* to both `file:///` and HTTP URIs so the Monaco JSON worker can resolve them
* synchronously without needing an external schema request service.
* within the component and function schemas. We map the active catalog and
* `COMMON_TYPES_SCHEMA` to both `file:///` and HTTP URIs so the Monaco JSON
* worker can resolve them synchronously without needing an external schema
* request service.
*/
private buildValidationSchemas(
layoutSchema: unknown,
galleryExampleSchema: unknown,
catalog: Catalog,
): monaco.json.DiagnosticsOptions['schemas'] {
return [
{
Expand All @@ -759,19 +762,15 @@ export class MonacoEditor {
},
{
uri: 'file:///catalog.json',
schema: structuredClone(BASIC_CATALOG_SCHEMA),
schema: structuredClone(catalog),
},
{
uri: 'https://a2ui.org/specification/v0_9/common_types.json',
schema: structuredClone(COMMON_TYPES_SCHEMA),
},
{
uri: 'https://a2ui.org/specification/v0_9/catalog.json',
schema: structuredClone(BASIC_CATALOG_SCHEMA),
},
{
uri: 'https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json',
schema: structuredClone(BASIC_CATALOG_SCHEMA),
schema: structuredClone(catalog),
},
];
}
Expand Down
Loading