asdf-standard icon indicating copy to clipboard operation
asdf-standard copied to clipboard

Drop style-related properties from the metaschema

Open perrygreenfield opened this issue 5 years ago • 6 comments

The current draft-01 yaml-schema metaschema includes three properties related to the style of the serialized YAML:

propertyOrder – specify the order in which object properties should be written

flowStyle – specify the YAML style for an array or an object

style - specify the YAML style for a string

perrygreenfield avatar Jun 19 '20 15:06 perrygreenfield

@embray let's chat about this issue here:

Not sure why this proposal. I always thought this was useful and can make for cleaner looking documents in many cases. As described in YAML Schema they're only intended as hints anyways, and are not required for implementations to follow.

Is there a better way to ensure YAML serialization consistency between implementations (not that this approach is perfect either given that it's optional)?

eslavich avatar Jun 23 '20 14:06 eslavich

Thanks, I didn't see there was an issue for it.

embray avatar Jun 23 '20 14:06 embray

I was the one who threw this idea up on the drawing board -- I've been thinking of these properties as a burden on implementations and noise in the spec that doesn't seem to offer much value. But it sounds like I don't understand the benefits of serialization consistency -- what do we stand to gain by that?

eslavich avatar Jun 23 '20 14:06 eslavich

At the moment I think the way this is implemented in the asdf package is not even entirely complete. Right now what it does ensure is round-tripping: If a file is read in and it contains some property like:

my_array: [1, 2, 3]

it will ensure that when the file is written out again this will round-trip back to

my_array: [1, 2, 3]

and not

my_array:
  - 1
  - 2
  - 3

I think part of the problem is that this feature (e.g. flowStyle) is not currently actually being used anywhere in the ASDF Standard, though I feel like it was at one time. Just to give one example where this might be useful is in the #/definitions/inline-data schema for ndarray. Here you probably want an array data represented in "flow" style like in my example above.

Different YAML implementations are free (IIRC) to make their own decisions about whether to prefer block style or flow style to represent a given value. Continuing with the ndarray example, this provides an explicit hint that when writing that value it should prefer flow style for an array.

embray avatar Jun 23 '20 15:06 embray

I think I originally added this to YAML Schema with good intentions, but it looks like it was never actually used in any of the ASDF schemas after all (except maybe some of my early prototypes; I'll have to see what I have in the archives). It's not really a part of ASDF so much as YAML Schema though, and doesn't add any implementation burden since YAML Schema states that they can be ignored by implementations.

I think it would be a good thing to encourage the use of, including by using these properties in the core schemas where appropriate. But maybe first I should come up with a concrete example where it improves round-tripping and consistency.

embray avatar Jun 23 '20 15:06 embray