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

schema inputs should prefer specific types instead of general strings #524

Open
jtmoon79 opened this issue Apr 21, 2023 · 4 comments
Open
Labels
Area: VsCodeExtension enhancement Small enhancement to existing functionality

Comments

@jtmoon79
Copy link

jtmoon79 commented Apr 21, 2023

Problem

This Azure Pipeline YAML code, validated against service-schema.json 97f39ff, runs just fine in Azure Devops (greatly simplified for sake of clarity):

# yaml-language-server: $schema=https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/97f39ff988232860b35556dde725d448151ec5a0/service-schema.json
trigger:
  batch: true
pr: none
stages:
- stage: stage1
  jobs:
  - job: job1
    timeoutInMinutes: 20
    condition: false
    steps:
    - script: echo "hello"

So it runs okay, yet the 20 and true and false are red underlined with hover errors

Incorrect type. Expected "string". yaml-schema: Pipeline schema

The fix is to make the inputs into strings:

# yaml-language-server: $schema=https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/97f39ff988232860b35556dde725d448151ec5a0/service-schema.json
trigger:
  batch: "true"
pr: none
stages:
- stage: stage1
  jobs:
  - job: job1
    timeoutInMinutes: "20"
    condition: "false"
    steps:
    - script: echo "hello"

However, now the following non-sense YAML values is also considered valid (no hover errors):

# yaml-language-server: $schema=https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/97f39ff988232860b35556dde725d448151ec5a0/service-schema.json
trigger:
  batch: "FOO"
pr: none
stages:
- stage: stage1
  jobs:
  - job: job1
    timeoutInMinutes: "BAR"
    condition: "!?!?!?!?!?!"
    steps:
    - script: echo "hello"

Solution

It's nice to use raw numbers, booleans, etc. for inputs where such types are expected. Then the user is given more accurate feedback about expected values for various inputs.

Also, in VS Code, they are visually different than plain strings, which is nice.

@jtmoon79 jtmoon79 changed the title schema inputs should prefer to allow native type instead of strings schema inputs should prefer specific types instead of general strings Apr 21, 2023
@vmapetr
Copy link

vmapetr commented Apr 23, 2023

Hi, @jtmoon79 thanks for reporting!
We are working on more prioritized issues at the moment but will get back to this one soon.

@vmapetr vmapetr added enhancement Small enhancement to existing functionality and removed triage labels Apr 23, 2023
@50Wliu
Copy link
Member

50Wliu commented Apr 25, 2023

Huh, I can't reproduce this @jtmoon79.
numbers-work-fine

Does the issue still repro if you remove that yaml-language-server comment? It seems significant but I don't recall us keying on that anywhere, so I wonder if another extension you have installed is overriding our schema validation somehow.

@FrancescElies
Copy link

I saw the same when using yaml-language-server, in this case isn't yaml-language-server rightfully complaining?

In service-schema.json timeoutinminutes is defined as non empty string but what we wrote is a number which is also accepted but not explicitely stated in the schema.

            "timeoutInMinutes": {
              "description": "Time to wait for this job to complete before the server kills it",
              "$ref": "#/definitions/nonEmptyString"
            },

What am I missing?

@henryiii
Copy link

This came up on SchemaStore, as validators like VSCode and others don't recognize numbers as valid for timeoutInMinutes (which is how all the examples in this repo are done, I'd recommend using the examples as input and trying to validate them with the schema file provided). SchemaStore/schemastore#3560

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: VsCodeExtension enhancement Small enhancement to existing functionality
Projects
None yet
Development

No branches or pull requests

5 participants