swagger-api / swagger-api/swagger-codegen

c# 'Name' is a namespace but is used like a type

Open
#10,387 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Issue description

Starting post 2.3.1, at least 2.4.1, C#.NET code can throw the above compile error where the namespace is the same as a type. This is reasonable, but in earlier versions, the generator added "Model" to the type, eg "ModelEvent" instead of "Event" (where a namespace "Event and type Event co-exist in the definition).

Swagger-codegen version

2.4.1 and above including latest version 3.0.20.

Swagger declaration file content or url

Not easy to post a definition file as it's proprietary to another company. But the issue is fairy generic to where a namespace and type definition have the name.

Command line used for generation

java -jar swagger-codegen-cli-2.4.1.jar generate -i "Event.swagger.json" -l csharp -o "Event" -c "Event.config.json"

Steps to reproduce

The config file looks like:

"packageName": "SKYLib.Event",
"targetFramework": "v4.5",
"modelPropertyNaming": "PascalCase",
"nonPublicApi": "false",
"sortParamsByRequiredFlag": "true",
"useCollection": "false",
"validatable": "false",
"optionalAssemblyInfo": "false",
"optionalEmitDefaultValues": "false",
"optionalMethodArgument": "true",
"optionalProjectFile": "false"

Related issues/PRs

I've search and tried to locate the change between 2.3.1 and 2.4.1 but there isn't enough detail to be sure of the source.

Suggest a fix/enhancement

I know I can add a model prefix during generation using a generate argument, but this is less attractive than what I assume was conflict detection in previous versions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the generated C# output with Event.swagger.json, Event.config.json, and the shown swagger-codegen command, comparing versions 2.3.1 and 2.4.1. Trace how the csharp generator handles a namespace and model with the same name; done means generation no longer produces the compile error without requiring a model prefix.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.