Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support string and null as schema representation #30

Merged
merged 4 commits into from
Aug 9, 2024

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Aug 7, 2024

In addition to "type": "object", it looks like the schema generator partially supports using "type": "string" for definitions. Those definitions are broken in unions though, as the generator for unions expects all definitions to be JSON.
This PR fixes that, and also adds support for "type": "null" definitions. Those are useful as part of unions if we only care about the element type. To model Dart's type hierarchy for instance, we may have an union StaticType = InterfaceType {...} | NullableType { StaticType inner } | ... | DynamicType. There is nothing interesting about DynamicType apart from knowing that we're dealing with dynamic, so null makes sense as the underlying JSON representation here.

Copy link
Contributor

@davidmorgan davidmorgan left a comment

Choose a reason for hiding this comment

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

Generally looks good, thanks, please also add schema as suggested so I can review fully.

};

for (final MapEntry(:key, :value) in allDefinitions.entries) {
if (value.oneOf.isNotEmpty) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I just merged another PR tweaking generation for oneOf, because the schema was not correct, please rebase; sorry about that. It moves the oneOf in the schema into a property called value, since that's what we write on the wire.

#26

voidType;
}

extension type StaticType.fromJson(Map<String, Object?> node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be useful to see schema change + code change + generator together, but I don't see the schema change--could you add it please?

There isn't any other test coverage for the generator besides what is in the schema, so it probably makes sense to add something to the schema even if it's just showing the new functionality. In that case please note in the description that the type is currently just there to show the union functionality :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't mean to commit the type changes in this PR, but I've added a few types with their schema definitions to test the generator.

Copy link
Contributor

@davidmorgan davidmorgan left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

schemas/dart_model.schema.json Outdated Show resolved Hide resolved
@davidmorgan
Copy link
Contributor

Please fix lint violation

   info - lib/generate_dart_model.dart:60:33 - Angle brackets will be interpreted as HTML. Try using backticks around the content with angle brackets, or try replacing `<` with `&lt;` and `>` with `&gt;`. - unintended_html_in_doc_comment

@davidmorgan davidmorgan merged commit 1bfa4b3 into dart-lang:main Aug 9, 2024
39 checks passed
@simolus3 simolus3 deleted the simpler-schema-types branch August 9, 2024 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants