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

Example string of type integer gets pasted as int #371

Closed
Morriz opened this issue Sep 30, 2020 · 10 comments · Fixed by redhat-developer/yaml-language-server#340
Closed
Assignees
Labels
Milestone

Comments

@Morriz
Copy link

Morriz commented Sep 30, 2020

When I use autocompletion I get a nice suggestion to use '1' (so obviously this entry in examples is a string), but after selecting it it ends up as 1, giving me an error as the validation spec expects a string.

Maybe this is a vscode problem, but I am reporting here first.

@evidolob
Copy link
Collaborator

evidolob commented Sep 30, 2020

@Morriz can you provide a sample of yaml and schema, where you get that behaviour?

@Morriz
Copy link
Author

Morriz commented Sep 30, 2020

I use draft 9 jsonschema, and the part that I use is:

...
    examples:
      - '1' # turns up as int after selecting in intellisense popup
      - 200m

@JPinkney
Copy link
Contributor

You can reproduce with this schema:

{
    "type": "object",
    "properties": {
        "env": {
            "type": "integer",
            "default": "1"
        },
        "enum": {
            "type": "string",
            "default": "1"
        }
    }
}

when you autocomplete env it will be correct but when you autocomplete enum it will add the integer 1 instead of the string 1
e.g.

enum: 1

when we want

enum: "1"

@JPinkney JPinkney added the bug label Sep 30, 2020
@evidolob evidolob self-assigned this Oct 1, 2020
@Morriz
Copy link
Author

Morriz commented Oct 1, 2020

@JPinkney that is another version of this bug but probably caused by the same underlying mechanism?

@Morriz
Copy link
Author

Morriz commented Oct 1, 2020

Sorry for giving a yaml example, but that is what we use as source and convert to json. (Would any dev really prefer json over yaml?)

@Morriz
Copy link
Author

Morriz commented Oct 1, 2020

On that note, is it possible to give a yaml file to this extension?

@JPinkney
Copy link
Contributor

JPinkney commented Oct 1, 2020

Yeah it's the same underlying mechanism. For example, I can also reproduce using:

properties:
  fooBar:
    type: string
    examples:
      - test
      - "2"
type: object

On that note, is it possible to give a yaml file to this extension?

Yeah it works with both json schemas and yaml schemas as of 0.11.0. This is how I was testing the above example:

"yaml.schemas": {
    "my-schema.yaml": "test.yaml"
},

@Morriz
Copy link
Author

Morriz commented Oct 1, 2020

Awesome!

@evidolob evidolob added this to the Sprint #191 milestone Oct 7, 2020
@evidolob
Copy link
Collaborator

@JPinkney I done some investigation on this, and found that YAML doesn't have number type, it has only scalar type,
i.e. for yaml point of view 1, '1', "1" is represents same value(string witch contains '1') in different flow scalar types
I can change code completion to surround numbers, booleans and null values with " in case if schema requires string but default value is other than string.
Or I can improve schema validation, by adding type conventions, i.e. if scheme requires number but we parse string, we will try to convert that string to number and do rest validations.

WDYT?

@JPinkney
Copy link
Contributor

I can change code completion to surround numbers, booleans and null values with " in case if schema requires string but the default value is other than string.

Yeah, that sounds good to me

bleach31 pushed a commit to bleach31/vscode-yaml that referenced this issue Jan 25, 2022
* redhat-developer#371 Support relative path in inline schema comment

Signed-off-by: Yevhen Vydolob <[email protected]>

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

Successfully merging a pull request may close this issue.

3 participants