Skip to content

Add enum support to Schema #190

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

Merged
merged 4 commits into from
Jun 25, 2025
Merged

Conversation

gspencergoog
Copy link
Contributor

Description

In preparation for adding Elicitation support, this add enum support to the Schema class.

Elicitations can request enum responses as part of their requestedSchema.

Tests

  • Added validation tests.

Copy link

github-actions bot commented Jun 25, 2025

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

String? get description => _value['description'] as String?;

/// The allowed enum values.
Set<String> get values => (_value['enum'] as Set).cast<String>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we handle null values better here similar to the previous PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we should.

String? get description => _value['description'] as String?;

/// The allowed enum values.
Set<String> get values => (_value['enum'] as Set).cast<String>();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is typically going to be a List, not a Set. We could call toSet, but I would probably just make it have an Iterable type so that it can be either? We should also validate that the JSON encoder can handle any kind of Iterable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I went back and forth on that too. Okay, I'll just make it an Iterable.

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 left out the .toSet, but I did add an assert to check for duplicate entries, which is why I wanted to use .toSet in the first place.

Copy link
Contributor

@jakemac53 jakemac53 left a comment

Choose a reason for hiding this comment

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

We should also add a custom "constructor" (actually static method) to the Schema class (see the other ones there)

@gspencergoog gspencergoog changed the title Add Enum support to Schema Add enum support to Schema Jun 25, 2025
Copy link
Contributor

@jakemac53 jakemac53 left a comment

Choose a reason for hiding this comment

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

See latest comment, one last thing to do actually before landing

@gspencergoog gspencergoog merged commit d0b89cf into dart-lang:main Jun 25, 2025
19 checks passed
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Jun 26, 2025
Revisions updated by `dart tools/rev_sdk_deps.dart`.

ai (https://github.com/dart-lang/ai/compare/706d224..d0b89cf):
  d0b89cf  2025-06-25  Greg Spencer  Add enum support to `Schema` (dart-lang/ai#190)
  f219861  2025-06-26  Brett Morgan  Update `simple_server.dart` (dart-lang/ai#187)
  8e3365f  2025-06-24  Greg Spencer  Add error checks for accessing Request members (dart-lang/ai#184)

protobuf (https://github.com/dart-lang/protobuf/compare/0bfff0c..bce362d):
  bce362d  2025-06-24  Devon Carew  prep to publish 22.4.0 (google/protobuf.dart#1023)
  269e004  2025-06-24  Devon Carew  improve the readability of generated gRPC client files (google/protobuf.dart#1021)
  48ba649  2025-06-24  Devon Carew  update the header for generated files (google/protobuf.dart#1022)

webdev (https://github.com/dart-lang/webdev/compare/6dc3dde..7f376d2):
  7f376d24  2025-06-25  Derek Xu  Set package versions to WIP versions (dart-lang/webdev#2637)

Change-Id: Ib720f5127f3fddeb82b62cf13f24c3ddb4038e33
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437260
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants