[csharp] Fix compile errors when schema names collide with framework types
A schema named Parameter, ParameterType, Task, RestRequest, … broke the restsharp ApiClient.cs with CS0104, because it imported the model namespace only to reach AbstractOpenAPISchema. A schema named ValidationResult hid System.ComponentModel.DataAnnotations.ValidationResult inside the model namespace, so every IValidatableObject.Validate implementation stopped compiling.
- restsharp
ApiClient.mustache/ApiClient.v790.mustache: dropusing {{packageName}}.{{modelPackage}};and qualifyAbstractOpenAPISchema, as the httpclientApiClientalready does. validatable.mustache: qualifySystem.ComponentModel.DataAnnotations.ValidationResult, asValidateRegex,modelOneOfandmodelAnyOfalready do. generichost shares this template, so its samples change too; that is most of the sample diff.- Added
3_0/csharp/model-name-collisions.yamland two tests inCSharpClientCodegenTest. restsharp and httpclient clients generated from that spec now compile under net8; on master they fail with CS0104 (Parameter,ParameterType,Task) and aValidatereturn-type mismatch (ValidationResult).
Related: #16123
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
Commit all changed files../mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
cc @mandrean @shibayan @Blackclaws @lucamazzanti
Summary by cubic
Fixes C# code generation so schemas named like framework types no longer produce code that fails to compile. Previously, a schema named Parameter, ParameterType, Task, or ValidationResult broke the generated restsharp client with CS0104, because ApiClient.cs imported the model namespace and models hid System.ComponentModel.DataAnnotations.ValidationResult.
- Removed the model namespace import from the restsharp
ApiClienttemplates and qualified allAbstractOpenAPISchemareferences. - Qualified
ValidationResultasSystem.ComponentModel.DataAnnotations.ValidationResultin thevalidatable.mustachetemplate shared by restsharp and generichost. - Added a regression spec and two tests that generate clients from a schema containing these colliding names.