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

fix: default value with special chars with anyOf #963

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

p-spacek
Copy link
Contributor

@p-spacek p-spacek commented May 2, 2024

What does this PR do?

  1. fixes a small specific issue when schema contains default value with special chars next to anyOf.

This schema

       {
          type: 'object',
          properties: {
            car: {
              type: 'object',
              required: ['engine'],
              properties: {
                engine: {
                  anyOf: [
                    {
                      type: 'object',
                    },
                    {
                      type: 'string',
                    },
                  ],
                  default: 'type$1234',
                },
              },
            },
          },

doesn't escape default value

note that an object with anyOf (engine) needs to be inside another object (car), then getInserTextForObject is called with schema { car: {engine: anyOf}}

  1. fixes condition to allow null, 0, emptyString, false as a default or const
  • the same logic is correctly used in other places

What issues does this PR fix or reference?

no ref

Is it tested? How?

unit-test

@coveralls
Copy link

coveralls commented May 2, 2024

Coverage Status

coverage: 84.305% (+0.1%) from 84.174%
when pulling 26ec17a on jigx-com:fix/default-value-with-special-chars-with-anyOf
into 7203630 on redhat-developer:main.

p-spacek added a commit to jigx-com/rh-yaml-language-server that referenced this pull request May 2, 2024
let value = propertySchema.default || propertySchema.const;
if (value) {
if (type === 'string') {
let value = propertySchema.default === undefined ? propertySchema.const : propertySchema.default;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixes condition to allow null,0,emptyString as a default or const
the same logic is correctly used in other places

@@ -1242,10 +1242,6 @@ export class YamlCompletion {
return this.getInsertTextForValue(value, separatorAfter, type);
}

private getInsertTextForPlainText(text: string): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved outside of the class to be able to use it from global functions

p-spacek added a commit to jigx-com/rh-yaml-language-server that referenced this pull request May 2, 2024
@msivasubramaniaan
Copy link
Contributor

@p-spacek please rebase the repo

@p-spacek p-spacek force-pushed the fix/default-value-with-special-chars-with-anyOf branch from 8672460 to 2675e84 Compare May 29, 2024 07:56
@p-spacek p-spacek force-pushed the fix/default-value-with-special-chars-with-anyOf branch from 2675e84 to 26ec17a Compare May 29, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants