yaml-language-server icon indicating copy to clipboard operation
yaml-language-server copied to clipboard

feat: add if filePatternAssociation

Open p-spacek opened this issue 3 years ago • 2 comments

What does this PR do?

this PR adds the ability to extend 'schema if condition' with filePatternAssociation. it means that it's possible to extend if condition to be connected to some yaml filename.

basically, it's something similar to yamlValidation: [{filematch, url}] to find whole schema based on yaml filename, but this feature is for finding subschema based on the yaml name.

I added this because my schemas are dynamically created and I need some small modifications inside the schema based on the filename.

     {
          type: 'object',
          title: 'basket',
          properties: {
            name: { type: 'string' },
          },
          if: {
            filePatternAssociation: '*fruit.yaml',
          },
          then: {
            properties: {
              pineapple: { type: 'string' },
            },
            required: ['pineapple'],
          },
          else: {
            properties: {
              carrot: { type: 'string' },
            },
            required: ['carrot'],
          },
        }

yaml: some-fruit.yaml

name: some fruit
pinnaple: 'ok'

yaml: some-vegetable.yaml

name: some vegetable
carrot: 'ok'

I hope it can be useful for you too.

What issues does this PR fix or reference?

no ref

Is it tested? How?

added unit test for validation and codecompletion

p-spacek avatar Aug 04 '22 12:08 p-spacek

Coverage Status

Coverage increased (+0.07%) to 83.198% when pulling 2e923ae9b9550ebf9ac026699acbef4c1322836e on jigx-com:feat/if-filePatternAssociation into 08d5f7be7cdc914cedaccbdd4f41fcbc62326c10 on redhat-developer:main.

coveralls avatar Aug 04 '22 12:08 coveralls

hello @msivasubramaniaan, any comments on this PR, please?

p-spacek avatar Sep 02 '22 12:09 p-spacek

@p-spacek Please update the branch

msivasubramaniaan avatar Nov 11 '22 07:11 msivasubramaniaan