yaml-language-server
yaml-language-server copied to clipboard
feat: add if filePatternAssociation
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
Coverage increased (+0.07%) to 83.198% when pulling 2e923ae9b9550ebf9ac026699acbef4c1322836e on jigx-com:feat/if-filePatternAssociation into 08d5f7be7cdc914cedaccbdd4f41fcbc62326c10 on redhat-developer:main.
hello @msivasubramaniaan, any comments on this PR, please?
@p-spacek Please update the branch