Skip to content

Json schemas - #2415

Merged
AucaCoyan merged 4 commits into
devfrom
json-schemas
Aug 3, 2025
Merged

AucaCoyan merged 4 commits into
devfrom
json-schemas

Conversation

@AucaCoyan

@AucaCoyan AucaCoyan commented Aug 2, 2025 •

Copy link
Copy Markdown
Collaborator

fixes #2122
I have a couple of topics to talk:

First question

anchors: and anchor: are arbitrary names but worth including as such. anchors: need not be unique if you have any control over that.

Mmmm, the main top-level keys are:

  • $schema
  • imports
  • anchors
  • match
  • global_vars

I don't allow any other top level key. Is that alright? (I saw you ask in the body of the #2122 issue)

Segunda pregunta:

  - trigger: something
    replace: null # "Incorrect type. Expected "string".

causes this popup
image

Is that your intended action? 🤔

Finally

This schema should work for this collection of samples:

# yaml-language-server: $schema=https://raw.githubusercontent.com/espanso/espanso/refs/heads/json-schemas/schemas/match.schema.json

imports:
  - "python.yml"

anchors:
  - &script1 |
    fruits = "apple"

global_vars:
  - name: one
    type: shell
    params:
      cmd: "echo one"
  - name: two
    type: shell
    depends_on: ["one"]
    params:
      cmd: "echo two"

matches:
  - trigger: ":localip"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "ip a"
          trim: false

  - trigger: :test
    replace: "{{output}}"
    anchor: &script1 |
      fruits = "banana"

  - trigger: \ao3ip
    form: "Currently @ Chapter [[chapnum]] (In Progress)"
    form_fields:
      chapnum: # "Property chapnum is not allowed"
        default: "1"

  - trigger: something
    # comment out because it errors
    # replace: null # "Incorrect type. Expected "string".
    replace: something

  - trigger: ":localip"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          shell: pwsh

  - trigger: ":localip"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          shell: zsh

  - trigger: right_word
    replace: right_word
    right_word: true
    left_word: false

  - trigger: inject var name
    replace: hello {{output}}
    vars:
      - name: output
        inject_vars: false
        type: date

  - trigger: :meat
    replace: 🥩
    search_terms:
      - steak
      - t-bone

  - trigger: ":hello"
    comment: this is a sample from a comment key
    replace: "hello {{one}} {{two}}"

  - trigger: ":form"
    replace: "Hey {{form1.name}}, how are you? Do you like {{form1.fruit}}?"
    vars:
      - name: "form1"
        type: form
        params:
          layout: "Name: [[name]] \nFruit: [[frutas]], [[verduras]]"
          fields:
            name:
              multiline: true
            frutas:
              type: list # or `choice`
              values:
                - Apples
                - Bananas
                - Oranges
                - Peaches
            verduras:
              type: choice
              values: |
                eggplants # 🤮 I hate eggplants
                tomatoes
                lettuce

  - trigger: filename
    replace: "{{output}}"
    vars:
      - type: shell
        name: output
        params:
          cmd: |
            FILENAME="${ESPANSO_FILEPICKER_FILE%.*}"
            echo "$FILENAME"
          # debug key possible
          debug: true

  - trigger: asdfg
    replace: asdfb
    vars:
      - name: out
        type: random
        params:
          choices:
            - some text
            - different text

@AucaCoyan

Copy link
Copy Markdown
Collaborator Author

Note that to test this schema you need:

# yaml-language-server: $schema=https://raw.githubusercontent.com/espanso/espanso/refs/heads/json-schemas/schemas/match.schema.json

@AucaCoyan
AucaCoyan marked this pull request as ready for review August 2, 2025 04:19
@AucaCoyan
AucaCoyan requested a review from smeech August 2, 2025 04:19

@smeech smeech left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good.

Can you remind me how to test it?
I've tried:

# yaml-language-server: $schema=https://github.com/espanso/espanso/blob/json-schemas/schemas/match.schema.json

but that doesn't work.

Ah, got it:

# yaml-language-server: $schema=https://raw.githubusercontent.com/espanso/espanso/json-schemas/schemas/match.schema.json

random: is now working, but its choices: parameter isn't yet.

@AucaCoyan

Copy link
Copy Markdown
Collaborator Author

Right! I thought it was choice but it's actually choices.
Done! should be working now 😊

@AucaCoyan
AucaCoyan merged commit 3f937b7 into dev Aug 3, 2025
@AucaCoyan
AucaCoyan deleted the json-schemas branch August 3, 2025 21:12
@smeech

smeech commented Aug 4, 2025

Copy link
Copy Markdown
Collaborator

Thanks. Just reloaded VSCodium to check. 👍

sboldt1978 pushed a commit to sboldt1978/espanso that referenced this pull request Feb 11, 2026
* ✨ add `random` var type

* 🐛 allow for more properties in `form_fields`

* 🩹 add descriptions and a required property in shell var

* ✏️ typo in `choices`
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.

Additons to https://github.com/espanso/espanso/blob/dev/schemas/match.schema.json

2 participants