Re: "YAML Easy Schemas"

Peter Murphy <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
Trans,

Thank you for putting the work into developing a schema language for YAML.

I do have one quibble. Where exactly is the spec for YPath? Most
people would be interested in finding all nodes with a given tag
property, and validating for that - but I can't even find how to do
that in the language.

I want to try and see if I understand your spec by trying it against
the "Invoice" example in the YAML spec:

http://www.yaml.org/spec/1.2/spec.html#id2761803

There are a few comments, which indicate possible directions for the
schema. All mistakes are mine. Example goes:

---
/[YPath expression for all nodes of tag <tag:clarkevans.com,2002:invoice>]:
  invoice: &mandatoryint
     type: int
     required: true #Shouldn't we use booleans like true and false?
  date:
     type: datetime #Indicate somehow that dates are required, but
times are not?
     required: true
  bill-to: &billing-schema-alias
     type: map
     required: true
     value: # We could refer to this by Ypaths, but it feels more
natural to embed in it the parent structure schema
       given: &amms # Short for "All Mandatory Strings Schema"
         type: str
         required: true
       family: *amms
       address:
           type: map
           required: true
           value:
               lines: *amms
               city: *amms # Or suburb.
               state: &aoss # Short for "All Optional Strings Schema"
                   type: string
                   required: false # Not every country has states or provinces.
               country: &aoss # Unnecessary if posting in the same country.
               postal: &aoss # Some countries don't use postcodes.
  ship-to: *billing-schema-alias # Yay for anchors and aliases!
  tax: &currency # Should indicate two decimal places - no more, no less.
    type: float
    required: true
  total: *currency
  comments: *amms
  product:
      type: seqorsing: # See below
      required: true
      value:
        sku: *amms
        quantity: *mandatoryint
        description: *amms
        price: *currency
...

I've probably made some indentation mistakes in typing in YAML, but
you get the gist. I think it is more natural to add a value property
to indicate the type of a mapping value, rather than use Ypath
expressions to refer to them. I also like the use of anchors and
aliases to save me typing in the same thing.

One more thing. In the original invoice example, "product" is a
sequence of separate products (in this case, 2). But if there is only
one product, is it necessary to express it as a sequence of one
product? Wouldn't it be more natural to let the user express it as a
single value in that case? I thought adding a type "seqorsing"
(sequence or singleton) would allow schema designers to validate
documents like this, while saving YAML writers a little bit of work.

What are your thoughts, Trans?

Best regards,
Peter


-- 
Email: [email protected]
WWW: http://www.pkmurphy.com.au/

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.