Skip to content

Conversation

@avgalex
Copy link
Member

@avgalex avgalex commented Dec 23, 2025

Summary

  • Fixed InvalidCastException when models contain enum properties
  • Fixed NullReferenceException when models contain nested object properties
  • Added safe TryGetValue check in NSwagRuleContext for consistency

Root Cause

In Microsoft.OpenApi 2.x (used by Swashbuckle 10.x / .NET 10), enum and nested class properties are represented as OpenApiSchemaReference instead of OpenApiSchema, causing:

  1. InvalidCastException in GetProperties() method
  2. NullReferenceException when accessing property schema in OpenApiRuleContext

Changes

  • OpenApiSchemaCompatibility.cs: Filter out schema references in GetProperties()
  • OpenApiRuleContext.cs: Return empty schema for null properties (schema references)
  • NSwagRuleContext.cs: Add TryGetValue check for safe property access
  • Added unit tests for enum and nested object properties

avgalex and others added 2 commits December 23, 2025 16:06
…ements#176 extended)

- OpenApiRuleContext.cs: Return empty schema for null properties (schema references)
- NSwagRuleContext.cs: Add TryGetValue check for safe property access
- Add test for nested object properties
- Update SetValidatorShouldNotSetParentPropertiesTest for OpenAPI v2 compatibility

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@avgalex avgalex merged commit 4e58bca into micro-elements:master Dec 23, 2025
2 checks passed
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.

1 participant