From 08ef04abcad7d2faa0fd1f787e115a198d14acfd Mon Sep 17 00:00:00 2001 From: Simon Schulte Date: Fri, 27 Mar 2026 11:14:20 +0100 Subject: [PATCH 1/2] fix(csharp): qualify model return types in generated tests to avoid standard library name collisions When a model class shares a name with a .NET standard library type (e.g. `Attributes`), the generated `Assert.IsType(model)` call is ambiguous and fails to compile. Use the fully-qualified type name `{{packageName}}.{{modelPackage}}.{{{.}}}` for model return types so the generated test code is unambiguous regardless of model naming. Co-Authored-By: Claude Sonnet 4.6 --- .../libraries/generichost/api_test.mustache | 5 +++ .../3_0/csharp/model-name-collision.yaml | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 modules/openapi-generator/src/test/resources/3_0/csharp/model-name-collision.yaml diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache index 32eb2b769f31..f69bf0bceef5 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache @@ -42,7 +42,12 @@ namespace {{packageName}}.Test.{{apiPackage}} {{#dataType}} var response = await _instance.{{operationId}}Async({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}); var model = response.{{vendorExtensions.x-http-status}}(); + {{#isModel}} + Assert.IsType<{{packageName}}.{{modelPackage}}.{{{.}}}>(model); + {{/isModel}} + {{^isModel}} Assert.IsType<{{{.}}}>(model); + {{/isModel}} {{/dataType}} {{^dataType}} await _instance.{{operationId}}Async({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}); diff --git a/modules/openapi-generator/src/test/resources/3_0/csharp/model-name-collision.yaml b/modules/openapi-generator/src/test/resources/3_0/csharp/model-name-collision.yaml new file mode 100644 index 000000000000..d3c243a8a61c --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/csharp/model-name-collision.yaml @@ -0,0 +1,36 @@ +openapi: 3.0.0 +info: + title: Model Name Collision Test + description: >- + Tests that generated test code uses fully-qualified type names for model + return types to avoid collisions with standard library classes (e.g. a + model named "Attributes" would conflict with System.Attribute). + version: 1.0.0 + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +paths: + /resources: + get: + operationId: GetResources + tags: + - Resources + responses: + '200': + description: Returns a resource with attributes + content: + application/json: + schema: + $ref: '#/components/schemas/Attributes' +servers: + - url: 'http://localhost' +components: + schemas: + Attributes: + type: object + properties: + id: + type: integer + format: int32 + name: + type: string From a367d8df8d45a3cdc5bfb7b9fe4082c555ac4fe3 Mon Sep 17 00:00:00 2001 From: Simon Schulte Date: Tue, 7 Apr 2026 12:58:52 +0200 Subject: [PATCH 2/2] remove additional yaml test file --- .../3_0/csharp/model-name-collision.yaml | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 modules/openapi-generator/src/test/resources/3_0/csharp/model-name-collision.yaml diff --git a/modules/openapi-generator/src/test/resources/3_0/csharp/model-name-collision.yaml b/modules/openapi-generator/src/test/resources/3_0/csharp/model-name-collision.yaml deleted file mode 100644 index d3c243a8a61c..000000000000 --- a/modules/openapi-generator/src/test/resources/3_0/csharp/model-name-collision.yaml +++ /dev/null @@ -1,36 +0,0 @@ -openapi: 3.0.0 -info: - title: Model Name Collision Test - description: >- - Tests that generated test code uses fully-qualified type names for model - return types to avoid collisions with standard library classes (e.g. a - model named "Attributes" would conflict with System.Attribute). - version: 1.0.0 - license: - name: Apache-2.0 - url: 'https://www.apache.org/licenses/LICENSE-2.0.html' -paths: - /resources: - get: - operationId: GetResources - tags: - - Resources - responses: - '200': - description: Returns a resource with attributes - content: - application/json: - schema: - $ref: '#/components/schemas/Attributes' -servers: - - url: 'http://localhost' -components: - schemas: - Attributes: - type: object - properties: - id: - type: integer - format: int32 - name: - type: string