dotnet / dotnet/runtime

JsonSchemaExporter: Consider setting readOnly/writeOnly

Open
#131,631 3 comments 0 reactions 0 assignees View on GitHub
area-System.Text.Json
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

From the spec:

https://www.ietf.org/archive/id/draft-bhutton-json-schema-validation-01.html#section-9.4

I think these should map to the internal CanSerialize/CanDeserialize properties on JsonPropertyInfo?

The logic should be along the lines of:

```csharp
if (jsonPropertyInfo.CanSerialize && !jsonPropertyInfo.CanDeserialize)
{
jsonSchema.WriteOnly = true;
}
else if (jsonPropertyInfo.CanDeserialize && !jsonProperty.CanSerialize)
{
jsonSchema.ReadOnly = true;
}
```

@eiriktsarpalis Does that make sense?

Contributor guide

Open the contributing guide

Research direction

Search for JsonSchemaExporter and JsonPropertyInfo first, then inspect the existing property-schema export path and related tests. Add coverage showing how CanSerialize and CanDeserialize affect readOnly and writeOnly, and consider the work complete when the expected schema flags are verified for both directions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.