Skip to content

Commit 8d7fa57

Browse files
authored
expand property schema when inserting text (#49)
Expand property schema when inserting text. This fixes cases like `dependencies` field in the package.json schema which just contains a reference to a schema definition. <img width="336" alt="Screenshot 2023-07-29 at 5 51 32 PM" src="https://github.com/acao/codemirror-json-schema/assets/4608143/f10d8d6f-111e-45ee-9ed9-544870ea5b89">
1 parent 5fcf5ad commit 8d7fa57

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.changeset/purple-bags-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"codemirror-json-schema": patch
3+
---
4+
5+
expand property schema when inserting text

src/json-completion.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ export class JSONCompletion {
258258
addValue: boolean,
259259
propertySchema?: JSONSchema7Definition
260260
) {
261+
// expand schema property if it is a reference
262+
propertySchema = propertySchema
263+
? this.expandSchemaProperty(propertySchema, this.schema)
264+
: propertySchema;
265+
261266
let resultText = `"${key}"`;
262267
if (!addValue) {
263268
return resultText;
@@ -334,6 +339,14 @@ export class JSONCompletion {
334339
}
335340
}
336341
if (!value || nValueProposals > 1) {
342+
debug.log(
343+
"xxx",
344+
"value",
345+
value,
346+
"nValueProposals",
347+
nValueProposals,
348+
propertySchema
349+
);
337350
value = "#{}";
338351
}
339352

0 commit comments

Comments
 (0)