-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[dotnet] Source-generate CDP command and response serialization #15172
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
That's my fault, I'm editing this as text because the IDE can't handle it. Syntax should be fixed. |
{ | ||
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::{{rootNamespace}}.{{domain.Name}}.{{className}}CommandSettings))] | ||
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::{{rootNamespace}}.{{domain.Name}}.{{className}}CommandResponse))] | ||
internal sealed partial class CdpSerializationContext; |
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 have 2 options:
- Having only one single
CdpSerializationContext
for types from all cdp namespaces (v130, v131, v132) (and we know how to resolve collisions) - Or separate json context per cdp version
I am not deep dived yet. Please suggest which option would be more friendly for us.
I separated the JSON serialization contexts into protocol versions, then I separated each context into request and response. This was still not enough. I will experiment by adding the context to each domain. |
It looks to be working now that each This relies on the "JsonNode request, JsonElement response" command overload to be AOT-safe. That means this PR relies on this one: #15159 |
return default({{dehumanize Name}}CommandResponse); | ||
} | ||
|
||
return response.Value.Deserialize<{{dehumanize Name}}CommandResponse>(jsonSerializerOptions); |
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.
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::{{../rootNamespace}}.{{dehumanize ../domain.Name}}.{{dehumanize Name}}CommandSettings))] | ||
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::{{../rootNamespace}}.{{dehumanize ../domain.Name}}.{{dehumanize Name}}CommandResponse))] | ||
{{/each}} | ||
internal sealed partial class {{protocolVersion}}{{dehumanize domain.Name}}SerializerContext : global::System.Text.Json.Serialization.JsonSerializerContext; |
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.
Due to a bug in System.Text.Json
I had to import protocolVersion
(eg. V130
) into each class name dotnet/runtime#72671
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Adds a common JSON serializer context for CDP commands and responses.
Motivation and Context
Contributes to #14480
Types of changes
Checklist
PR Type
Enhancement
Description
Introduced a JSON serialization context for CDP commands and responses.
Updated
DevToolsSession
to use the new serialization context.Added source generation for serialization in command templates.
Improved type safety and serialization handling for CDP commands.
Changes walkthrough 📝
DevToolsSession.cs
Update DevToolsSession to use serialization context
dotnet/src/webdriver/DevTools/DevToolsSession.cs
CdpSerializationContext
for JSON serialization.SendCommand
method to use type-specific serialization.CdpJsonSerializationContext.cs
Add CdpSerializationContext for JSON source generation
dotnet/src/webdriver/DevTools/Json/CdpJsonSerializationContext.cs
CdpSerializationContext
.command.hbs
Update command templates for JSON serialization
third_party/dotnet/devtools/src/generator/Templates/command.hbs
responses.
CdpSerializationContext
into command templates.