Skip to content

Reject schema properties marked both readOnly and writeOnly#72

Merged
shibayan merged 1 commit into
masterfrom
fix/dictionary-converter-readonly-writeonly
May 26, 2026
Merged

Reject schema properties marked both readOnly and writeOnly#72
shibayan merged 1 commit into
masterfrom
fix/dictionary-converter-readonly-writeonly

Conversation

@shibayan

Copy link
Copy Markdown
Owner

Summary

OpenAPI allows declaring a property as readOnly: true and writeOnly: true, but the combination has no well-defined serialization direction. The dictionary converter generated code that skipped such properties in both directions (IsRequestSerializerOptions(options) || IsResponseSerializerOptions(options)reader.Skip()), so a required property in that state silently dropped on every read — data loss without diagnostic.

Detect the combination while building each SchemaDefinition and throw UnsupportedGenerationException, which surfaces as OAW004. Consumers that hit this either fix the schema (the spec-correct outcome) or get a clear failure instead of silent data loss.

Related issue

None.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring or maintenance

Validation

  • dotnet build OpenApiWeaver.slnx
  • dotnet test OpenApiWeaver.slnx

Impact checklist

  • Added or updated tests for generator output, diagnostics, or supported OpenAPI shapes when behavior changed
  • Updated README.md or documentation when user-facing behavior, configuration, or limitations changed
  • Updated AnalyzerReleases.Unshipped.md when diagnostics were introduced or changed
  • Called out breaking changes or notable generated output changes in the summary

Notes for reviewers

  • No new diagnostic ID: reuses the existing OAW004 "unsupported feature" channel.
  • AnalyzerReleases.Unshipped.md is unchanged because no new rule is introduced.
  • The dictionary converter retains its { ReadOnly: true, WriteOnly: true } branch in BuildRequiredDictionaryConverterPropertyExpression and the skip block — those paths are now unreachable from any valid input, but removing them is a separate clean-up.
  • Breaking change scope: previously this generated client silently lost data; now it fails at compile time. Anyone hitting OAW004 needs to drop one of the flags on their schema.

🤖 Generated with Claude Code

A property carrying both flags has no well-defined serialization
direction. The dictionary converter previously generated code that
skipped such properties in *both* directions, silently dropping
required values during deserialization. Detect the combination during
schema build and emit the OAW004 diagnostic instead.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 26, 2026 09:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request prevents silent data loss in generated dictionary converters by rejecting OpenAPI schema properties that are simultaneously marked readOnly: true and writeOnly: true, reporting the existing unsupported-feature diagnostic (OAW004) instead of generating code that skips the property in both directions.

Changes:

  • Add validation in schema transformation to throw UnsupportedGenerationException when a property is both readOnly and writeOnly.
  • Add a diagnostics test asserting OAW004 is produced and no client source is generated for such schemas.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/OpenApiWeaver.Tests/ClientGeneratorTests.Diagnostics.cs Adds a regression test ensuring the invalid RO+WO combination reports OAW004 and blocks client generation.
src/OpenApiWeaver/ClientGenerator.Transformer.Schemas.cs Adds early validation during SchemaDefinition construction to reject properties marked both readOnly and writeOnly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/OpenApiWeaver.Tests/ClientGeneratorTests.Diagnostics.cs
@shibayan shibayan merged commit 2af1a66 into master May 26, 2026
5 checks passed
@shibayan shibayan deleted the fix/dictionary-converter-readonly-writeonly branch May 26, 2026 09:49
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