Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Add ffigen schema and refer them in example config yaml using modeline #586

Merged
merged 49 commits into from
Jul 12, 2023

Conversation

mannprerak2
Copy link
Contributor

Closes dart-lang/native#468

  • Added a schema file
  • Refer to schema locally using yaml modeline in example configs.

@mannprerak2
Copy link
Contributor Author

mannprerak2 commented Jun 3, 2023

I've put the schema at the root level in ffigen.schema.json. I am not sure how we proceed though, I just now learned about json schema 🙈 .

@mannprerak2
Copy link
Contributor Author

mannprerak2 commented Jun 3, 2023

Some concerns-

  1. We could add additionalProperties: false but I feel it may be misleading since I'm not sure about the delay in publishing new schema and when the user updates their package.
  2. Different ffigen versions could have different schema's, is there any way we can handle this?
  3. How do we test this?

Copy link
Contributor

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet!

Thanks @mannprerak2 !

ffigen.schema.json Outdated Show resolved Hide resolved
@dcharkes
Copy link
Contributor

dcharkes commented Jun 5, 2023

Some concerns-

  1. We could add additionalProperties: false but I feel it may be misleading since I'm not sure about the delay in publishing new schema and when the user updates their package.

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.

  1. Different ffigen versions could have different schema's, is there any way we can handle this?

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.

  1. How do we test this?

See comment above about generating the schema.

@DanTup might know how to test VSCode things on the GitHub CI.

@DanTup
Copy link

DanTup commented Jun 5, 2023

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.

@HosseinYousefi
Copy link
Contributor

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.

Screenshot 2023-06-05 at 15 32 20


As @dcharkes mentioned, I'd suggest having this generated automatically.

@dcharkes
Copy link
Contributor

dcharkes commented Jun 6, 2023

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

@mannprerak2
Copy link
Contributor Author

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).

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 Map<List<String>, Specification> _getSpecs

@dcharkes
Copy link
Contributor

dcharkes commented Jun 7, 2023

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 Map<List<String>, Specification> _getSpecs

👍

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.

@mannprerak2
Copy link
Contributor Author

Regarding the new schema abstraction. How does it relate to for example https://pub.dev/packages/json_schema or https://pub.dev/packages/json_schema2 ?

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.

@mannprerak2
Copy link
Contributor Author

I think this is ready for review now @dcharkes

Copy link
Contributor

@dcharkes dcharkes left a 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! 🎉

lib/src/config_provider/schema.dart Outdated Show resolved Hide resolved
lib/src/config_provider/schema.dart Outdated Show resolved Hide resolved
ffigen.schema.json Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
test/config_tests/json_schema_test.dart Show resolved Hide resolved
lib/src/config_provider/config.dart Outdated Show resolved Hide resolved
lib/src/config_provider/config.dart Outdated Show resolved Hide resolved
lib/src/config_provider/config.dart Show resolved Hide resolved
),
],
);
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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. 👌

@mannprerak2 mannprerak2 requested a review from dcharkes July 7, 2023 19:23
lib/src/config_provider/config.dart Outdated Show resolved Hide resolved
lib/src/config_provider/config.dart Outdated Show resolved Hide resolved
lib/src/config_provider/config.dart Outdated Show resolved Hide resolved
lib/src/config_provider/config.dart Outdated Show resolved Hide resolved
lib/src/config_provider/config.dart Outdated Show resolved Hide resolved
lib/src/config_provider/config_spec.dart Show resolved Hide resolved
lib/src/config_provider/config_spec.dart Outdated Show resolved Hide resolved
lib/src/config_provider/config_spec.dart Outdated Show resolved Hide resolved
lib/src/config_provider/config_spec.dart Outdated Show resolved Hide resolved
@dcharkes
Copy link
Contributor

Sorry for the 1 million iterations here! 🙈 I think we're ready to land after the renames. 🚀

@mannprerak2
Copy link
Contributor Author

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 🙈

@dcharkes dcharkes merged commit d46d4fd into dart-archive:main Jul 12, 2023
@dcharkes
Copy link
Contributor

Thanks @mannprerak2 !

@mannprerak2 mannprerak2 deleted the ffigen_schema branch July 12, 2023 19:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Create a schema for auto-completion of ffigen.yaml
4 participants