Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array object completion - should not suggest const #620

Closed
p-spacek opened this issue Dec 14, 2021 · 0 comments
Closed

array object completion - should not suggest const #620

p-spacek opened this issue Dec 14, 2021 · 0 comments
Assignees
Labels
Milestone

Comments

@p-spacek
Copy link
Contributor

Describe the bug

array object completion - should not suggest const

schema:

{
  "properties": {
    "test": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "constProp": {
            "type": "string",
            "const": "const1"
          }
       }
    }
  "type": "object",
}

yaml:

test:
  - constProp
    # cursor here

image

this test fails

    it('array completion - should not suggest const', async () => {
      languageService.addSchema(SCHEMA_ID, {
        type: 'object',
        properties: {
          test: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                constProp: {
                  type: 'string',
                  const: 'const1',
                },
              },
            },
          },
        },
      });
      const content = 'test:\n  - constProp:\n    ';
      const result = await parseSetup(content, content.length);
      expect(result.items.length).to.be.equal(0);
    });

problem is probably here in yamlCompletion.ts
check for array is missing

// it will treated as a property key since `:` has been appended
if (nodeParent && isSeq(nodeParent) && schema.schema.type !== 'object') {
  this.addSchemaValueCompletions(schema.schema, separatorAfter, collector, {});
}

Expected Behavior

should not suggest const value inside the array
But if it's not an array, just an object, completion works ok.
image

Current Behavior

Steps to Reproduce

Environment

Mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants