3 ms·
It's much the same as an XML schema, or K8s CRDs that have a schema embedded into the definition - schema are very useful for ensuring your data structure is va
by EdwardDiego 4y ago
It's much the same as an XML schema, or K8s CRDs that have a schema embedded into the definition - schema are very useful for ensuring your data structure is valid.
You can use the schema to validate that data is structured correctly, then apply business rule validations afterwards.
And most importantly, people creating data you're ingesting have a thorough schema to validate against.
The JSON Schema documentation was rather terrible for a long time, but has significantly improved. Now the fun part is making sure that the version of JSON Schema you're using is supported by the library you're using.
But JSON Schema is far better than OpenAPI because the latter is mostly focused on API description, which adds a lot of noise when you're trying to simply describe a data structure.
And OpenAPI is also hampered by the tight binding to Swagger. For a long time OpenAPI disallowed union types because it caused issues with Swagger's codegen.
I think that latest versions of OpenAPI allow union types, but I don't think Swagger supports those versions yet. At least they didn't the last time I looked.
- jspdown 4y agoOpen API schema objects are define using JSON Schema. The latest version even let you specify the JSON Schema dialect.
- crabbone 4y ago> It's much the same as an XML schema, That's wishful thinking. I can find a lot of differences, but want to point out this one to underscore the difference in approach and level of sophistication. So, in XSL (which is one of the XML schema languages), there's a sequence element. This element describes how tags are supposed to appear in certain order. The analogous structure in JSON would be the dictionary keys, which are also allowed to repeat... but the schema doesn't even cover that option! To make this more concrete, below, is a valid JSON: { "x": 1, "x": "2" } But there's no way of describing in the schema what happens here. Not only this, XSL can restrict the number of times a certain element may repeat... but JSON schema cannot still figure out what to do about this. There are plenty of things that can be implemented in various XML schema languages, but have nothing analogous to them in JSON schema. Another example would be ensuring uniqueness of some particular type of values across the entire document.
- 9dev 4y agoJust because you can doesn’t mean you should. If someone told me tags must appear in a specific sequence for their markup to work, I call the implementation flawed. That’s been the downfall of XML - doing way too much for it’s own good.
- crabbone 4y ago> Just because you can doesn’t mean you should. This is where you are wrong. If you are making a validator, if the format can do something, the validator should deal with that possibility. If validator is incomplete wrt' validated features, it cannot be used to guarantee the document validity, which is... well, it's most important function. It has nothing to do with your emotional attachments to tags and sequences.
- 9dev 4y agoI get where you're coming from, but I don't believe overloading a data exchange format with too many dimensions of meaning is sensible. In XML, you can use tags, sequences of tags, tag attributes, and children tags; there are a multitude of ways to express the same thing. Following your approach, we could also count the number of spaces tags are indented with as an additional dimension: It's entirely possible to write XML this way and infer meaning from it, it's just not specified right now. I doubt you'd follow along with that. Let's look at the concrete reality we're dealing with: XML usage has declined, JSON (maybe supported by JSON schema) is ubiquitous. I'd be inclined to say the pendulum has swung a little too far in terms of simplicity - but overall, it's very clear why XML failed, and too few dimensions of meaning is definitely none of the reasons.