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
36 changes: 36 additions & 0 deletions src/__tests__/__fixtures__/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,43 @@ export const testSchema2 = {
oneOfEg2: {
oneOf: [{ type: "string" }, { type: "array" }],
},
oneOfObject: {
oneOf: [
{ $ref: "#/definitions/fancyObject" },
{ $ref: "#/definitions/fancyObject2" },
],
},
enum1: {
description: "an example enum with default bar",
enum: ["foo", "bar"],
default: "bar",
},
enum2: {
description: "an example enum without default",
enum: ["foo", "bar"],
},
booleanWithDefault: {
description: "an example boolean with default",
default: true,
type: "boolean",
},
},
required: ["foo", "object.foo"],
additionalProperties: false,
definitions: {
fancyObject: {
type: "object",
properties: {
foo: { type: "string" },
bar: { type: "number" },
},
},
fancyObject2: {
type: "object",
properties: {
apple: { type: "string" },
banana: { type: "number" },
},
},
},
} as JSONSchema7;
131 changes: 131 additions & 0 deletions src/__tests__/json-completion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,137 @@ describe("jsonCompletion", () => {
info: "",
template: '"oneOfEg2": ',
},
{
detail: "",
info: "",
label: "oneOfObject",
template: '"oneOfObject": ',
type: "property",
},
]);
});
it("should include defaults for enum when available", async () => {
await expectCompletion('{ "en| }', [
{
label: "enum1",
type: "property",
detail: "",
info: "an example enum with default bar",
// TODO: should this not autocomplete to default "bar"?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what I was referring to with completion of default enum value, this is why i added the if/else block in #48

// template: '"enum1": "${bar}"',
template: '"enum1": #{}',
},
{
label: "enum2",
type: "property",
detail: "",
info: "an example enum without default",
template: '"enum2": #{}',
},
]);
});
it("should include value completions for enum", async () => {
await expectCompletion('{ "enum1": "|" }', [
{
label: '"foo"',
info: "an example enum with default bar",
},
{
label: '"bar"',
detail: "Default value",
},
]);
});
it("should include defaults for boolean when available", async () => {
await expectCompletion('{ "booleanW| }', [
{
type: "property",
detail: "boolean",
info: "an example boolean with default",
label: "booleanWithDefault",
template: '"booleanWithDefault": ${true}',
},
]);
});
// TODO: should provide true/false completions
it("should include value completions for boolean", async () => {
await expectCompletion('{ "booleanWithDefault": | }', []);
});
it("should include insert text for objects", async () => {
await expectCompletion('{ "ob| }', [
{
type: "property",
detail: "object",
info: "",
label: "object",
template: '"object": {#{}}',
},
]);
});
// this has regressed for json4 only for some reason
it("should include insert text for nested object properties", async () => {
await expectCompletion('{ "object": { "|" } }', [
{
detail: "string",
info: "an elegant string",
label: "foo",
template: '"foo": "#{}"',
type: "property",
},
]);
});
it("should include insert text for nested object properties with filter", async () => {
await expectCompletion('{ "object": { "f|" } }', [
{
detail: "string",
info: "an elegant string",
label: "foo",
template: '"foo": "#{}"',
type: "property",
},
]);
});
it("should autocomplete for oneOf with nested definitions and filter", async () => {
await expectCompletion('{ "oneOfObject": { "f|" } }', [
{
detail: "string",
info: "",
label: "foo",
template: '"foo": "#{}"',
type: "property",
},
]);
});
it("should autocomplete for oneOf with nested definitions", async () => {
await expectCompletion('{ "oneOfObject": { "|" } }', [
{
detail: "string",
info: "",
label: "foo",
template: '"foo": "#{}"',
type: "property",
},
{
detail: "number",
info: "",
label: "bar",
template: '"bar": #{0}',
type: "property",
},
{
detail: "string",
info: "",
label: "apple",
template: '"apple": "#{}"',
type: "property",
},
{
detail: "number",
info: "",
label: "banana",
template: '"banana": #{0}',
type: "property",
},
]);
});
});