[C# Generator] CS0101: Type and child namespace share the same name when schema has nested sub-schema
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 333
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 116
Description
### What are you generating using Kiota, clients or plugins?
API Client/SDK
### In what context or format are you using Kiota?
Nuget tool
### Client library/SDK language
Csharp
### Describe the bug
[kiota-repro.zip](https://github.com/user-attachments/files/28167281/kiota-repro.zip)
When an OpenAPI spec defines a schema named Foo and a separate nested schema named Foo.Bar (dot-separated
component name), Kiota generates:
- Foo.cs → class Foo in namespace X.Y
- Foo/Bar.cs → namespace X.Y.Foo
C# does not allow a type and a child namespace to share the same identifier in the same scope, resulting in a
CS0101 compile error.
### Expected behavior
Kiota should detect this collision at generation time and either:
1. Rename the child namespace (e.g. ResourceTypeModels) to avoid the conflict, or
2. Emit a warning and suggest --exclude-path for the conflicting paths
### How to reproduce
Kiota version: 1.31.1
.NET version: 10.0.105
Language: CSharp
1. Download the attached internal_permission_service.openapi.json
2. Run:
kiota generate \
--language csharp \
--openapi internal_permission_service.openapi.json \
--output ./Generated \
--namespace-name My.Api \
--class-name InternalPermissionApiClient
3. Build the generated project
Generated output:
Generated/Models/Zitadel/Internal_permission/V2/
├── ResourceType.cs ← class ResourceType in namespace My.Api...V2
├── ResourceFilter.cs ← class ResourceFilter in namespace My.Api...V2
├── ResourceType/
│ └── ProjectGrant.cs ← namespace My.Api...V2.ResourceType ← CONFLICT
└── ResourceFilter/
└── ProjectGrant.cs ← namespace My.Api...V2.ResourceFilter ← CONFLICT
Compile error:
error CS0101: The namespace 'My.Api...V2' already contains a definition for 'ResourceType'
error CS0101: The namespace 'My.Api...V2' already contains a definition for 'ResourceFilter'
The spec contains component schemas ...ResourceType and ...ResourceType.ProjectGrant (dot-separated). Kiota
interprets the dot as a directory separator, generating a subdirectory ResourceType/ while also generating a class
file ResourceType.cs — causing the collision.
### Open API description file
[internal_permission_service.openapi.json](https://github.com/user-attachments/files/28167236/internal_permission_service.openapi.json)
### Kiota Version
1.31.1
### Latest Kiota version known to work for scenario above?(Not required)
_No response_
### Known Workarounds
_No response_
### Configuration
_No response_
### Debug output
Click to expand log
```
```
### Other information
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached internal_permission_service.openapi.json and reproduce the issue using the shown kiota generate command with --language csharp. Inspect how the C# generator maps dot-separated schemas into ResourceType.cs and ResourceType/ProjectGrant.cs, then build the generated output. Done means the conflicting schema produces valid C# without CS0101, with the chosen rename or warning behavior covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100