Skip to content

fix: Properly escape string litterals and support implict usings false#38

Merged
nikcio merged 3 commits intomainfrom
feature/escape-strings-and-implict-usings
Apr 2, 2026
Merged

fix: Properly escape string litterals and support implict usings false#38
nikcio merged 3 commits intomainfrom
feature/escape-strings-and-implict-usings

Conversation

@nikcio
Copy link
Copy Markdown
Contributor

@nikcio nikcio commented Apr 2, 2026

  • Understand the review feedback (emit using directives conditionally)
  • Implement NeedsSystemNamespace() helper using schema-format inspection
  • Implement NeedsCollectionsNamespace() helper using schema-type inspection
  • Implement NeedsGlobalizationNamespace() helper checking date format + default value
  • Add SchemaResolvesToSystemType() and SchemaResolvesToCollectionType() static helpers
  • Update Emit() to conditionally emit using directives (restore original flags for System.IO and System.Text.Json)
  • All 192 tests pass
  • Code review passed - no comments
  • CodeQL security scan passed - 0 alerts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves C# code generation correctness for string escaping (notably backslashes) and adds coverage to ensure generated output compiles even when the consuming project disables implicit usings.

Changes:

  • Introduces a centralized C# string literal escaping helper and uses it for enum member names, JSON property names, and string defaults.
  • Updates generated file headers to include explicit using directives to avoid relying on consuming-project implicit usings.
  • Adds new integration-style tests for backslash escaping and for compiling generated code with ImplicitUsings=disable.

Reviewed changes

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

File Description
tests/OpenApiCodeGenerator.Tests/CSharpSchemaGeneratorTests.cs Adds compilation harness helper plus new round-trip tests covering backslash escaping and a compile-only test with implicit usings disabled.
src/OpenApiCodeGenerator/CSharpCodeEmitter.cs Adds EscapeCSharpStringLiteral and applies it in emitted attributes/defaults; emits explicit using directives in generated output.

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

@nikcio nikcio enabled auto-merge April 2, 2026 13:55
@nikcio nikcio merged commit ba1dab6 into main Apr 2, 2026
4 checks passed
@nikcio nikcio deleted the feature/escape-strings-and-implict-usings branch April 2, 2026 13:55
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.

3 participants