Skip to content

Commit 08ef04a

Browse files
Neokilclaude
andcommitted
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<Attributes>(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 <noreply@anthropic.com>
1 parent a2fd144 commit 08ef04a

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api_test.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ namespace {{packageName}}.Test.{{apiPackage}}
4242
{{#dataType}}
4343
var response = await _instance.{{operationId}}Async({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
4444
var model = response.{{vendorExtensions.x-http-status}}();
45+
{{#isModel}}
46+
Assert.IsType<{{packageName}}.{{modelPackage}}.{{{.}}}>(model);
47+
{{/isModel}}
48+
{{^isModel}}
4549
Assert.IsType<{{{.}}}>(model);
50+
{{/isModel}}
4651
{{/dataType}}
4752
{{^dataType}}
4853
await _instance.{{operationId}}Async({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Model Name Collision Test
4+
description: >-
5+
Tests that generated test code uses fully-qualified type names for model
6+
return types to avoid collisions with standard library classes (e.g. a
7+
model named "Attributes" would conflict with System.Attribute).
8+
version: 1.0.0
9+
license:
10+
name: Apache-2.0
11+
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
12+
paths:
13+
/resources:
14+
get:
15+
operationId: GetResources
16+
tags:
17+
- Resources
18+
responses:
19+
'200':
20+
description: Returns a resource with attributes
21+
content:
22+
application/json:
23+
schema:
24+
$ref: '#/components/schemas/Attributes'
25+
servers:
26+
- url: 'http://localhost'
27+
components:
28+
schemas:
29+
Attributes:
30+
type: object
31+
properties:
32+
id:
33+
type: integer
34+
format: int32
35+
name:
36+
type: string

0 commit comments

Comments
 (0)