Resolved schema caching not working when $id is set to retrieval URI
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- tooling
Research direction
Start in src/services/jsonSchemaService.ts, at resolveSchemaContent and registerEmbeddedSchemas, then add the supplied regression test for a schema whose $id matches its retrieval URI. Run the JSON schema service tests and confirm the schema resolves once while the second getResolvedSchema call uses the cached result.
Written by the indexing model from the issue text.
Description
In JSONSchemaService.resolveSchemaContent, there is a function called registerEmbeddedSchemas, which is supposed to find any sub-schemas with an $id property, and register them to the service. However, when traversing the schema, it also visits the root. If $id is set there to the same URI as the one that is currently being resolved, it will be overridden with setSchemaContent, which also clears its resolvedSchema promise.
This means there is effectively no caching for schemas that set their $id to their retrieval URI, which is probably most of them.
Here's a test case to reproduce:
test('Schema with $id matching its own URI should not cause double resolution', async function () {
const schemaUri = 'https://exmaple.com/schema';
const schema: JSONSchema = {
$schema: 'https://json-schema.org/draft/2019-09/schema',
$id: schemaUri,
type: 'object'
};
const service = new SchemaService.JSONSchemaService(newMockRequestService(), workspaceContext);
service.setSchemaContributions({ schemas: { [schemaUri]: schema } });
let resolveSchemaContentCount = 0;
// Intercept resolveSchemaContent to count resolution calls
const originalResolveSchemaContent = (service as any).resolveSchemaContent.bind(service);
(service as any).resolveSchemaContent = function (
schemaToResolve: SchemaService.UnresolvedSchema,
handle: SchemaService.ISchemaHandle
) {
resolveSchemaContentCount++;
return originalResolveSchemaContent(schemaToResolve, handle);
};
// First call - resolves the schema
const result1 = await service.getResolvedSchema(schemaUri);
assert.ok(result1, 'First resolution should succeed');
assert.strictEqual(result1?.schema.type, 'object');
// Second call - should return cached result
const result2 = await service.getResolvedSchema(schemaUri);
assert.ok(result2, 'Second call should return cached result');
assert.strictEqual(result2?.schema.type, 'object');
assert.strictEqual(
resolveSchemaContentCount,
1,
`Expected single resolution, but got ${resolveSchemaContentCount}. Schema with $id matching its URI should not invalidate its own resolution cache.`
);
});
- Dominant language
- TypeScript
- Stars
- 326
- Forks
- 145
- Avg merge
- 22h 10m
- Merged PRs (30d)
- 9
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/vscode-json-languageservice
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
microsoft/vscode-json-languageservice#354 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
microsoft/vscode-json-languageservice#350 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
All issues in microsoft/vscode-json-languageservice
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·