dart-lang / macros

A Dart mono-repo for macro development.
BSD 3-Clause "New" or "Revised" License
20 stars 2 forks source link

Add strict schemas #8

Open davidmorgan opened 2 weeks ago

davidmorgan commented 2 weeks ago

The default schema is very loose, because JSON allows new things everywhere.

Add strict schemas that don't match all future versions, just exactly the current version.

jakemac53 commented 6 days ago

What would the idea be with these? How would we deal with SDK versioning and protocol support?

davidmorgan commented 6 days ago

A strict schema matches as closely as possible what one specific version of the code is supposed to produce, without allowing for future changes.

So it's mostly useful for e2e tests :) to check you are actually producing the JSON you think you're producing.

Otherwise, you can put all the data under "properteis" instead of "properties" and the (loose) schema matches fine :)

There's considerable overlap with the test coverage you get from e2e tests using code generated from the schema; except that the schema can be a little stricter, it will catch a test merely sending incorrect data whereas via the generated code you would have to have code that tries to use it.

Probably we start with the code tests, we need those anyway, and consider adding strict schemas if it seems worth doing.

The other advantage of strict schemas, maybe, is you can conveniently compare multiple versions; whereas with codegen-based tests it's not super convenient to generate multiple versions. But, not sure what we would actually use that for :)

tl;dr: I think this is mostly obsoleted by codegen from the schema.