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

Pattern matching in a sequence? #13

Closed
retr0h opened this issue Feb 26, 2015 · 3 comments
Closed

Pattern matching in a sequence? #13

retr0h opened this issue Feb 26, 2015 · 3 comments

Comments

@retr0h
Copy link

retr0h commented Feb 26, 2015

Is it not possible to check a pattern against a sequence?

data:
  deploy_args:
    allowed_address_pairs:
      - 10.10.10.10
schema:
  type: map
  mapping:
    deploy_args:
      required: true
      type: map
      mapping:
        allowed_address_pairs:
          type: seq
          required: true
          pattern: ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$
          sequence:
            - type: str
@Grokzen
Copy link
Owner

Grokzen commented Feb 26, 2015

Yes in a way it is possible to this but i think that you have to redefine your schema some. The idea here is not to have the pattern validation on the seq definition itself but on the data part of the sequence.

The idea is that you define the key allowed_address_pairs and then you define the data that should be in that key. And in this case that should be a sequence and you set it as required but it would make no sense to define a pattern there because you can't define a pattern for the sequence itself. How would you define a regex pattern that matches on a list defenition (not the data that it contains).

The next level is then the data inside the sequence and that is where i moved the regex check below. By having it there it makes perfect sense because you define the type of data that you want and that is a string and you then want a regex to match that data.

I tried the following

deploy_args:
  allowed_address_pairs:
    - 10.10.10.1012
type: map
mapping:
  deploy_args:
    required: true
    type: map
    mapping:
      allowed_address_pairs:
        type: seq
        required: true
        sequence:
          - type: str
            pattern: ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$

And that fails with pattern validation error on the key in the data block thus proving that the pattern key works there.

@Grokzen
Copy link
Owner

Grokzen commented Feb 26, 2015

I do not know if this will help you visualize anything but this is a image from the original kwalify lib

https://web.archive.org/web/20120222211120/http://www.kuwata-lab.com/kwalify/ruby/img/fig01.png

@Grokzen
Copy link
Owner

Grokzen commented Feb 26, 2015

Also i would really like it if you join the gitter chat if you have any further questions and avoid using the issue tracking for regular questions.

The link to gitter can be found in the readme file and if you ping me with @Grokzen in there i get a notification email :]

@Grokzen Grokzen closed this as completed Feb 26, 2015
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

No branches or pull requests

2 participants