-
Notifications
You must be signed in to change notification settings - Fork 55
Add ffigen schema and refer them in example config yaml using modeline #586
Conversation
I've put the schema at the root level in |
Some concerns-
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet!
Thanks @mannprerak2 !
That's a good question. I don't really know. What's the behavior? Showing an error or a warning? If it's just a warning, maybe it's fine. Because if you mistype a property you would want to see a warning/error.
They don't change that quickly right? I have no idea if the the pub people cc @jonasfj @sigurdm and dartcode @DanTup can tell us something about versioning JSON schemas in vscode via pub packages.
See comment above about generating the schema. @DanTup might know how to test VSCode things on the GitHub CI. |
Does VS Code support schemas for YAML? There is a RedHat extension (https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) that says it supports them, but I don't think it's built-in. In which case users would need to install that extension (and configure it, unless the schema is on schemastore.org). I'm not sure we can reasonably make any of that automatic though. It might be possible to write some tests that set up VS Code, install the RedHat YAML extension and configure it to check that diagnostics/completion work, although I think if the scheme is valid then the rest of that is already tested by the RedHat extension. |
Installing RedHat YAML extension is required. The schemas are downloaded from https://www.schemastore.org/json/ by default. So we need to upload them there eventually. As @dcharkes mentioned, I'd suggest having this generated automatically. |
Following the discussions in dart-lang/native#468, I'm happy to land a schema, manually publish it to the schema store, have a stable url of the schema on this repo, and have all the examples point to the one on this repo or the schemastore (maybe pointing to a stable URL on this repo would be best because we can guarantee it to stay up to date). We should probably version the schema file with the semantic version of the package. https://github.com/SchemaStore/schemastore/blob/master/CONTRIBUTING.md |
Cool For the auto-generation, I'll try to come up with a good abstraction which can handle validation and json schema generation. Will probably need to rewrite |
👍 This is probably a general pattern we want, I've filed dart-lang/tools#112 to make a general solution. Feel free to either come up with a general solution, and try it both in package:ffigen and package:native_assets_cli, or to make something package:ffigen specific, and report your experiences on that bug. |
They are more focused on having a JsonSchema input than generating a JsonSchema, The classes probably can't be reused (and might change since they aren't part of the public API). Validations are possible if we write the Schema by hand and use that as an initial step. The custom validation, extraction and default spec part would still remain, so I feel the current approach might be better. |
I think this is ready for review now @dcharkes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So happy to see red squigglies in my editor! 🎉
), | ||
], | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any if key a
is in this map, then b
is required?
Or if a
is in this map, then b
must not be supplied?
That's probably not expressible in JSON schemas.
But I have some of that kind of logic in package:native_assets_cli
. https://github.com/dart-lang/native/blob/main/pkgs/native_assets_cli/lib/src/model/build_config.dart
We would probably model that by referring from one schema to the other. I believe the setup in this PR would work fine with trying to add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use OneOfSchema
for these situations. It might be too complicated though for a lot of if-else, Since we'd need one Schema for each permutation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option supported by JsonSchema as well would be https://json-schema.org/understanding-json-schema/reference/conditionals.html#id6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice! If I find some time, I can give your abstraction a spin and add these, and use it in package:native_assets_cli. If the abstraction works well standalone, we could move it to package:config_cli. 👌
…ed by List<FixedMapEntry> in FixedMapConfigSpec
Sorry for the 1 million iterations here! 🙈 I think we're ready to land after the renames. 🚀 |
Ah, no problem. It's finally ready now I suppose 🙈 |
Thanks @mannprerak2 ! |
Closes dart-lang/native#468